Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
audio-buffer
Advanced tools
The audio-buffer npm package provides a simple and efficient way to handle audio data in the form of buffers. It allows you to create, manipulate, and process audio buffers, which are essential for various audio processing tasks such as audio synthesis, effects, and analysis.
Creating an Audio Buffer
This feature allows you to create a new audio buffer with a specified number of channels and samples per channel. In this example, a stereo buffer with 44100 samples per channel is created.
const AudioBuffer = require('audio-buffer');
const buffer = new AudioBuffer(2, 44100); // 2 channels, 44100 samples per channel
Filling an Audio Buffer with Data
This feature allows you to fill an audio buffer with data. In this example, each channel of the buffer is filled with a sine wave.
const AudioBuffer = require('audio-buffer');
const buffer = new AudioBuffer(2, 44100);
for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
const data = buffer.getChannelData(channel);
for (let i = 0; i < data.length; i++) {
data[i] = Math.sin(2 * Math.PI * i / 44100); // Example: filling with a sine wave
}
}
Copying Audio Buffer Data
This feature allows you to copy data from one audio buffer to another. In this example, data from buffer1 is copied to buffer2.
const AudioBuffer = require('audio-buffer');
const buffer1 = new AudioBuffer(2, 44100);
const buffer2 = new AudioBuffer(2, 44100);
buffer2.copyToChannel(buffer1.getChannelData(0), 0);
buffer2.copyToChannel(buffer1.getChannelData(1), 1);
Resampling an Audio Buffer
This feature allows you to resample an audio buffer to a different sample rate. In this example, the buffer is resampled from 44100 samples per channel to 22050 samples per channel.
const AudioBuffer = require('audio-buffer');
const resample = require('audio-buffer-resample');
const buffer = new AudioBuffer(2, 44100);
const resampledBuffer = resample(buffer, 22050); // Resample to 22050 samples per channel
The audio-buffer-utils package provides a set of utility functions for working with audio buffers, such as copying, slicing, and filling buffers. It offers more specialized functions compared to audio-buffer, making it a good complement for more advanced audio buffer manipulations.
The audio-context package provides a simplified interface for creating and managing Web Audio API contexts. While it focuses more on the context management rather than buffer manipulation, it can be used in conjunction with audio-buffer for comprehensive audio processing tasks.
The audio-buffer-list package allows you to manage a list of audio buffers, providing functionalities such as concatenation and splitting of buffers. It is useful for handling multiple audio buffers in a more organized manner, which can complement the basic buffer manipulation provided by audio-buffer.
AudioBuffer optimal implementation for node. In browser provides just a useful constructor for web-audio’s AudioBuffer, in node is also useful instead of Buffer in audio streams.
var AudioBuffer = require('audio-buffer');
//Create audio buffer from a data source or of a length.
//Data is interpreted as a planar sequence of float32 samples.
//It can be Array, TypedArray, ArrayBuffer, Buffer, AudioBuffer, DataView, NDArray etc.
var buffer = new AudioBuffer(channels?, data|length, sampleRate?);
//Duration of the underlying audio data, in seconds
buffer.duration;
//Number of samples per channel
buffer.length;
//Default sample rate is 44100
buffer.sampleRate;
//Default number of channels is 2
buffer.numberOfChannels;
//Get array containing the data for the channel (not copied)
buffer.getChannelData(channel);
//Place data from channel to destination Float32Array
buffer.copyFromChannel(destination, channelNumber, startInChannel?);
//Place data from source Float32Array to the channel
buffer.copyToChannel(source, channelNumber, startInChannel?);
//Some special properties, it’s unlikely you will ever need them.
//Type of storage to use for data - replace to Float64Array, if needed.
//It will only affect node implementation.
AudioBuffer.FloatArray = Float32Array;
//In browser, you can set the audio context (online/offline).
//By default it is taken from audio-context module.
AudioBuffer.context;
pcm-util — utils for audio format convertions.
ndsamples — audio-wrapper for ndarrays. A somewhat alternative approach to wrap audio data, based on ndarrays, used by some modules in livejs.
FAQs
AudioBuffer class for node/browser
The npm package audio-buffer receives a total of 25,361 weekly downloads. As such, audio-buffer popularity was classified as popular.
We found that audio-buffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.