Skip to content

Commit

Permalink
adding oscillator_fmSynth example
Browse files Browse the repository at this point in the history
  • Loading branch information
therewasaguy committed Aug 23, 2014
1 parent 7a14272 commit 41b1879
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/oscillator_FMSynth/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<head>
<script language="javascript" type="text/javascript" src="../../lib/p5.js"></script>

<script language="javascript" type="text/javascript" src="../../lib/addons/p5.dom.js"></script>

<script language="javascript" type="text/javascript" src="../../lib/p5.sound.js"></script>

<script language="javascript" type="text/javascript" src="sketch.js"></script>

</head>
41 changes: 41 additions & 0 deletions examples/oscillator_FMSynth/sketch.js
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 41b1879

Please sign in to comment.