Reputation: 93
I am struggling to understand how to create an array of WebAudio oscillators, such as osc[i]. I have been able to construct single oscillators such as
let oscillator = audioContext.createOscillator();
oscillator.frequency.value = 493.88; //B4
I have looked at articles such as ".. Polyphonic Synthesis" but I don't understand what is happening with the author's "compact" code!
Upvotes: 0
Views: 299
Reputation: 17062
you can use a loop:
const oscs = [];
for(let i = 0; i < 7; i++) {
const oscillator = audioContext.createOscillator();
oscillator.frequency.value = 110 * 2 ** i;
oscs.push(oscillator);
}
this will create 7 oscillators (A2 to A8)
Upvotes: 1