如何将双声道音频转换为能够控制每个声道音量的单声道?
How to convert dual channel audio to mono with ability to control each channel volume?
我正在尝试在两个耳机中收听 2 声道音频(左右耳机中的音频相同)。
现状:
滑块居中 - 效果非常好(两个耳机的两个通道)。
滑块在右侧 - 效果非常好(两个耳机的右声道)。
滑块在左侧 - 不起作用(左声道仅在左耳机中)。
const splitter = wavesurfer.backend.ac.createChannelSplitter(2);
const merger = wavesurfer.backend.ac.createChannelMerger(2);
const leftGain = wavesurfer.backend.ac.createGain();
const rightGain = wavesurfer.backend.ac.createGain();
const panner = wavesurfer.backend.ac.createPanner();
splitter.connect(leftGain, 0);
splitter.connect(rightGain, 1);
leftGain.connect(merger, 0, 0);
rightGain.connect(merger, 0, 1);
merger.connect(panner);
let slider = document.querySelector('#Slider');
$(slider ).change(function () {
rightGain.gain.value = Number(slider.value);
leftGain.gain.value = 1- (Number(slider.value));
})
wavesurfer.backend.setFilters([splitter, leftGain, rightGain, merger]);
当滑块位于左侧时,我只想在两个耳机中听到左声道。
有人可以帮助我吗?
Problem
当调用setFilters()时,waversurfer.js将把所有提供的节点连接成一个简单的链。在您的情况下,这意味着它将像这样创建额外的连接:
splitter.connect(leftGain);
leftGain.connect(rightGain);
rightGain.connect(merger);
这可能不是您想要的。但是可以利用该行为。我稍微修改了你的例子。
const input = wavesurfer.backend.ac.createGain();
const splitter = wavesurfer.backend.ac.createChannelSplitter(2);
const merger = wavesurfer.backend.ac.createChannelMerger(2);
const leftGain = wavesurfer.backend.ac.createGain();
const rightGain = wavesurfer.backend.ac.createGain();
// This will make sure that a mono signal gets upmixed to stereo.
// If you always have stereo sound you can remove it.
input.channelCountMode = 'explicit';
// It is only necessary to connect the right channel
// because this is the one which needs optional parameters.
splitter.connect(rightGain, 1);
rightGain.connect(merger);
rightGain.connect(merger, 0, 1);
// Only the one connection which needs an optional parameter
// needs to be done for the left channel
leftGain.connect(merger, 0, 1);
// wavesufer.js will connect everything else.
wavesurfer.backend.setFilters([ input, splitter, leftGain, merger ]);
我还添加了另一个 GainNode 作为第一个节点,以确保在信号是单声道的情况下将其上混为立体声。我删除了 PannerNode,因为它没有在您的示例中使用。
我正在尝试在两个耳机中收听 2 声道音频(左右耳机中的音频相同)。
现状:
滑块居中 - 效果非常好(两个耳机的两个通道)。
滑块在右侧 - 效果非常好(两个耳机的右声道)。
滑块在左侧 - 不起作用(左声道仅在左耳机中)。
const splitter = wavesurfer.backend.ac.createChannelSplitter(2);
const merger = wavesurfer.backend.ac.createChannelMerger(2);
const leftGain = wavesurfer.backend.ac.createGain();
const rightGain = wavesurfer.backend.ac.createGain();
const panner = wavesurfer.backend.ac.createPanner();
splitter.connect(leftGain, 0);
splitter.connect(rightGain, 1);
leftGain.connect(merger, 0, 0);
rightGain.connect(merger, 0, 1);
merger.connect(panner);
let slider = document.querySelector('#Slider');
$(slider ).change(function () {
rightGain.gain.value = Number(slider.value);
leftGain.gain.value = 1- (Number(slider.value));
})
wavesurfer.backend.setFilters([splitter, leftGain, rightGain, merger]);
当滑块位于左侧时,我只想在两个耳机中听到左声道。 有人可以帮助我吗?
Problem
当调用setFilters()时,waversurfer.js将把所有提供的节点连接成一个简单的链。在您的情况下,这意味着它将像这样创建额外的连接:
splitter.connect(leftGain);
leftGain.connect(rightGain);
rightGain.connect(merger);
这可能不是您想要的。但是可以利用该行为。我稍微修改了你的例子。
const input = wavesurfer.backend.ac.createGain();
const splitter = wavesurfer.backend.ac.createChannelSplitter(2);
const merger = wavesurfer.backend.ac.createChannelMerger(2);
const leftGain = wavesurfer.backend.ac.createGain();
const rightGain = wavesurfer.backend.ac.createGain();
// This will make sure that a mono signal gets upmixed to stereo.
// If you always have stereo sound you can remove it.
input.channelCountMode = 'explicit';
// It is only necessary to connect the right channel
// because this is the one which needs optional parameters.
splitter.connect(rightGain, 1);
rightGain.connect(merger);
rightGain.connect(merger, 0, 1);
// Only the one connection which needs an optional parameter
// needs to be done for the left channel
leftGain.connect(merger, 0, 1);
// wavesufer.js will connect everything else.
wavesurfer.backend.setFilters([ input, splitter, leftGain, merger ]);
我还添加了另一个 GainNode 作为第一个节点,以确保在信号是单声道的情况下将其上混为立体声。我删除了 PannerNode,因为它没有在您的示例中使用。