diff --git a/src/analysis/FFT.js b/src/analysis/FFT.js index 1a0abdc..dbd63cc 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(); @@ -94,7 +136,48 @@ class FFT extends p5soundNode { * Returns an array of sample values from the input audio. * @method waveform * @for FFT - * @return {Array} Array of sample values from -1 to -1. + * @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/core/p5soundSource.js b/src/core/p5soundSource.js index d0c5157..4f1ad00 100644 --- a/src/core/p5soundSource.js +++ b/src/core/p5soundSource.js @@ -18,9 +18,9 @@ class p5soundSource extends p5soundNode { this.started = false; } /** - * Starts the p5 sound source. + * Starts a p5 sound source. * - * Should be called from a user interaction such as MousePressed() in order to adhere to the browser's autoplay policy. + * Must be called from a user interaction such as mousePressed() in order to adhere to the browser's autoplay policy. * @method start * @for p5soundSource * @example @@ -65,7 +65,7 @@ class p5soundSource extends p5soundNode { } /** - * Stops the p5 sound source. + * Stops a p5 sound source. * @method stop * @for p5soundSource * @example 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/Envelope.js b/src/effects/Envelope.js index e676a9e..3af4b97 100644 --- a/src/effects/Envelope.js +++ b/src/effects/Envelope.js @@ -140,9 +140,8 @@ class Envelope extends p5soundNode { } /** - * Trigger the Release of the envelope. Similar to releasing the key on - * a piano and letting the sound fade according to the release level and - * release time. + * Triggers the "release" of an envelope. Akin to letting go of a key on + * the piano after striking its. * @method triggerRelease * @for Envelope * @example diff --git a/src/effects/Gain.js b/src/effects/Gain.js index 23e4fa2..2436060 100644 --- a/src/effects/Gain.js +++ b/src/effects/Gain.js @@ -8,7 +8,7 @@ import { Gain as ToneGain } from "tone/build/esm/core/context/Gain.js"; import { p5soundNode, resolveInput } from "../core/p5soundNode.js"; /** - * Generate a gain node to use for mixing and main volume. + * Generate a gain node to use for mixing and adjusting volume levels. * @class Gain * @constructor * @extends p5soundNode 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'); diff --git a/src/sources/AudioIn.js b/src/sources/AudioIn.js index 566c63b..66ee8aa 100644 --- a/src/sources/AudioIn.js +++ b/src/sources/AudioIn.js @@ -56,7 +56,7 @@ class AudioIn extends p5soundSource { this.node = new ToneUserMedia().connect(this.output); } /** - * Start the audio input. + * Start the audio input device. * @method start * @for AudioIn * @example @@ -108,7 +108,7 @@ class AudioIn extends p5soundSource { }); } /** - * Stop the audio input. + * Stop the audio input device. * @method stop * @for AudioIn * @example diff --git a/src/sources/Noise.js b/src/sources/Noise.js index 0878cf9..1515c29 100644 --- a/src/sources/Noise.js +++ b/src/sources/Noise.js @@ -54,7 +54,7 @@ class Noise extends p5soundSource { /** * Changes the type of noise function. * - * White noise is brighter and more "full spectrum" while 'pink' and 'brown' noise is a bit darker. + * White noise is brighter and has a wider spectrum while 'pink' and 'brown' noise sound warmer. * @method type * @for Noise * @param {String} type the type of noise (white, pink, brown) diff --git a/src/sources/SoundFile.js b/src/sources/SoundFile.js index 28a56b7..9a56435 100644 --- a/src/sources/SoundFile.js +++ b/src/sources/SoundFile.js @@ -113,7 +113,7 @@ class SoundFile extends p5soundSource { } /** - * Start the soundfile. + * Start the soundfile. Same as the play() method. * @method start * @for SoundFile * @example