MegaDriveSynth Embedded Demo
This example shows the higher-level browser API intended for embedding Mega Drive / Genesis audio into a browser app or game.
MegaDriveSynth hides the AudioContext, AudioWorkletNode,
WASM loading, and worklet initialization details.
Minimal Usage
import {
MegaDriveSynth,
} from "../js/megasynth.js";
const megaDrive =
new MegaDriveSynth({
workletUrl: "../js/ym2612-worklet.js",
ym2612WasmUrl: "../generated/ym2612_wasm.wasm",
segaPsgWasmUrl: "../generated/segapsg_wasm.wasm",
});
await megaDrive.start();
const synth = megaDrive.fm;
synth.setOperator(0, 0, { tl: 0x7f });
synth.setOperator(0, 1, { tl: 0x7f });
synth.setOperator(0, 2, { tl: 0x7f });
synth.setOperator(0, 3, {
dt: 0,
multi: 1,
tl: 8,
ar: 22,
d1r: 6,
d2r: 3,
sl: 3,
rr: 8,
});
synth.setAlgo(0, 7, 0);
synth.setPan(0, true, true);
synth.noteOn(0, 4, 553);
setTimeout(() => {
synth.noteOff(0);
}, 1000);
// PSG is optional. With segaPsgWasmUrl enabled:
megaDrive.psg.tone(0, { note: "C4", volume: 0.4 });
setTimeout(() => megaDrive.psg.off(0), 1000);
Ready.
What MegaDriveSynth Hides
Application / Game
|
v
MegaDriveSynth
|
+-- AudioContext
+-- AudioWorklet
+-- AudioWorkletNode
+-- WASM loading
+-- Worklet initialization
|
v
YM2612Synth
|
v
YM2612WorkletTransport
|
v
YM2612 / ymfm WASM
|
v
Audio output
Low-Level Alternative
If you want to understand or control the AudioWorklet setup directly, see the YM2612Synth AudioWorklet Demo .