Nasty flanging phaser noise from sinus tone in pbind

Hi, I am all new to SC and have only used it for a speciel task - or a few. I´m getting some nasty phasing or flanging sub- and top harminics when playing back this bit of code to record some special requiencies to use in a piece of music:
Pbind
(\freq, Pseq([84], inf),
\dur, Pseq([60], inf),
\amp, Pseq([1.0], inf),
\legato, Pseq([1.0],inf))
.play(TempoClock(30/60));

and a beating noise when playing back this:

Pbind
(\freq, Pseq([1508], inf),
\dur, Pseq([60], inf),
\amp, Pseq([1.0], inf),
\legato, Pseq([1.0],inf))
.play(TempoClock(30/60));

Would anyoine know what causes this?
Thanks in advance :slight_smile:

Hi and welcome,

there’s nothing wrong here. Your assumption that SC would play a sine tone by default is wrong. It plays the default instrument which is written in the file Event.sc:

	*makeDefaultSynthDef {
		SynthDef(\default, { arg out=0, freq=440, amp=0.1, pan=0, gate=1;
			var z;
			z = LPF.ar(
				Mix.new(VarSaw.ar(freq + [0, Rand(-0.4,0.0), Rand(0.0,0.4)], 0, 0.3, 0.3)),
				XLine.kr(Rand(4000,5000), Rand(2500,3200), 1)
			) * Linen.kr(gate, 0.01, 0.7, 0.3, 2);
			OffsetOut.ar(out, Pan2.ar(z, pan, amp));
		}, [\ir]).add;
	}

If you would like to hear another default synth check

https://scsynth.org/t/how-to-change-the-default-synth-tutorial

Two further remarks: in your Pbind you could also write

Pbind(
	\freq, 84,
	\dur, 0.2,
	\amp, 1,
	\legato, 1
)
.play(TempoClock(30/60));

And please enclose code with three backticks, which generates indentation and makes it better readable.

Best

Daniel

Hi Daniel,
wow, I had no idea. Thank you, I´ll try that.
Best
Christian

Hi again, sorry for asking a very simple question, but how do i get that piece of code you posted to play? I´m evaluating but nothing happens. No sound, and the default synt still sounds the same. What am I doing wrong? Also, I tried the link you suggested, but no luck.
thanks in advance
Christian

It was thought to show how the default synth is defined (it’s done via the method ‘makeDefaultSynthDef’), so you don’t need to evaluate it. You can simply define any SynthDef as default synth. It is described under the link I have given.

What do you mean with “no luck” ? Please understand, from such a formulation nobody can help you and tell what’s not working. Is it the link ? Or the code that is posted there ?

Mads has explained it on his site:

https://www.madskjeldgaard.dk/how-to-change-the-default-synth-in-supercollider/

I guess I am too unversed in this to understand how that piece of code is supposed to help me.
Christian Kjelds explanantion is good I guess, but I follow it, and the synth that plays is still the same
annoying flanger thing. I put the code in the Startup menu, reboot the server and nothing changes. Don´t know what I´m doing wrong.
best
Christian

Hm, I just checked and get a new default sound.
Could it be you’re not really evaluating the code (e.g. not evaluating all lines) ?
Does your post window show up “-> a SynthDef” ?

If yes the default synth should be replaced !
However it still is no sine.

You could check out this:

(
SynthDef.new(\default, {
arg dur, attack=0.01, release=1.0,
t_gate=1, out, freq=442, amp=0.5;

var env = EnvGen.kr(Env.perc(attack, release), t_gate, timeScale: dur, doneAction: 2);
var sig = SinOsc.ar(freq: freq, mul: env);
Out.ar(out, sig * amp);
}).add;
)

x = (dur: 60).play

x.free

When evaluating this in the startup.scd window, I get this in the postwindow:


ERROR: syntax error, unexpected NAME, expecting $end
in file ‘selected text’
line 12 char 1:

x = (dur: 60).play
^


ERROR: Command line parse failed
-> nil


Is it supposed to look like that?

This is an evaluation error. You must not evaluate all in once but each chunk of code !
First you have to evaluate the definition of the SynthDef, this has to be done before playing, you wouldn’t free before listening to the playing.
I recommend starting with the Getting-Started tutorial which is contained in SC’s help system.

To clarify Daniel’s answer: There is an informal convention in SC code to break it up into “chunks,” using ( ... ) on separate lines for each chunk. I think this might be discussed in the Getting Started tutorial series, but I’m not sure if it’s ever really been formalized anywhere. (It isn’t part of the formal language definition – but it is a usage pattern that is so common, we might tend to assume everybody “just knows.”)

So there was a bit of a miscommunication. You might have been assuming that

... all of the code
... in a *forum* block
... should be run at one time

But it’s really

(
Put the cursor inside these parentheses
and run it
)

(
SECOND, put the cursor inside these parentheses
and run it
)

(
THIRD...
)

// And this single line is not in ( )
// So run it in isolation
x = (dur: 60).play;

hjh

Hi, thanks for the helpful explanation reg. “chunks”. I still can´t change the default synt. I tried to change the default synt in the startup window (as suggested by Mads Kjelgaard) in Daniels link:
I evaluate this:


