-
Notifications
You must be signed in to change notification settings - Fork 1
Setting up an audio modulator
In order to use an oscillator for modulation, we'll require two oscillators. The first will modulate the amplitude, and it is called the 'modulator'. The second is the 'carrier', and it will take the output of the modulator and apply it to the audio player.
Step 0 - Set up our oscillator
var audio = new maximJs.maxiAudio();
var osc = new maximJs.maxiOsc();
function setup() {
audio.play = playLoop;
audio.init();
}
function playLoop() {
this.output = osc.sinewave(440);
}
Step 1 - Set up our modulator oscillator
var audio = new maximJs.maxiAudio(); var osc = new maximJs.maxiOsc(); var ampMod = new maximJs.maxiOsc();
Step 2 - Make value of modulator a stream between 0 and 1
function playLoop() { var amp = (ampMod.sinewave(8)+1)/2; this.output = osc.sinewave(440); }
This sets the value of variable amp
to a changing stream of numbers generated by the sinewave. The wave travels between -1 and 1 at a rate of 8 times per second (you can change this). We then add one so it is between 0 and 2 and then divide by 2 so it is always within our desired range - 0 and 1.
Step 3 - Change the amplitude of our output based on the value of amp
.
Super simple - just multiply the output by amp
.
function playLoop() { var amp = (ampMod.sinewave(8)+1)/2; this.output = osc.sinewave(440) * amp; }