specshow
specshow(
S,options?):CanvasRenderingContext2D
Defined in: packages/pleco-xa/src/scripts/xa-display.js:235
Display a spectrogram/chromagram/CQT/etc on a Canvas element
Renders time-frequency data (spectrograms, chromagrams, CQT, etc.) to a Canvas with appropriate scaling, colormaps, and axis labels.
Parameters
Section titled “Parameters”Float32Array<ArrayBufferLike> | number[][]
2D spectrogram data [frequency, time]
options?
Section titled “options?”Display options
canvas
Section titled “canvas”HTMLCanvasElement
Target canvas element (required)
string
Colormap name (default: ‘magma’)
drawAxes
Section titled “drawAxes”boolean
Draw axis labels and ticks (default: true)
drawColorbar
Section titled “drawColorbar”boolean
Draw colorbar legend (default: false)
number
Maximum frequency for y-axis (default: sr/2)
number
Minimum frequency for y-axis (default: 0)
hopLength
Section titled “hopLength”number
Hop length in samples (default: 512)
number
Sample rate in Hz (default: 22050)
number
Maximum value for colormap (default: auto)
number
Minimum value for colormap (default: auto)
string
X-axis type: ‘time’, ‘frames’, ‘s’, ‘ms’ (default: ‘time’)
string
Y-axis type: ‘linear’, ‘log’, ‘mel’, ‘cqt_hz’, ‘cqt_note’ (default: ‘linear’)
Returns
Section titled “Returns”CanvasRenderingContext2D
Canvas 2D context with rendered spectrogram
Example
Section titled “Example”// Display mel spectrogramconst canvas = document.getElementById('spec-canvas');const S = melspectrogram(y, sr, { nMels: 128 });specshow(S, { canvas: canvas, sr: 22050, hopLength: 512, yAxis: 'mel', cmap: 'magma'});