OPL3 emulator usable as a CLI tool or as a library.
Ported from Yamaha YMF262 (OPL3) Emulator by Robson Cozendey.
Using from command line
Install OPL3 emulator as
npm install -g opl3.
OPL3 emulator v0.4.2 Usage: opl3 <input file> [OPTIONS] Options: --mp3 Export to MP3/Lame --wav Export to WAV --ogg Export to OGG/Vorbis --opus Export to OGG/Opus --mid Export to MIDI --laa Use LAA format --mus Use MUS format --dro Use DRO format --imf Use IMF format --raw Use RAW format -h, --help You read that just now -i, --genmidi Use external GENMIDI lump (only MUS format) -n, --normalize PCM audio normalization (default on, turn off with -n0) -p, --play Play after processing -o, --output Output directory Examples: opl3 D_E1M1.mus Copyright (c) 2016 IDDQD@doom.js
Accepts glob patterns as input file, like
Use OPL3 and a format handler (like LAA) to process:
var fs = ;var OPL3 = OPL3;var LAA = formatLAA;var Player = Player;var WAV = WAV;var player = LAA;player;player;
To convert source (in LAA format) to raw PCM audio, you can use the
Readable stream approach:
var fs = ;var OPL3 = OPL3;var LAA = formatLAA;var Player = Player;var player = LAA;var file = fs;player;player;player;
Convert source DRO to MP3 using node-lame:
var fs = ;var lame = ;var OPL3 = OPL3;var LAA = formatLAA;var Player = Player;var player = LAA;var file = fs;var encoder =// inputchannels: 2 // 2 channels (left and right)bitDepth: 16 // 16-bit samplessampleRate: 49700 // 49,700 Hz sample rate;player;encoder;player;player;
Using in a browser
OPL3 is also available as a Bower package, install with
bower install opl3.
If installed from Bower, include OPL3 client library as:
OPL3 client library is supporting UMD. When included as a global script, the library is available as
WebWorker support is available in the browser, the library will automatically use a
Worker to process audio in the background. You can find a browser example here.
The OPL3 client library has a built-in realtime playback feature using Web Audio API, see here. See an example here for realtime playback using pico.js.
Player is a Readable stream, with extra events.
new Player(format[, options])
format<FormatHandler> Any format handler included in
opl3module or a custom format handler.
options<Object$gt; Optional options object.
options properties are:
trueto enable normalization (not available in realtime), default is
- bitDepth: set bit depth of output PCM audio (
32), default is
- bufferSize: size of audio chunk buffer for a single channel, default is
64for realtime playback.
- sampleRate: set sample rate of output PCM audio, default is
- instruments: only supported in MUS format handler, override default GENMIDI instruments. This can be a raw lump file extracted from a WAD file or a JSON exported with WAD Commander.
- prebuffer: prebuffer size in milliseconds for realtime audio playback, default is
200. Set this value to
-1if you want to disable any prebuffering.
- volume: realtime audio playback starting volume, default is
- disableWorker: force processing on main thread.
buffer<Buffer> | <ArrayBuffer> Source buffer
callback<Function> Optional callback when the audio processing is finished (including normalization if enabled). The result PCM audio buffer is passed to the callback function as an
Load source buffer for audio processing and start processing immediately. Result PCM audio buffer is 2-channel (stereo) 16-bit with 49700Hz sample rate.
buffer<Buffer> | <ArrayBuffer> Source buffer
Start or continue playing source buffer in realtime. Only available if AudioContext is supported.
Pause realtime audio playback.
Seek realtime audio playback to position in milliseconds.
Get position of realtime audio playback in milliseconds.
Get length of realtime audio in milliseconds. Starts at zero and growing to full length while processing source buffer in background
Get or set audio volume, from
'progress' event is emitted on audio processing and returns the current position of the audio processing in percentage (from 0 to 100).
'midi' event is emitted only if the format handler supports MIDI conversion. Emitted only once after audio is fully processed. Returns MIDI file buffer as an
'normalization' event is emitted on audio normalization (if enabled) and returns the current current position of the normalization in percentage (from 0 to 100).
'gain' event is emitted after normalization and returns the scale of normalization.
Emitted on realtime audio playback, returns audio playback position in milliseconds (same as
ConvertTo32Bit is a
Transform stream class, use this to convert 16-bit PCM audio data to 32-bit.
Normalizer is a
Transform stream class, use this to normalize PCM audio data. Used internally in
See more details here. Use this function to generate WAV audio format buffer from PCM audio data.
Supported format types
- LAA: LucasArts music
- MUS: Doom music
- DRO: DosBox RAW OPL
- IMF: Id Music Format
- RAW: Rdos Raw OPL Capture
MUS format GENMIDI instruments support
The OPL3 library includes GENMIDI lump from shareware Doom as the default instrument set. You can override this in the CLI tool and in the
Player class as well.
opl3 doom2/*.mus --genmidi DOOM2.OP2 to inject the
DOOM2.OP2 GENMIDI lump file into the MUS format handler.
OPL3formatMUSinstruments: genmidi // ArrayBuffer or JSON;
Supported audio export formats
- WAV: PCM audio WAVE
- MP3/Lame: using node-lame
- OGG/Vorbis: using node-vorbis and node-ogg
- OGG/Opus: using node-opus and node-ogg
- MIDI: currently only supported by MUS file format handler
- Audio playback: using node-speaker in node.js and Web Audio API in browser.
MP3, OGG and audio playback support are based on optional dependencies. If a dependency install has failed, the export format won't be available.
PCM audio normalization
By default the command line utility uses peak normalization on the PCM audio result buffer. To turn off this feature, please use
To enable normalization in the Player class, instantiate the player like:
var player = LAA normalization: true ;
Special thanks to
- Robson Cozendey, for creating
That Vintage ToneOPL3 emulator
- Paul Radek, for creating the
- Vladimir Arnost, for creating
- Nathan Rajlich, for creating the