在Javascript中控制音频平衡(L/R)
我想在使用此代码时控制音频平衡在Javascript中控制音频平衡(L/R),javascript,audio,balance,Javascript,Audio,Balance,我想在使用此代码时控制音频平衡 var oscillator = audioCtx.createOscillator(); oscillator.type = 'square'; oscillator.frequency.value = frequency; // value in hertz oscillator.connect(audioCtx.destination); oscillator.start(); setTimeout(function(){oscillator.stop()
var oscillator = audioCtx.createOscillator();
oscillator.type = 'square';
oscillator.frequency.value = frequency; // value in hertz
oscillator.connect(audioCtx.destination);
oscillator.start();
setTimeout(function(){oscillator.stop();}, duration);
而且当我播放本地mp3文件时。
如何执行此操作?使用以下方法向链中添加一个:
现在,您可以使用以下方式控制L/R:
panner.pan.value = someValue; // value in the range -1 (L) to 1 (R)
功能示例:
var audioCtx=new(AudioContext | | webkitadiocontext)();
var振荡器=audioCtx.create振荡器();
var panner=audioCtx.createStereoPanner();
振荡器类型='square';
振荡器.frequency.value=440;//赫兹值
振荡器。连接(平移器);
panner.connect(audioCtx.destination);
start();
document.querySelector(“输入”).oninput=function(){
panner.pan.value=+this.value;
};
setInterval(函数(){
振荡器.frequency.value=Math.round(Math.random()*10)*400+200;
}, 100);代码>
lr
我已经看到了这一点,但在我(最新)的FF中没有任何代码起作用。例如,我得到了错误“@ObEfamI.js:68:1”,您是否尝试实现链接到的第二个答案中的createPanner
?(还有一个)。也值得一看。非常感谢!!我可以用它,它工作得很好!
panner.pan.value = someValue; // value in the range -1 (L) to 1 (R)