问题
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