Skip to content

Commit

Permalink
Add optional callback function
Browse files Browse the repository at this point in the history
Parameters are now handed to drawSpectrogram in a params object.
  • Loading branch information
pcprince committed Oct 15, 2018
1 parent fdc7db8 commit a62583c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions wav-spectrogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ function medianFilter(array) {

}

function drawSpectrogram(arrayBuffer, canvasElem, cmap, nfft = 512, frameLengthMs = 0.1, frameStepMs = 0.005) {
function drawSpectrogram(params, callback) {

var err, sampleRate, samples, sampleArray, frameLength, frameStep, numFrames, paddedArrayLength, frames, i, maxValue, minValue, spectrumFrames, spectrum, m, n, a, o, p, ctx, specWidth, specHeight, colours;
var arrayBuffer, canvasElem, cmap, nfft, frameLengthMs, frameStepMs, err, sampleRate, samples, sampleArray, frameLength, frameStep, numFrames, paddedArrayLength, frames, i, maxValue, minValue, spectrumFrames, spectrum, m, n, a, o, p, ctx, specWidth, specHeight, colours;

arrayBuffer = params.arrayBuffer;
canvasElem = params.canvasElem;
cmap = params.cmap;
nfft = params.nfft || 512;
frameLengthMs = params.frameLengthMs || 0.1;
frameStepMs = params.frameStepMs || 0.005;

decode(arrayBuffer, (err, audioBuffer) => {

Expand Down Expand Up @@ -174,6 +181,8 @@ function drawSpectrogram(arrayBuffer, canvasElem, cmap, nfft = 512, frameLengthM

}

typeof callback === 'function' && callback();

});

}
Expand Down

0 comments on commit a62583c

Please sign in to comment.