Skip to main content

Module fm

Module fm 

Source
Expand description

Two-operator FM voices in the style of the Yamaha OPL2/OPL3 chips, used to play Blood’s MIDI music with its AdLib timbre bank when no CD audio was ripped.

Written from the chips’ publicly documented behaviour, not from any emulator’s code and not cycle-exact: each operator has a phase generator (frequency multiplier, vibrato), an envelope (attack / decay / sustain / release rates in the OPL’s 4-step-per-octave rate scale, key-scale rate), total level and key-scale level attenuation, tremolo and one of eight OPL3 waveforms. The modulator can feed back into itself and either phase-modulates the carrier (FM) or is mixed with it (additive).

Structs§

Operator 🔒
Timbre
One instrument from a 13-byte timbre record: the register values an AdLib driver writes to registers 0x20, 0x40, 0x60, 0x80 and 0xE0 for the modulator and carrier, register 0xC0 (feedback and connection), a transpose and a velocity sensitivity.
Voice
One sounding note: a modulator and a carrier.

Enums§

Stage 🔒

Constants§

ATTACK_RATE1 🔒
Time for a full attack (silence to full level) at rate 1, in seconds.
DECAY_RATE1 🔒
Time for a full decay or release (0 to -96 dB) at rate 1, in seconds.
MULT 🔒
Frequency multipliers for register values 0-15.
SILENT_DB 🔒
Envelope floor: below this the operator is silent.
TREMOLO_DB 🔒
TREMOLO_HZ 🔒
VIBRATO_DEPTH 🔒
Vibrato depth as a frequency ratio (about 7 cents).
VIBRATO_HZ 🔒

Functions§

stage_time 🔒
Seconds a stage of rate rate (0-15) takes, with the key-scale rate offset rof (0-15). Rate 0 never advances; every four effective-rate steps halve the time.
wave 🔒
Waveform w at phase p (cycles, 0..1).