Small library to extract peaks from either a TypedArray of audio samples or a webaudio AudioBuffer into an Int8Array, Int16Array, or Int32Array.
MIT License
Small library to extract peaks from an array of audio samples or a webaudio AudioBuffer.
npm install webaudio-peaks --save
var extractPeaks = require("webaudio-peaks");
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
//decode an ArrayBuffer into an AudioBuffer
audioCtx.decodeAudioData(audioData, function (decodedData) {
//calculate peaks from an AudioBuffer
var peaks = extractPeaks(decodedData, 10000, true);
});
function to extract peaks from a TypedArray, or AudioBuffer
Params
TypedArray|AudioBuffer
- A source of audio samples.number
- Number of samples used to calculate a single peak.boolean
- Combine all channels into one array of peaks or not.number
- Sample to begin at. The offset is inclusive.number
- Sample to end at. The offset is exclusive.(8|16|32)
- Resolution of calculated peaks.Returns: object
{
length: `number`; //Number of calculated peaks,
//Computed peak data, length == #channels or 1 if isMono == true
//Each entry of type `Int{bits}Array`
data: `Array`;
bits: `(8|16|32)`; //Resolution of calculated peaks.
}