admin管理员组

文章数量:1291611

Using the Web Audio API, I have an oscillator node with a frequency of 1000. I want to change this frequency value, but not directly. I want to use a multiplier instead.

So, given 1.5, the frequency would be made 1500. Given 0.5, it would become 500.

I thought I could achieve this by connecting a gain node to the frequency parameter, like so (where context is the audio context):

const oscNode = context.createOscillator();
oscNode.frequency.setValueAtTime(1000, context.currentTime);
const gainNode = context.createGain();
gainNode.connect(oscNode.frequency);
gainNode.gain.setValueAtTime(1.5, context.currentTime);

The following is not viable:

let multiplier = 1.5;
oscNode.frequency.setValueAtTime(1000 * multiplier, context.currentTime);

That’s because it must be possible to modulate the multiplier, say, with another oscillator acting as an LFO.

Perhaps gain is not a generic signal multiplier as I thought and can only work as expected while augmenting other gains. If so, are there other ways to multiply arbitrary parameter values? Are there general ways to provide computed values to audio parameters in place of simple integers?

Note: I do not get an error and playback works as expected when connecting the gain node to the frequency param. It just does not appear to do anything.

本文标签: Web audio gain node as a generic multiplierStack Overflow