naomiaro/webaudio-peaks

extractPeaks(decodedData, 10000, true, 0, 0); doesn't return empty peaks

a3626a opened this issue · 1 comments

extractPeaks(decodedData, 10000, true, 1, 1); returns empty peaks
but extractPeaks(decodedData, 10000, true, 0, 0); does not. (gives peaks for the entire buffer)

I think extractPeaks(decodedData, 10000, true, 0, 0) should return emtpy peaks. If you just think it is perfectly normal extractPeaks(decodedData, 10000, true, 0, 0) to return peaks for the entire buffer, I will just close this issue

it is because :

webaudio-peaks/index.js

Lines 128 to 141 in 354c143

if (typeof source.subarray === "undefined") {
for (c = 0; c < numChan; c++) {
channel = source.getChannelData(c);
cueIn = cueIn || 0;
cueOut = cueOut || channel.length;
slice = channel.subarray(cueIn, cueOut);
peaks.push(extractPeaks(slice, samplesPerPixel, bits));
}
}
else {
cueIn = cueIn || 0;
cueOut = cueOut || source.length;
peaks.push(extractPeaks(source.subarray(cueIn, cueOut), samplesPerPixel, bits));
}

cueOut = cueOut || channel.length; is channel.length when cueOut == 0. I think it can be changed into cueOut = cueOut != undefined ? cueOut : channel.length;

Hello!

Yes, this looks like it definitely should be updated to return zero peaks. Hopefully I can update this sometime soon.