FM7 control matrix iteration

I would like to duplicate the FM7 seven times with a specific frequency shift each time it is duplicated (applied to all of the six operators) ie for the second duplication: freq=freq*shift2 applied on all of the six lines, for the third duplication freq=freq*shift3 and so on. I am used to iterate with random values and I don’t know how to deal with a number of fixed value. Also if it was a classic osc I would do

freq= [freq,freq*shift2,freq*shift3,freq*shift4....];
snd=Saw.ar(freq);

But like the FM7 has this control matrix it is well more tricky for me as a newb.


var shift1= 0.452, shift2= 0.321 etc...

snd= { FM7.ar(17,  [
		[freq,0,e1],
		[freq,0,e2],
		[freq,0,e3],
		[freq,0,e4],
		[freq,0,e5],
		[freq,0,e6],
	], 1.3);
}.dup(7);  //???

Thanks.

var shift1 = 0.452, shift2 = 0.321

Rule of thumb: Whenever you find yourself writing numbered variables (more than two or three), you might be able to simplify the code considerably by using arrays.

var shifts = [0.452, 0.321, ...];

Then you can get all of the frequencies in one go:

// assuming `freq` is a synth arg
var freqs = freq * shifts;

Now you have an array of frequencies.

If you have an array of numbers and you want an array of something else based on those numbers, you would use .collect.

This case is no exception.

var fms = freqs.collect { |oneFreq|
	FM7.ar(17, [
		[oneFreq, 0, e1],
		...
	], 1.3)
};

hjh

1 Like

Oh, easily understable and extremely usefull, thank you