How to modulate the pulsewidth of the Web Audio API Square OscillatorNode?

自古美人都是妖i 提交于 2021-02-11 17:26:37

问题


I want to modulate the square waveform of the Web Audio API OscillatorNode by connecting to other OscillatorNodes. But I can not find the parameter in the AudioParams.

Is this possible at all or is there a workaround?

I thought about creating a "custom" wavetable Oscillator with the "audioContext.createWaveTable()" function. This wavetable could contain different pulses with sweeping pulsewidths.

But than again I have no idea how to control the position of the wavetable pointer via AudioParams to modulate the sweep.

Is this possible or do I have a fundamental misunderstanding how this API works?


回答1:


You can't, I'm afraid. We don't have pulse-width modulation in the oscillator yet. You'll have to do it by hand in a script processor node.




回答2:


I found a workaround to the PWM problem here: http://musicdsp.org/archive.php?classid=1#8

"Take an upramping sawtooth and its inverse, a downramping sawtooth. Adding these two waves with a well defined delay between 0 and period (1/f) results in a square wave with a duty cycle ranging from 0 to 100%."

The inverse sawtooth can be done with a GainNode with gain value -1.



来源:https://stackoverflow.com/questions/19178908/how-to-modulate-the-pulsewidth-of-the-web-audio-api-square-oscillatornode

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