WebAudio / web-audio-api

The Web Audio API v1.0, developed by the W3C Audio WG
https://webaudio.github.io/web-audio-api/
Other
1.05k stars 166 forks source link

Oscillator's audio parameters can't be controlled by other nodes #2466

Closed Megaemce closed 2 years ago

Megaemce commented 2 years ago

Describe the issue

Connecting any node to oscillatorNode's audio parameters like frequency or detune gives no clear sound result. I would assume that this kind of connection should give me a pulsing oscillator effect however it makes no effect on oscillator output at all.

Consider this code:

const ac = new AudioContext;
const osc1 = new OscillatorNode(ac, {frequency: 220});
const osc2 = new OscillatorNode(ac, {frequency: 400});

osc1.connect(osc2.frequency);
osc2.connect(ac.destination);

osc1.start(0);  // no change to osc2 frequency parameter
osc2.start(0);

image

If this is not a bug can someone explain to me why is it happening like so?

EDIT: I can see in the example 3 that the first oscillator is connected with gain that "determines the amplitude of the modulation signal"

function setupRoutingGraph() {
  const context = new AudioContext();
  // Create the low frequency oscillator that supplies the modulation signal
  const lfo = context.createOscillator();
  lfo.frequency.value = 1.0;
  // Create the high frequency oscillator to be modulated
  const hfo = context.createOscillator();
  hfo.frequency.value = 440.0;
  // Create a gain node whose gain determines the amplitude of the modulation signal
  const modulationGain = context.createGain();
  modulationGain.gain.value = 50;
  // Configure the graph and start the oscillators
  lfo.connect(modulationGain);
  modulationGain.connect(hfo.detune);
  hfo.connect(context.destination);
  hfo.start(0);
  lfo.start(0);
}

but shouldn't the inital output be enough? Why it has to to multiply by 50?