1

F is the carrier, and E and D are modulators.

FM Synthesis with one modulator

Simple FM Synthesis with only one modulator, is pretty straightforward in webaudio.

FM Synthesis with one modulator

var ctx = new AudioContext || webkitAudioContext();
var out = ctx.destination;

// Instantiating
var E = ctx.createOscillator(); // Modulator
var F = ctx.createOscillator(); // Carrier

// Setting frequencies
E.frequency.value = 440;
F.frequency.value = 440;

// Modulation depth
var E_gain = ctx.createGain();
E_gain.gain.value = 3000;

// Wiring everything up
E.connect(E_gain);
E_gain.connect(F.frequency);
F.connect(out);

// Start making sound
E.start();
F.start();

But now I would like to make something like this.

FM Synthesis with two modulators

Two modulators that is. How can this be implemented in webaudio?

Tomasito665
  • 1,188
  • 1
  • 12
  • 24

2 Answers2

1

You can connect two nodes into the same input. Just call the connect() method twice. For example (using your diagram and naming convention):

E.connect(E_gain);
D_gain.connect(E_gain);

Each time E_gain produces an output sample, its input value will be determined by summing one sample from E with one sample from D_gain.

I think whether you want to connect to the frequency parameter or to the detune parameter depends on whether you want to implement Linear FM or Exponential FM. The frequency parameter is measured in Hertz (linear scale) whereas detune is measured in cents (exponential). Though if you do connect to frequency then you'll most probably want to adjust the gain every time the frequency of the carrier changes. E.g. you'd set the gain to 440 * d for some constant modulation depth d when a using a 440Hz carrier, but need to change the gain to 220 * d when you play the note an octave lower. Although keeping the gain constant can generate some interesting dissonant effects too.

0

Response: You need to connect to detune not to frequency.

Example: Hey, I have an example on my site for you: http://gtube.de/

Go to the publish Area in the head and select the FM synth.

There you can see the connections and you can try it live (use the keyboard A-L)! :-)

Exampleobject:

{"name":"connection","Name":"Connection at Pos6","ConnectFrom":"1_#_MOD 1_#_object","ConnectTo":"3_#_GAIN MOD1_#_object"},
{"name":"connection","Name":"Connection at Pos7","ConnectFrom":"3_#_GAIN MOD1_#_object","ConnectTo":"0_#_OSC_#_detune"},
{"name":"connection","Name":"Connection at Pos8","ConnectFrom":"2_#_MOD 2_#_object","ConnectTo":"4_#_GAIN MOD2_#_object"},
{"name":"connection","Name":"Connection at Pos9","ConnectFrom":"4_#_GAIN MOD2_#_object","ConnectTo":"0_#_OSC_#_detune"}
{"name":"connection","Name":"Connection at Pos10","ConnectFrom":"0_#_OSC_#_object","ConnectTo":"5_#_GAIN OSC_#_object"},
{"name":"connection","Name":"Connection at Pos11","ConnectFrom":"5_#_GAIN OSC_#_object","ConnectTo":"context.destination"}]
Kilian Hertel
  • 166
  • 1
  • 14