Hey,
actually your code will produce some strident timbres on any soundcard.
You will hear a crazy Timbre due to distortion. This happens when the sound is clipping. You could use this effect as some sort of digital overdrive but that’s probably not what you’re looking for.
If you want a clean sound, the Signal you’re sending to the sound card needs to be in a certain range. (In the analogue world it would be voltage).
SuperCollider doesn’t automatically limit this range so you need to take care of that.
If you just add a *0.5
to the signal it should be better already.
Here are some additional remarks:
It’s also good to add a doneAction
to your envelope, so that the synths get removed from the node tree. And you prevent crashing SC / your computer.
The SynthDef can be initialized just once and the called by Synth(\<name_of_the_synth>)
. It makes working with the routines a bit easier.
(
SynthDef.new(\lowBell,{
arg freq=1, amp=0.8;
var fund, harm1,harm2,harm3,harm4,sig,env;
//envelope
env=EnvGen.kr(Env.new([1,0.8,0.5,0.8,0.0001],[0.2,3,0.5,10],\sin), doneAction: 2);
//spectral content
sig = Klang.ar(`[
[100,40,56,65,80],
[0.8,0.2,0.3,0.2,0.01]],freq);
sig=sig*env * 0.5;
//effects
sig=Pan2.ar(sig,0);
Out.ar(0,sig);
}).add;
SynthDef.new(\highBell,{
arg freq=1, amp=0.8;
var fund, harm1,harm2,harm3,harm4,sig,env;
//envelope
env=EnvGen.kr(Env.new([1,0.8,0.5,0.8,0.0001],[0.2,3,0.5,10],\sin), doneAction: 2);
//spectral content
sig=Klang.ar(`[
[700,40,56,65,80],
[0.8,0.2,0.3,0.2,0.01]],freq);
sig=sig*env * 0.5;
//effects
sig=Pan2.ar(sig,0);
Out.ar(0,sig);
}).add;
)
(
~rut = Routine {
loop {
Synth(\lowBell);
3.wait;
Synth(\highBell);
10.wait;
}
};
)
~rut.play;
~rut.stop;
Since your bells are similar except for the spectrum, you could also use just one SynthDef and pass the spectrum as an argument. Note, that with Klank you need to pass the frequency array as an immutable object (use #
before the []
)
Below the unused variables and the explicit defaults are removed. It makes reading and understanding the code a bit easier.
Be careful if you play to many instances at once since the amplitudes are adding up and you will have some clipping again. You could use the amp
argument as in Synth(\bell, [\amp, 0.1])
for example.
If you wan’t to check out the the Basic Server (/sound) architecture of SuperCollider, this is a good read: Server Architecture | SuperCollider 3.12.2 Help
(
SynthDef(\bell, {|out = 0, timbre = #[100,40,56,65,80], amp=0.5|
var sig,env;
//envelope
env = EnvGen.kr(
Env.new([1,0.8,0.5,0.8,0.0001],[0.2,3,0.5,10], \sin),
doneAction: 2);
//spectral content
sig = Klang.ar(`[
timbre,
[0.8,0.2,0.3,0.2,0.01]]);
sig = Pan2.ar(sig * amp);
Out.ar(0, sig * env);
}).add;
)
(
~darkTimbre = #[100,40,56,65,80];
~brightTimbre = #[700,40,56,65,80];
// Synth(\bell, [\timbre, ~brightTimbre]); // testing
~rut = Routine {
loop {
Synth(\bell, [\timbre, ~darkTimbre]);
3.wait;
Synth(\bell, [\timbre, ~brightTimbre]);
10.wait;
}
};
)
~rut.play;
~rut.stop;
hth,
cheers
Florian