diff --git a/src/content/examples/en/17_Sound/00_Echo_Synth/code.js b/src/content/examples/en/17_Sound/00_Echo_Synth/code.js new file mode 100644 index 0000000000..f78084b875 --- /dev/null +++ b/src/content/examples/en/17_Sound/00_Echo_Synth/code.js @@ -0,0 +1,43 @@ +let osc, delay, env; + +function setup() { + let cnv = createCanvas(400, 400); + background(220); + textAlign(CENTER); + textSize(13); + text('click and drag mouse', width/2, 150); + + osc = new p5.Oscillator('sawtooth'); + osc.amp(0.74); + env = new p5.Envelope(0.01); + delay = new p5.Delay(0.12, 0.7); + + osc.disconnect(); + osc.connect(env); + env.disconnect(); + env.connect(delay); + + cnv.mousePressed(oscStart); + cnv.mouseReleased(oscStop); + cnv.mouseOut(oscStop); + describe('Click and release or hold, to play a square wave with delay effect.'); +} + +function oscStart() { + background(0, 255, 255); + text('release to hear delay', width/2, 150); + osc.start(); + env.triggerAttack(); +} + +function oscStop() { + background(220); + text('click and drag mouse', width/2, 150); + env.triggerRelease(); +} + +function draw() { + osc.freq(map(mouseY, height, 0, 440, 880)) + let dtime = map(mouseX, 0, width, 0.1, 0.5); + delay.delayTime(dtime); +} \ No newline at end of file diff --git a/src/content/examples/en/17_Sound/00_Echo_Synth/description.mdx b/src/content/examples/en/17_Sound/00_Echo_Synth/description.mdx new file mode 100644 index 0000000000..771f10ec30 --- /dev/null +++ b/src/content/examples/en/17_Sound/00_Echo_Synth/description.mdx @@ -0,0 +1,10 @@ +--- +featuredImage: "../../../images/featured/16_Async_Await_PromiseAll-thumbnail.png" +featuredImageAlt: Three random images loaded and displayed on a canvas after using async/await and Promise.all. +title: Echo Synth +oneLineDescription: Trigger a short sound with a variable echo effect. +--- + +This example demonstrates how to use the p5.sound.js add-on library. + +The sketch includes an oscillator (which produces a tone) and the Envelope and Delay processors. The echo effect is created through the combination of echo and delay. \ No newline at end of file