问题描述
是否可以通过创建 Gain
实例并将信号连接到增益输入和幅度控制参数来对信号进行平方?因为我至少在 Firefox 中看到了奇怪的结果.我可以看到 Tone.js 使用波形整形器代替 pow
操作,所以也许这是要走的路.但我很好奇,因为 API 说 gain
参数是音频速率,显然必须涉及一些延迟.
Should it be possible to square a signal by creating a Gain
instance and connecting the signal both to the gain input and amplitude control parameter? Because I am seeing odd results at least in Firefox. I can see that Tone.js uses a wave-shaper instead for a pow
operation, so perhaps this is the way to go. But I'm curious, since the API says the gain
parameter is audio-rate, obviously there must be some delays involved.
推荐答案
这对我有用:
var c = new AudioContext();
var o = c.createOscillator();
var g = c.createGain();
g.gain.value = 0;
g.connect(c.destination);
o.connect(g);
o.connect(g.gain);
o.start();
o.stop(c.currentTime + 2);
你听不出来,但如果你把代码粘贴到 http://hoch.github.io/canopy/,可以看到正弦波已经平方了.
You can't tell from listening but if you paste the code into http://hoch.github.io/canopy/, you can see that the sine wave has been squared.
这篇关于Web Audio API — 使用增益对信号进行平方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!