diff --git a/examples/oscillator_FMSynth/index.html b/examples/oscillator_FMSynth/index.html new file mode 100644 index 00000000..6ec1957c --- /dev/null +++ b/examples/oscillator_FMSynth/index.html @@ -0,0 +1,10 @@ +
+ + + + + + + + + diff --git a/examples/oscillator_FMSynth/sketch.js b/examples/oscillator_FMSynth/sketch.js new file mode 100644 index 00000000..65a56f89 --- /dev/null +++ b/examples/oscillator_FMSynth/sketch.js @@ -0,0 +1,41 @@ +var carrier, modulator; + +// carrier frequency signal, a p5.Signal +var carrierFreq; + +// modulator frequency signal, a p5.Signal +var modFreq; + + +// output envelope +var env; + +function setup() { + carrier = new p5.Oscillator(); + + carrierFreq = new p5.Signal(240); + carrier.freq(carrierFreq); + carrier.start(); + + env = new p5.Env(0.05, 1, 0.5, 0); + carrier.amp(env); + + modulator = new p5.Oscillator(); + modulator.disconnect(); + modFreq = new p5.SignalMult(8); + modFreq.setInput(carrierFreq); + modulator.freq(modFreq); + modulator.start(); + + var m1 = new p5.SignalMult(); + m1.setInput(modulator); + m1.setValue(100); +} + +function draw() { + carrierFreq.fade(mouseX); +} + +function mousePressed() { + env.play(); +} \ No newline at end of file