1.0.3 • Published 7 years ago
audio-buffer-remix v1.0.3
audio-buffer-remix
Upmix or downmix channels in AudioBuffer or AudioBufferList by the following table:
Input Channels | Output Channels | Rules |
---|---|---|
1 (Mono) | 2 (Stereo) | output0 = input0output1 = input0 |
1 (Mono) | 4 (Quad) | output0 = input0output1 = input0output2 = 0output3 = 0 |
1 (Mono) | 6 (5.1) | output0 = 0output1 = 0output2 = input0output3 = 0output4 = 0output5 = 0 |
2 (Stereo) | 1 (Mono) | output0 = 0.5 * (input0 + input1) |
2 (Stereo) | 4 (Quad) | output0 = input0output1 = input1output2 = 0output3 = 0 |
2 (Stereo) | 6 (5.1) | output0 = input0output1 = input1output2 = 0output3 = 0output4 = 0output5 = 0 |
4 (Quad) | 1 (Mono) | output0 = 0.25 * (input0 + input1 + input2 + input3) |
4 (Quad) | 2 (Stereo) | output0 = 0.5 (input0 + input2)output1 = 0.5 (input1 + input3) |
4 (Quad) | 6 (5.1) | output0 = input0output1 = input1output2 = 0output3 = 0output4 = input2output5 = input3 |
6 (5.1) | 1 (Mono) | output0 = 0.7071 (input0 + input1) + input2 + 0.5 (input2 + input3) |
6 (5.1) | 2 (Stereo) | output0 = input0 + 0.7071 (input2 + input4)output1 = input1 + 0.7071 (input2 + input5) |
6 (5.1) | 4 (Quad) | output0 = input0 + 0.7071 input2output1 = input1 + 0.7071 input2output2 = input4output3 = input5 |
n | m | outputn = inputn |
Usage
const AudioBuffer = require('audio-buffer')
const remix = require('audio-buffer-remix')
let stereoBuffer = new AudioBuffer(2, 1024)
quadBuffer = remix(stereoBuffer, 4)
API
let dest = remix(source, channels|map, interpretation|{context, interpretation}?)
Take source
audio buffer and upmix/downmix its channels to dest
with the indicated number of channels
. options
may provide audio context
or interpretation type: 'discrete'
or 'speaker'
, see channelInterpretation MDN reference.
Alternatively pass map
− a list or object with channel mapping. Numbers as values map channels directly by numbers, null
drops channel from output and function with (destChannelData, source) => {}
signature expects to fill destChannelData
array.
const util = require('audio-buffer-utils')
let source = util.noise(util.create(1024, 2))
let dest = remix(source, {
//0 output channel - take first input channel data
0: 1,
//1 output channel - mute the data
1: null,
//2 output channel - mix 0 + 1 channels
2: (destChannel, source) => {
let left = source.getChannelData(0)
let right = source.getChannelData(1)
for (let i = 0; i < out.length; i++) {
destChannel[i] = left[i] * .5 + right[i] * .5
}
}
})
dest.numberOfChannels // 3
See also
- audio — high-level class for audio
- audio-buffer — audio buffer class for nodejs and browser
- audio-buffer-list — audio buffer class for nodejs and browser
- audio-buffer-utils — toolset for audio buffers