CH·59 Procedural & synthesis
verified 2026-08-01

opal-zig active

RealBitdancer vunknown added 2026-08-01 verified 2026-08-01

[Use when]

You need to emulate OPL3/OPL2 FM synthesis (Yamaha YMF262) in a Zig project without runtime dependencies beyond libc.

Engines
S Standalone * Engine-agnostic
License

MIT

Pricing

Free

Last verified

2026-08-01

Added

2026-08-01

about

opal-zig is a Zig binding for the opal OPL3/OPL2 FM synthesis emulator. It compiles the upstream C11 core via the Zig build system and exposes it as a native Zig module with no code generation step and no dependencies beyond libc. Requires Zig 0.16.0 or newer.

The public API wraps the eight C functions as methods on a plain `Opal` struct. Because the struct contains no internal pointers, copying an instance produces a complete save state, which is useful for rewinding or snapshotting synthesis state. Internal fields such as envelope stage, envelope generator output, and key state are exposed directly through mirrored `extern struct` types, making it straightforward to build visualizers on top of the emulator.

A layout verification test suite checks every field offset and struct size against the C compiler at build time, so Zig-side mirrors cannot silently drift from the C layout. A convenience `render` method fills buffers of interleaved stereo i16 frames. A demo target renders a short FM arpeggio to a WAV file.