问题
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.
回答1:
This works for me:
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);
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.
回答2:
Yes, it works to square a signal this way. (I use it in my vocoder.) There should be no delay in doing things this way.
来源:https://stackoverflow.com/questions/31458161/web-audio-api-squaring-a-signal-by-using-a-gain