Coder Social home page Coder Social logo

audio-buffer-utils's Introduction

Utility functions for Audio Buffers.

Usage

$ npm install audio-buffer-utils

var utils = require('audio-buffer-utils');

//Create a new buffer from any argument.
//Data can be a length, an array with channels' data, an other buffer or plain array.
utils.create(channels?, data, sampleRate?);

//Create a new buffer with the same characteristics as `buffer`,
//contents are undefined.
utils.shallow(buffer);

//Create a new buffer with the same characteristics as `buffer`,
//fill it with a copy of `buffer`'s data, and return it.
utils.clone(buffer);

//Copy the data from one buffer to another, with optional offset
utils.copy(fromBuffer, result, offset?);

//Reverse `buffer`. Place data to `result` buffer, if any, otherwise modify `buffer` in-place.
utils.reverse(buffer, result?);

//Invert `buffer`. Place data to `result` buffer, if any, otherwise modify `buffer` in-place.
utils.invert(buffer, result?);

//Zero all of `buffer`'s channel data. `buffer` is modified in-place.
utils.zero(buffer);

//Fill `buffer` with random data. `buffer` is modified in-place.
utils.noise(buffer);

//Test whether the content of N buffers is the same.
utils.equal(bufferA, bufferB, ...);

//Fill `buffer` with provided function or value.
//Place data to `result` buffer, if any, otherwise modify `buffer` in-place.
//Pass optional `start` and `end` indexes.
utils.fill(buffer, result?, value|function (sample, channel, idx) {
	return sample / 2;
}, start?, end?);

//Create a new buffer by mapping the samples of the current one.
utils.map(buffer, function (sample, channel, idx) {
	return sample / 2;
});

//Create a new buffer by slicing the current one.
utils.slice(buffer, start?, end?);

//Create a new buffer by concatting passed buffers.
//Channels are extended to the buffer with maximum number.
//Sample rate is changed to the maximum within the buffers.
utils.concat(buffer1, buffer2, buffer3, ...);

//Return new buffer based on the passed one, with shortened/extended length.
//Initial data is whether sliced or filled with zeros.
//Useful to change duration: `util.resize(buffer, duration * buffer.sampleRate);`
utils.resize(buffer, length);

//Shift signal in the time domain by `offset` samples, filling with zeros.
//Modify `buffer` in-place.
utils.shift(buffer, offset);

//Shift signal in the time domain by `offset` samples, in circular fashion.
//Modify `buffer` in-place.
utils.rotate(buffer, offset);

//Fold buffer into a single value. Useful to generate metrics, like loudness, average, etc.
utils.reduce(buffer, function (previousValue, currendValue, channel, idx, channelData) {
	return previousValue + currentValue;
}, startValue?);

//Normalize buffer by the max value, limit to the -1..+1 range.
//Place data to `result` buffer, if any, otherwise modify `buffer` in-place.
utils.normalize(buffer, result?, start?, end?);

//Create buffer with trimmed zeros from the start and/or end, by the threshold.
utils.trim(buffer, threshold?);
utils.trimStart(buffer, threshold?);
utils.trimEnd(buffer, threshold?)

//Mix second buffer into the first one. Pass optional weight value or mixing function.
util.mix(bufferA, bufferB, ratio|fn(valA, valB, channel, idx)?, offset?);

//Return buffer size, in bytes. Use pretty-bytes package to format bytes to a string, if needed.
utils.size(buffer);

//Get channels' data in array. Pass existing array to transfer the data to it.
//Useful in audio-workers to transfer buffer to output.
utils.data(buffer, data?);

Related

audio-buffer — audio data container, both for node/browser.
pcm-util — utils for low-level pcm buffers, like audio formats etc.
scijs — DSP utils, like fft, resample, scale etc.

audio-buffer-utils's People

Contributors

dy avatar

Watchers

 avatar  avatar

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.