s.doWhenBooted{
SynthDef.new(\default, {
arg dur, attack=0.01, release=1.0,
t_gate=1, out, freq=442, cutoff=5500,
rq=1, pan=0.0, amp=0.5;


then this


var env = EnvGen.kr(Env.perc(attack, release), t_gate, timeScale: dur, doneAction: 2);
var sig = DPW3Tri.ar(freq: freq, mul: env);
sig = RLPF.ar(sig, cutoff.clip(20.0, 20000.0), rq.clip(0.0,1.0));
sig = Pan2.ar(sig, pan);
Out.ar(out, sig * amp);
}).add;
};


and play it back with this:


().play


And it´s still the same synt. The same happens when I use Daniels bit of code:


SynthDef.new(\default, {
arg dur, attack=0.01, release=1.0,
t_gate=1, out, freq=442, amp=0.5;

var env = EnvGen.kr(Env.perc(attack, release), t_gate, timeScale: dur, doneAction: 2);
var sig = SinOsc.ar(freq: freq, mul: env);
Out.ar(out, sig * amp);
}).add

x = (dur: 60).play


I must be doing something fundamentally wrong.
thanks
Christian

Hi,
note also that Mads’ Synth makes use of an extension. If you don’t have the extensions pack installed “DPW3TRi.ar” will not be found…

Again, please enclose code blocks in triple backticks.

While you are typing, code blocks should look like this:

```
my code here
```

Otherwise they are formatted as plain text and it’s harder to work with.

Right there, you’ve broken up a single block into two blocks. That isn’t going to work.

You have to run the whole bit from s.doWhenBooted to the closing } of that block.

Daniel’s example.

Step one. Boot the server. Wait for the server to complete booting before doing anything else. (If you’ve already booted, it’s OK, “boot” again will just say it’s already running.)

s.boot;

Step two. Run this block in its entirety. Run only this block (do not add other blocks to it, just yet) and do not split it into multiple blocks.

(
SynthDef.new(\default, {
	arg dur, attack=0.01, release=1.0,
	t_gate=1, out, freq=442, amp=0.5;
	
	var env = EnvGen.kr(Env.perc(attack, release), t_gate, timeScale: dur, doneAction: 2);
	var sig = SinOsc.ar(freq: freq, mul: env);
	Out.ar(out, sig * amp);
}).add;
)

Step three. Play the synth.

x = (dur: 60).play;

hjh

It works. Thank you. It´s only in one channel though. Can you see from the code why that is? Also I would love to be able to make this the default synt, and not something I need to do every time I boot up. I tried also putting this code in the start up menu, but when I booted up next time it was back to the old synt again. Is there an easy fix? Thanks again. best Christian - not sure if the code I put in the quote should have the backtics?

Hi Christian,

The synth you have been using only produces one channel of output. You can make it produce two by duplicating the sig in the last statement. For example, you could write

sig.dup * amp

instead of

sig * amp

To permanently replace the default synth, follow the instructions in Mads’ post, they are quite clear.

The problem seems to be that you haven’t worked through any tutorials before coming here with questions. Please do so, there are many excellent ones to be found with a simple search, next to the ones included in the help system.

I personally started with the one you can find here (thanks, Thor!):

www.ixi-audio.net/content/backyard.html

Or if you prefer video, try Eli Fieldsteel’s

https://www.youtube.com/playlist?list=PLPYzvS8A_rTaNDweXe6PX4CXSGq4iEWYC

Cheers,

eddi

To add to alln4tural’s correct answer – first I’ll requote Daniel from several messages ago:

I recommend starting with the Getting-Started tutorial which is contained in SC’s help system.

I point this out because, in this tutorial series, there is a chapter “06. Presented in Living Stereo” – here is a link to an online copy, but you can also find it in the IDE’s help browser. http://doc.sccode.org/Tutorials/Getting-Started/06-Presented-in-Living-Stereo.html

This chapter explains the mono/stereo question.

I’ll be the third person on this thread to point out that you’re skipping over several fundamentals in order to get to the “fun stuff,” and then getting confused. There is a way to reduce some of that confusion – step back and look over the fundamentals.

not sure if the code I put in the quote should have the backtics?

You should use backticks when posting code in the forum, but there is no need for them in the IDE.

Here, I’m not sure why the entire block of code has been collapsed onto a single line? It’s syntactically valid that way, but much much harder to read.

To permanently replace the default synth, follow the instructions in Mads’ post, they are quite clear.

I’d suggest a slightly different approach. His approach should work for the default server, but not for other servers.

There is a “system action” class for things to do after a server is booted and ready to accept commands.

So put this into your startup file:

ServerTree.add {
	SynthDef(\default, { |out = 0, freq = 440, gate = 1, pan = 0, amp = 0.1|
		var eg = EnvGen.kr(Env.adsr(0.01, 0.2, 0.6, 0.12), gate, doneAction: 2),
		sig = SinOsc.ar(freq);
		Out.ar(out, Pan2.ar(sig, pan, eg * amp));
	}).add;
};

hjh

Thanks for this. It works like a charm. Thanks for your help :slight_smile: Christian

Thanks for helping we out with this guys. I absolutely take to heart your comment on getting started from scratch with a tutorial. Really appreciate the time you took to help with this. I was/am in the middle of a project where I needed it to work… now, so had to skip ahead in the proces. Thanks :pray: