Giter Site home page Giter Site logo

zeozeozeo / jslibxm Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 133 KB

A JavaScript .XM file (FastTracker II Extended Module) player using libxm with emscripten.

Home Page: https://zeozeozeo.github.io/jslibxm/examples/minimal/

License: The Unlicense

Makefile 5.52% JavaScript 94.48%
emscripten fasttracker javascript libxm player web xm fasttracker2

jslibxm's Introduction

jslibxm - simple JavaScript API for libxm

jslibxm is a JavaScript .XM file (FastTracker II Extended Module) player using libxm with emscripten.

  • Very small: ~69,9 kB in size for the minified version
  • Easy to use API (see examples)
  • Fast

Usage

To use this in your project,

  1. Add the script to your HTML file:
<script src="https://cdn.jsdelivr.net/gh/zeozeozeo/jslibxm@master/dist/jslibxm.min.js"></script>
  1. In your JavaScript, add a function that will be called once the module loads:
libxm.onload = function () {
    // create a new XM module
    var xm = new XMModule(); // sample rate is 48000 by default

    // load a module, you can use a URL string, File or an Int8Array
    var url =
        "https://api.modarchive.org/downloads.php?moduleid=41760#elw-sick.xm";
    xm.load(url, function (err) {
        if (err) {
            // this condition will run
            // if there was an an error
            console.error(err);
            return;
        }
        // module is loaded, start playing the song
        xm.resume();
    });
};

WARNING: In most browsers, the AudioContext will only start playing audio when the user interacts when the page (e.g. clicks a button).

For more examples, look inside the examples folder.

Documentation

function XMModule(sampleRate = 48000, onfillbuffer, onxmdataupdate)

Main constructor. Returns itself.
 * sampleRate - how much samples to generate and play per second
 * onfillbuffer - will be called each time when filling new audio buffer
 * onxmdataupdate - will be called each time when XMModule.xmdata updates

XMModule.load(input, callback)

Loads an XM module into the context.
 * {(File|string|Int8Array)} input - loads the module from file, URL or Int8Array.

 * {Function} callback<err> - callback function after module load.

 * Callback has 1 parameter (error) - false if loaded successfully, string if not.

Example:

xm.load(input, function (err) {
    if (err) {
        // this condition will run
        // if there was an an error
        console.error(err);
        return;
    }
    // module is loaded
});

XMModule.xmdata

XMModule.xmdata is an array containing all of the events that happening while filling the previous audio buffer.

...unfinished, look into the source code

Building

To build libxm with emscripten,

  1. Clone the repository with submodules git clone --recurse-submodules [email protected]:zeozeozeo/jslibxm.git
  2. Download and install emscripten and add it to PATH
  3. cd into the directory and run make. For more information on building libxm, see this
  4. If everything went successfully, the lib folder will have libxm.js, which is code generated by emscripten
  5. If you also have uglifyjs installed, you can minify the source code for distribution by running uglifyjs lib/libxm.js src/jslibxm.js -o dist/jslibxm.min.js. The dist folder will contain the minified code for libxm.js and jslibxm.js in one file, jslibxm.min.js.

jslibxm's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.