Reference p5.FFT

p5.FFT

Analyze the frequency spectrum and waveform of sounds.

Examples

Syntax

p5.FFT([fftSize])

Parameters

fftSize
Number: FFT anaylsis size. Must be a power of two between 16 and 1024. Defaults to 32.

Methods

setInput

Set the input source for the FFT analysis. If no source is provided, FFT will analyze all sound in the sketch.

waveform
Returns an array of sample values from the input audio.
analyze
Returns the frequency spectrum of the input signal.
getEnergy

Returns the amount of energy (volume) at a specific frequency, or the average amount of energy between two frequencies. Accepts Number(s) corresponding to frequency (in Hz), or a "string" corresponding to predefined frequency ranges ("bass", "lowMid", "mid", "highMid", "treble"). Returns a range between 0 (no energy/volume at that frequency) and 255 (maximum energy). NOTE: analyze() must be called prior to getEnergy(). analyze() tells the FFT to analyze frequency data, and getEnergy() uses the results to determine the value at a specific frequency or range of frequencies.

getCentroid

Returns the spectral centroid of the input signal. NOTE: analyze() must be called prior to getCentroid(). Analyze() tells the FFT to analyze frequency data, and getCentroid() uses the results determine the spectral centroid.

smooth

Smooth FFT analysis by averaging with the last analysis frame.

linAverages

Returns an array of average amplitude values for a given number of frequency bands split equally. N defaults to 16. NOTE: analyze() must be called prior to linAverages(). Analyze() tells the FFT to analyze frequency data, and linAverages() uses the results to group them into a smaller set of averages.

logAverages

Returns an array of average amplitude values of the spectrum, for a given set of Octave Bands NOTE: analyze() must be called prior to logAverages(). Analyze() tells the FFT to analyze frequency data, and logAverages() uses the results to group them into a smaller set of averages.

getOctaveBands

Calculates and Returns the 1/N Octave Bands N defaults to 3 and minimum central frequency to 15.625Hz. (1/3 Octave Bands ~= 31 Frequency Bands) Setting fCtr0 to a central value of a higher octave will ignore the lower bands and produce less frequency groups.

Notice any errors or typos? Please let us know. Please feel free to edit src/FFT.js and open a pull request!

Related References