Strategy to control an additive synth

Hello,
while thinking of ways how to control all the partials of an additive synth i came up this idea, maybe it is useful for somebody else!

(
~number_of_partials = 100;
~sample_rate = s.sampleRate;
~buffer_amplitudes !? _.free;
~buffer_amplitudes = Buffer.alloc(s, ~number_of_partials);

//x = number of the partial, y = amplitude of the partial
~plotter = Plotter.new('Amplitudes', Rect(600, 30, 800, 250));
~plotRoutine = Routine.new({
	loop {
		~buffer_amplitudes.getToFloatArray(action: {arg array; a = array});
		{~plotter.setValue(a)}.defer(0).yield;
	}
});

Ndef(\additive_amp_control, 
	{
		/*
		 Amplitude control part
		
		A gauss curve is written into the ~buffer_amplitudes.
		The value at ~buffer_amplitudes[i] is the amplitude of the i-th partial
		*/
		BufWr.ar(
			LFGauss.ar(
				duration: ~sample_rate.reciprocal * ~number_of_partials / \factor.kr(1,0.5), 
				width: \width.kr(0.2,0.5),
				iphase: \phase.kr(0,0.5).mod(4)
			),
			bufnum: ~buffer_amplitudes,
			phase: Phasor.ar(
				end: ~number_of_partials
			)
		);
		
		//Additive synthesis part
		Mix.fill(~number_of_partials, {
			arg i;
		SinOsc.ar(
				//Odd harmonics
				freq: ((i * 2) + 1) * \fund.kr(120,0.5),
				//The i-th value of ~buffer_amplitudes is read with an Index Ugen
				mul: Index.ar(~buffer_amplitudes,i)
			)/~number_of_partials
		})!2
});
Ndef(\additive_amp_control).play.gui;
fork{loop{~plotRoutine.value;0.032.wait;}};
)
1 Like

thx! interesting approach