Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion src/analysis/FFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,48 @@ class FFT extends p5soundNode {
* @method analyze
* @for FFT
* @returns {Array} Array of amplitude values from 0 to 1.
* @example
* <div>
* <code>
* 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)
* }
* }
* </code>
* </div>
*/
analyze() {
return this.analyzer.getValue();
Expand All @@ -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
* <div>
* <code>
* 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();
* }
* </code>
* </div>
*/
waveform() {
return this.samples.getValue();
Expand Down
6 changes: 3 additions & 3 deletions src/core/p5soundSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +65,7 @@ class p5soundSource extends p5soundNode {
}

/**
* Stops the p5 sound source.
* Stops a p5 sound source.
* @method stop
* @for p5soundSource
* @example
Expand Down
41 changes: 41 additions & 0 deletions src/effects/Delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <div>
* <code>
* 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);
* }
* }
* </div>
* </code>
*/
process(input, delayTime = this.node.delayTime.value, feedback = this.node.feedback.value) {
//both values are set immediately rather than ramped: process() is usually
Expand Down
5 changes: 2 additions & 3 deletions src/effects/Envelope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/effects/Gain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/effects/PitchShifter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { p5soundNode, resolveInput } from "../core/p5soundNode.js";
* @example
* <div>
* <code>
* let cnv, pitchShifter;
* let pitchShifter;
*
* async function setup() {
* describe('a sketch that pitches the microphone input up an octave');
Expand Down Expand Up @@ -53,7 +53,7 @@ class PitchShifter extends p5soundNode {
* @example
* <div>
* <code>
* let cnv, pitchShifter;
* let pitchShifter;
*
* async function setup() {
* describe('a sketch that pitches the microphone input up an octave');
Expand Down
4 changes: 2 additions & 2 deletions src/sources/AudioIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +108,7 @@ class AudioIn extends p5soundSource {
});
}
/**
* Stop the audio input.
* Stop the audio input device.
* @method stop
* @for AudioIn
* @example
Expand Down
2 changes: 1 addition & 1 deletion src/sources/Noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/sources/SoundFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class SoundFile extends p5soundSource {
}

/**
* Start the soundfile.
* Start the soundfile. Same as the play() method.
* @method start
* @for SoundFile
* @example
Expand Down