Git Product home page Git Product logo

webaudio-peaks's Introduction

webaudio-peaks

Small library to extract peaks from an array of audio samples or a webaudio AudioBuffer.

npm

Installation

npm install webaudio-peaks --save

Basic Usage

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);
});

extractPeaks(source, samplesPerPixel, isMono, cueIn, cueOut, bits)

function to extract peaks from a TypedArray, or AudioBuffer

Params

  • source TypedArray|AudioBuffer - A source of audio samples.
  • samplesPerPixel number - Number of samples used to calculate a single peak.
  • isMono boolean - Combine all channels into one array of peaks or not.
  • cueIn number - Sample to begin at. The offset is inclusive.
  • cueOut number - Sample to end at. The offset is exclusive.
  • bits (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.
}

License

MIT License

webaudio-peaks's People

Contributors

naomiaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

webaudio-peaks's Issues

Can't get stereo data

Hi there, was just trying to use this to get stereo peaks but I always get a single array in 'data'
This seems to be line 112 in index.js always causing isMono to get set to true.

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

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.