Web Audio API — squaring a signal by using a Gain

纵饮孤独 提交于 2020-02-06 08:07:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!