From a62583c9ec53a2dadb0649d48f5edf1f0b9f563e Mon Sep 17 00:00:00 2001 From: Peter Prince Date: Mon, 15 Oct 2018 10:35:47 +0100 Subject: [PATCH] Add optional callback function Parameters are now handed to drawSpectrogram in a params object. --- wav-spectrogram.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wav-spectrogram.js b/wav-spectrogram.js index 928c707..12be7f9 100644 --- a/wav-spectrogram.js +++ b/wav-spectrogram.js @@ -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) => { @@ -174,6 +181,8 @@ function drawSpectrogram(arrayBuffer, canvasElem, cmap, nfft = 512, frameLengthM } + typeof callback === 'function' && callback(); + }); }