Anybody smart

SynthDef("a", {
	arg ratio=1, base, amp, out;
	var sig;
	base = base*ratio;
	amp = (ratio.log2 * \tilt.kr(-3)).dbamp; 
	sig = amp*(SinOsc.ar(base));
	Out.ar(out, sig) 
}).add
(
var func; 
func = {
	|harmonics, even_uneven_ratio, freq, tilt|
	{
		|i|
		var b;
		/*if(i.odd,{ even_uneven_ratio },{ even_uneven_ratio = 1});*/
		b = Synth("a", [
			base: freq, 
			ratio:i, 
			amp: 0.5
		]);
	}.dup(harmonics);
};
func.value(harmonics:64,even_uneven_ratio: 0.5,freq: 440,tilt: -3)
)

** CLICKS IN LEFT EAR, 64 SYNTHS, NO SOUND **

Hi @sin

Two problems!

you want to use .collect here instead of dup

evaluate this to see how it works

64.collect{|i| i + 8}

And you need to avoid ratio of 0 because 0.log2 is infinite - this is what was making no sound come out.

Finally you are not making use of your “amp” arg so sound will be too loud!

here’s your example working mostly:

SynthDef("a", {
	arg ratio=1, base, amp, out;
	var sig;
	base = base*ratio;
	amp = (ratio.log2 * \tilt.kr(-3)).dbamp * amp; // multiply by amp  
	sig = amp*(SinOsc.ar(base));
	Out.ar(out, sig) 
}).add
(
var func; 
func = {
	|harmonics, even_uneven_ratio, freq, tilt|
	harmonics.collect{  
		| harmonic |
		var b;
		/*if(i.odd,{ even_uneven_ratio },{ even_uneven_ratio = 1});*/
		b = Synth("a", [
			base: freq, 
			ratio: harmonic + 1, //ratio of 0 gives infinite volume!
			amp: 0.03,
		]);
	}
};
func.value(harmonics:64,even_uneven_ratio: 0.5,freq: 440,tilt: -3)
)

Sorry, I’m not smart

calling bullshit here

(though maybe anyone who learns this much SC is by def dumb)

the answer is already here, dup dont have index of iteration passed as argument, i just dumbly fill Array with same function evaluation, thats the reason on the first place. I tried to initiate synth that is based on freq 440 * nothing, The confusing part is they existed on sever but hasnt freq defined in SInOsc. Like they dont have func envirement where they have different buffer, but it looked like it did. Every iterative method was could be used . Array.fill, .collect (Func that act like Array.map in other langs).

SynthDef("a", {
	arg ratio=1, base, amp, out;
	var sig;
	base = base*ratio;
	amp = (ratio.log2 * \tilt.kr(-24)).dbamp * amp; // multiply by amp  
	sig = amp*(SinOsc.ar(base));
	Out.ar(out, sig ! 2) 
}).add
(
var func; 
func = {
	|harmonics, even_uneven_ratio, freq, tilt|
	var a = Array.fill(harmonics,{  
		| harmonic |
		var b;
		if (harmonic.odd{} { even_uneven_ratio = 1});
		b = Synth("a", [
			base: freq, 
			ratio: harmonic + 1, //ratio of 0 gives infinite volume!
			amp: even_uneven_ratio,
	])});
	};
func.value(harmonics:64,even_uneven_ratio: 0.5,freq: 442,tilt: -3)
)

This works completely fine as well just calling Synth every time with new ratio
this is valuable statement that log2(0) is infinite, so you can just not do Synth if it if ratio = 0. Ofc you dont need a synth running at 0 freq

I actually would wish a friendly practical tutorial, step by step, im not a programmer at all, why i learn that iterations start from zero only now? like isnt it the base of programming languages, it would be handy i knew this binops, operators without trying to skip 80% of boring video on yt, or wathing it directly in documentation. You dont start with documentation right?
In supercollider it makes sense, its not C

Nice simple tut:

https://www.berkeleynoise.com/celesteh/podcast/projects/abandoned-tutorial/

From the docs: (this section of docs should maybe be updated?)

https://doc.sccode.org/Tutorials/Getting-Started/00-Getting-Started-With-SC.html

https://doc.sccode.org/Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial.html

this one nice as well

https://composerprogrammer.com/teaching/supercollider/sctutorial/tutorial.html

You can also do this…

(1...harms).collect{
    |harmonic|
    Synth(\a, [
        base: freq, 
        ratio: harmonic, 
        amp: if(harmonic.odd, even_uneven_ratio, 1)
    ])
} 

The top line explicitly creates a range of values from 1 to 5 (including 1 & 5).

Just a few things you might want to think about as there are some errors in your code

Right now you are multiplying by amp twice, is this intended?
Your if statement is a little odd.
The variable b doesn’t actually do anything.

The final code might look like this…

SynthDef(\a, {
	var freq = \base.kr * \ratio.kr(1);
	var boostdb = \ratio.kr.clip(1, inf).log2 * \tilt.kr(-24); 
	var sig = SinOsc.ar(freq) * \amp.kr(0.1) * boostdb.dbamp;
	Out.ar(\out.kr(0), sig ! 2) 
}).add;

(

var func = {
	|harmonics, even_uneven_ratio, freq, tilt|
	(1..harmonics).collect{
		| harmonic |
		Synth(\a, [
			base: freq, 
			ratio: harmonic,
			amp: harmonic.odd.if(even_uneven_ratio, 1),
		])
	};
};

func.value(
   harmonics:64, 
   even_uneven_ratio: 0.5, 
   freq: 442, 
   tilt: -3
)

)
1 Like

ha that second amp multiplication was my addition! whoops