8000 GitHub - dmitrysmagin/opl3: Adlib Player with OPL3 emulator in pure JS (no WASM, no Emscripten)
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dmitrysmagin/opl3

Repository files navigation

OPL3 emulator

This is a fork of https://github.com/doomjs/opl3 with some useful changes:

  • Deprecated Worker+ScriptProcessorNode are replaced with newer AudioWorkletNode. This means less load on the cpu and less data moved around between the Worker and main thread.
  • Removed CLI tool because the change above makes the code browser-only
  • Browserify is dropped in favor of Rollup
  • JS syntax updated to ES2015 (import instead of require(), class instead of function)
  • The code is refactored to properly separate parts that run in the main thread and in the AudioWorklet
  • Added RAD format, disabled MUS because of large instruments

The ultimate goal is to add A2M format replayer which is yet to be ported from here

Usage example

Bundled opl3.js should be included into the page as an external script:

    <script type="text/javascript" src="/js/opl3.js" />

Then it could be invoked in the main script:

    var counter = document.querySelector(".counter");
    var info = document.querySelector("#info");
    var player = new OPL3.Player({ prebuffer: 3000, sampleRate: 48000 });

    player.on("currentTime", (value) => {
        counter.innerHTML = `currentFrame: ${value.currentFrame}, currentTime: ${value.currentTime.toFixed(2)} s`;
    })

    function FileToArrayBuffer(file) {
        const fileReader = new FileReader();

        return new Promise((resolve, reject) => {
            fileReader.onerror = () => {
                fileReader.abort();
                reject(new Error('Problem parsing input file'))
            };

            fileReader.onload = () => {
                resolve(fileReader.result);
            };

            fileReader.readAsArrayBuffer(file);
        });
    }

    async function loadFileWorklet(files) {
        if (files instanceof FileList && files.length) {
            var file = files[0];
            var data = await FileToArrayBuffer(file);

            player.play(data);
        }
    }

    function PlayerPause() {
        player.pause();
    }

    function PlayerResume() {
        player.resume();
    }

    function PlayerStop() {
        player.stop();

Full example here

About

Adlib Player with OPL3 emulator in pure JS (no WASM, no Emscripten)

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0