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)
+ * }
+ * }
+ *
+ *
+ * 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();
+ * }
+ *
+ *
+ * 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);
+ * }
+ * }
+ *
- * 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');