forked from processing/p5.js-sound
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JoshuaStorm
committed
Aug 26, 2016
1 parent
56facfe
commit 236d943
Showing
9 changed files
with
270 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!doctype html> | ||
<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> | ||
|
||
<body> | ||
click to trigger saw oscillator through heavy distortion | ||
|
||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Trigger an oscillator processed through distortion. | ||
*/ | ||
|
||
var env; // this is the env | ||
var osc; // this oscillator that will be effected by the distortion | ||
var distortion; // this is the waveshaper distortion effect | ||
|
||
var fft; | ||
|
||
function setup() { | ||
createCanvas(windowWidth, windowHeight); | ||
fft = new p5.FFT(0, 256); | ||
|
||
|
||
env = new p5.Env(); | ||
env.setADSR(0.01, 0.2, 0.1, 0.3); | ||
env.setRange(1.0, 0.0); | ||
|
||
osc = new p5.SawOsc(); // connects to master output by default | ||
osc.start(0); | ||
osc.freq(220); | ||
osc.amp(env); | ||
osc.disconnect(); // Disconnect from output to process through distortion | ||
|
||
// Create a waveshaper distortion with 2x oversampling | ||
distortion = new p5.Distortion(2000, '4x'); | ||
osc.connect(distortion); | ||
} | ||
|
||
function draw() { | ||
var samples = fft.waveform(); | ||
drawOscilloscope(samples); | ||
} | ||
|
||
function drawOscilloscope(samples) { | ||
var yTranslateScope = 50; | ||
var xTranslateScope = 50; | ||
var scopeWidth = width / 5; | ||
var scopeHeight = height / 4; | ||
|
||
fill(177, 177, 177); | ||
rect(xTranslateScope, yTranslateScope, scopeWidth, scopeHeight); | ||
|
||
stroke(0, 0, 0); | ||
strokeWeight(0.5); | ||
|
||
beginShape(); | ||
for (var sampleIndex in samples) { | ||
var x = map(sampleIndex, 0, samples.length, 0, scopeWidth); | ||
var y = map(samples[sampleIndex], -1, 1, -scopeHeight / 2, scopeHeight / 2); | ||
vertex(x + xTranslateScope, y + scopeHeight/2 + yTranslateScope); | ||
} | ||
endShape(); | ||
} | ||
|
||
function mousePressed() { | ||
env.triggerAttack(); | ||
} | ||
|
||
function mouseReleased() { | ||
env.triggerRelease(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.