Reputation: 67310
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.
Upvotes: 0
Views: 406
Reputation: 6056
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.
Upvotes: 2
Reputation: 13918
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.
Upvotes: 1