I'm quite confused on how to implement parameters in additive synthesis.
I'm trying to implement a system where I can sequence the following parameters: arbitrary number of partials, base frequency. I'm not sure of the feasibility of the arbitrary number of partials, but sequencing the base frequency should be indeed totally possible in my opinion.
Here is the code I'm working on:
(
z = {
arg index, freq, nn;
var finalFreq, ff, amp, nn;
ff = index*freq;
amp = 0.5/nn;
finalFreq = freq + ff;
finalFreq.postln;
s = SinOsc.ar(finalFreq, 0, amp);
};
)
(
SynthDef.new('additive',{
arg freq, nn;
var sig, env;
env = Line.kr(1,0,0.2);
sig = Mix.fill(nn, z) * env;
Out.ar(0,sig);
}).add
)
(p = Pbind(
\instrument, \additive,
\dur, Pseq([0.1,0.2,0.3,0.4],inf),
\freq, Pseq([100,440,880,55],inf),
\nn, Pseq([1,5,10,100],inf)
).play;
)
This fails with Index not an Integer
. And I'm not even sure on how to send parameters to z.
An alternative formulation, which I envisioned exploiting variable scope is the following:
(
SynthDef.new('additive',{
arg freq, nn;
var sig, env;
env = Line.kr(1,0,0.2);
z = {
arg index;
var finalFreq, ff, amp, nn;
ff = index*freq;
amp = 0.5/nn;
finalFreq = freq + ff;
finalFreq.postln;
s = SinOsc.ar(finalFreq, 0, amp);
};
sig = Mix.fill(nn, z) * env;
Out.ar(0,sig);
}).add
)
It's also not working, failing with Index not an Integer
.
How would you tackle this problem?