Skip to content

Comment on Frequency Modulation (FM) with Web Audio APIparent

Comments

grenOP

I have no music background, so thanks a lot, your feedback is really helpful :)

When you say modulating a phase offset instead of frequency, does this mean you have like 2 oscillators A and B set to the same frequency, where you modulate the offset of A, and you connect both A and B to the audio output?

About your second note, you are so right! Actually it was a mistake in my article, this is what I've done actually but my explanation was a bit wrong. My first demo is a multiple of the frequency. My second demo is a multiple of (carrier frequency/4). Nothing related to octave, I shouldn't have mentioned that (I will fix it ASAP).

Hey, no problem. FM synthesis is one of my greater interests! With modulating the phase offset I mean that instead of doing

    carrier = sin((f + modulator) * pi)
(a typical way of modulating the frequency) you can do
    carrier = sin(f * pi + modulator)
The modulator could be scaled by something from 0 to 2 pi but experiment with what sounds best.

The reason for doing this to begin with is probably that simply adding an offset in a sin table readout is probably a more effective design than adding the offset to the phase accumulator, especially if you want a consistent timbre without scaling the modulator amplitude along with the carrier frequency, and don't want to deal with negative frequencies.

Another nice thing you get for free with phase modulation is that you can do stable feedback modulation. In essence, you use the last calculated sample value for an operator (envelope * oscillator) as a modulation source in itself. In code, something like

    float generate_sample() {
        sample = envelope * sin(f * pi + old_sample * feedback_level);
        old_sample = sample;
    }
It's very effective for brass sounds or harsher sounds like trying to model distorted guitars
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.