Giter VIP home page Giter VIP logo

modplayer.js's Introduction

ModPlayer.js

JavaScript player for the famous Fasttracker II and Protracker module formats.

Plays modules plugin-free with low CPU usage in modern browsers.

Demo

Note: The player is in an early stage of implementation. At the moment there is no API for stopping playback. Also many effects are not implemented, yet.

Requirements

ModPlayer.js uses the HTML5 Web Audio API. See whether your browser is supported at caniuse.com.

Note: The current implementation is known not to play well in Firefox. Please use a Webkit-based browser like Chrome or Safari.

Installation

Download or install with Bower package manager:

bower install junghans-schneider/ModPlayer.js

Add a script tag:

<script src="bower_components/ModPlayer.js/modplayer.min.js"></script>

That's it!

Examples

Playback

mp.module(data).play();

data is an ArrayBuffer in this case. You can also use mp.loadModule() to load a module from your server:

mp.loadModule('mymodule.xm', function (err, module) {
	if (err) {
	    // failed to load module
	} else {
		module.play();
	}
});

Adding another module format

There is a simple plugin mechanism for adding support for other module formats. Just register a parser function which returns null for inadequate input:

mp.format.register(parseMyModule);

function parseMyModule(data) {
  if (! isMyModule()) {
    return null;
  }

  var iter = mp.format.bytesIter(data);
  var parsedData = readMyModule(iter); // magic happens here

  return parsedData;
}

The generic mp.format.parseModule() function calls each registered parser until one of them doesn't return null, i.e. until one of them parsed the data. data is an Int8Array. We suggest to use the built-in bytes iterator for reading the data:

iter.str(17); // read next 17 bytes as string
iter.byte();  // read one byte as integer
iter.word();  //  ... two bytes
iter.dword(); //  ... four bytes

iter.step(2).byte(); // just skip the next 2 bytes, then read a byte
iter.pos();          // get the current position of the iterator

Numbers are read as little endian and by default unsigned. Pass true to read signed:

iter.word(true);

Use iter.list() to get a list of values:

iter.list('byte', 256);

You can also pass a custom read() function, which gets the iterator as first argument. Add additional arguments at the end:

iter.list(readPattern, numPatterns, numChannels);

function readPattern(iter, numChannels) {
	... // do complex read operations here
}

Some of the util functions in util.js may also help you implementing your format parser.

modplayer.js's People

Contributors

jkissel avatar til-schneider avatar

Watchers

James Cloos avatar Christian Graff 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.