Coder Social home page Coder Social logo

opljs's Introduction

opl.js

Javascript wrapper: Copyright 2018 Adam Nielsen <[email protected]>
OPL emulator: Copyright 2002-2015 The DOSBox Team

This is a Javascript wrapper around the OPL3 emulator included in DOSBox. It allows OPL-compatible FM synthesis from within Javascript code, running in Node or in the browser.

The emulator is written in C++ and compiled to Javascript WebAssembly with Emscripten. A small wrapper is provided to simplify the interface between the C++ code and the Javascript code.

Example code is provided, both for the Node environment (with require()) and for the browser (using <script/>).

Installation

npm install @malvineous/opl

Use

const OPL = require('@malvineous/opl');

OPL.create().then(opl => {
    opl.write(0xBD, 0x20);
    const samples = opl.generate(512);
    // samples now contains 512 16-bit stereo samples as a Uint8Array
});

Examples

In the examples/ folder there are some short demonstrations showing how to interface with the OPL emulator.

The web example may not work if loading the HTML file directly, as some browsers do not like loading WebAssembly files from file:// URLs. To run this example, you can either upload it somewhere or use Node to run serve-demo-web.js which will use ExpressJS to host the necessary files. You may need to run npm install --dev to get ExpressJS installed first.

Limitations

The library is only focused on generating the audio. It does not feature any sort of playback or audio mixing mechanism, as this is likely to be very different for different projects. You will need to include another library in your project if you wish to play the generated audio. The web example shows how to use WebAudio for playback in the browser, and the Node example shows how to save the generated audio to a .wav file instead.

8-bit and floating point audio formats are not supported. You can still use these formats, but you'll need to convert the signed 16-bit samples into these formats yourself. The WebAudio sample code shows conversion to floating point.

Contributing

When you install the release with npm the WebAssembly binary is included. This is not part of the git repository, so if you clone the repo you will need to install emscripten in order to compile the C++ code into Javascript.

Once emscripten is installed, run:

npm run build

This will compile the C++ code in src/ and put the compiled files into lib/.

opljs's People

Contributors

malvineous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

eparadis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.