diff --git a/src/analysis/FFT.js b/src/analysis/FFT.js index 1a0abdc..e1e9af0 100644 --- a/src/analysis/FFT.js +++ b/src/analysis/FFT.js @@ -85,6 +85,48 @@ class FFT extends p5soundNode { * @method analyze * @for FFT * @returns {Array} Array of amplitude values from 0 to 1. + * @example + *
+ * + * let soundfile, fft; + * + * async function setup() { + * createCanvas(100, 100); + * soundfile = await loadSound('assets/chime.mp3'); + * textAlign(CENTER); + * textSize(10); + * + * fft = new p5.FFT(); + * soundfile.connect(fft); + * soundfile.loop(); + * } + * + * function mousePressed() { + * if(!soundfile.isPlaying()) { + * soundfile.play(); + * } + * else { + * soundfile.stop(); + * } + * } + * + * function draw() { + * background(220); + * + * text('tap to play', width/2, height/2 - 20); + * let spectrum = fft.analyze(); + * + * noStroke(); + * fill(0); + * + * for (let i = 0; i < spectrum.length; i++) { + * let x = map(i, 0, spectrum.length, 0, width); + * let h = -height + map(spectrum[i], 0, 0.1, height, 0); + * rect(x, height, width / spectrum.length, h * 4) + * } + * } + * + *
*/ analyze() { return this.analyzer.getValue(); @@ -95,6 +137,47 @@ class FFT extends p5soundNode { * @method waveform * @for FFT * @return {Array} Array of sample values from -1 to -1. + * @example + *
+ * + * let soundfile, fft; + * async function setup() { + * createCanvas(100, 100); + * soundfile = await loadSound('assets/chime.mp3'); + * textAlign(CENTER); + * textSize(10); + * + * fft = new p5.FFT(); + * soundfile.connect(fft); + * soundfile.loop(); + * } + * + * function mousePressed() { + * if(!soundfile.isPlaying()) { + * soundfile.play(); + * } + * else { + * soundfile.stop(); + * } + * } + * + * function draw() { + * background(220); + * + * text('tap to play', width/2, height/2 - 20); + * let waveform = fft.waveform(); + * noFill(); + * beginShape(); + * stroke(20); + * for (let i = 0; i < waveform.length; i++){ + * let x = map(i, 0, waveform.length, 0, width); + * let y = map( waveform[i], -1, 1, 0, height); + * vertex(x,y); + * } + * endShape(); + * } + * + *
*/ waveform() { return this.samples.getValue(); diff --git a/src/effects/Delay.js b/src/effects/Delay.js index a6a37d9..a1097f8 100644 --- a/src/effects/Delay.js +++ b/src/effects/Delay.js @@ -187,6 +187,47 @@ class Delay extends p5soundMixEffect { * @param {Object} unit A p5.sound source such as an Oscillator, Soundfile, or AudioIn object. * @param {Number} [delayTime] The amount of delay in seconds. A number between 0 and 1. Keeps the current delay time if omitted. * @param {Number} [feedback] The amount of feedback. A number between 0 and 1. Keeps the current feedback amount if omitted. + * @example + *
+ * + * let delay, osc; + * + * function setup() { + * createCanvas(100, 100); + * textAlign(CENTER); + * text('tap to play', width/2, height/2); + * + * osc = new p5.Oscillator('sine'); + * osc.disconnect(); + * delay = new p5.Delay(); + * //use the delay effect to process the oscillator with a delay time of 0.240 seconds and a feedback amount of 0.7 + * delay.process(osc, 0.240, 0.7); + * } + * + * function mousePressed() { + * osc.start(); + * } + * + * function mouseReleased() { + * osc.stop(); + * } + * + * function draw() { + * background(220) + * let dtime = map(mouseX, 0, width, 0.1, 0.5); + * delay.delayTime(dtime); + * let feedback = map(mouseY, 0, height, 0.1, 0.99); + * delay.feedback(feedback); + * if(!osc.started) { + * text('tap to play', width/2, height/2); + * } + * else { + * text('delay time: ' + dtime.toFixed(2), width/2, height/2); + * text('feedback: ' + feedback.toFixed(2), width/2, height/2 + 20); + * } + * } + *
+ * */ process(input, delayTime = this.node.delayTime.value, feedback = this.node.feedback.value) { //both values are set immediately rather than ramped: process() is usually diff --git a/src/effects/PitchShifter.js b/src/effects/PitchShifter.js index 389ed1e..c43455d 100644 --- a/src/effects/PitchShifter.js +++ b/src/effects/PitchShifter.js @@ -15,7 +15,7 @@ import { p5soundNode, resolveInput } from "../core/p5soundNode.js"; * @example *
* - * let cnv, pitchShifter; + * let pitchShifter; * * async function setup() { * describe('a sketch that pitches the microphone input up an octave'); @@ -53,7 +53,7 @@ class PitchShifter extends p5soundNode { * @example *
* - * let cnv, pitchShifter; + * let pitchShifter; * * async function setup() { * describe('a sketch that pitches the microphone input up an octave');