Giter Site home page Giter Site logo

webaudioloader's Introduction

WebAudioLoader

Caching Loader and Decoder for audio files to be used with Web Audio.

Usage:

var WebAudioLoader = require("webaudioloader");

var audioContext = new AudioContext();

var options = {
	context : audioContext,
	cache : true,
	maxCacheSize : 2000,
	onprogress : function (event){
		console.log('Loading some files...', event.loaded/event.total);
	}
}

var wal = new WebAudioLoader(options);

wal.load('http://www.example.com/audio.mp3', {
		onload : function (err, buffer){
		if(!err){
			console.log('Loaded file of duration', buffer.duration);
		}
	},
});

Why WebAudioLoader

  • Easy API (deals with loading and decoding audio for you) for XHR loading of audio.
  • Uses LRU Cache for caching decoded audio.
  • Uses node style callbacks (err, buffer) to return decoded buffers.
  • Registers a global single instance and returns a reference if one is found.

Note

  • Web Audio only works in a browser (for now), so does this module.

Install

  1. With npm do:

    npm install webaudioloader

  2. Use browserify:

    var WebAudioLoader = require('webaudioloader')

    and

    browserify myapp.js > bundle.js

  3. Standalone (AMD, global object) builds are avilable here.

API

Constructor

eg : var wal = new WebAudioLoader(options);

  • option object can have following optional properties

    • cache : boolean - enable/disable cache globally. Default is true.
    • maxCacheSize : Number - maximum size in kB of cached audio buffers. Default is 1000.
    • onload : Function - global callback when a load operation is complete. The callback has node style return arguments callback(err, buffer).
    • onprogress : Function - global callback when a load operation is in progress. The callback return a progress Event.
    • context : AudioContext - an AudioContext to use for decoding the audio.

Properties

  • onload : Function - global callback when a load operation is complete. The callback has node style return arguments callback(err, buffer).

    eg : wal.onload = function(){};

  • onprogress : Function - global callback when a load operation is in progress. The callback return a progress Event.

    eg : wal.onprogress = function(){};

  • cache : boolean - enable/disable cache globally.

    eg : wal.cache = false;

Methods

  • load : Main API method to load ()and decode) a given AudioFile.

    eg :

     wal.load('http://www.example.com/audio.mp3');
     wal.load([object File]);
     wal.load('http://www.example.com/audio.mp3', options);
    • the source argument can either be a URL String or a File object

    • option object can have following optional properties

      • decode : boolean - toggle if the audio file should be decoded. If decoded the onload callback returns an AudioBuffer, else it returns an ArrayBuffer.
      • cache : boolean - if the audio from this specific load call should be cached. Overrides the global property.
      • onload : Function - callback when this specific load operation is complete. The callback has node style return arguments callback(err, buffer).
      • onprogress : Function - callback when this specific load operation is in progress. The callback return a progress Event.
  • flushCache : Resets the internal cache of the loader.

    eg : wal.flushCache();

License

MIT

webaudioloader's People

Contributors

notthetup avatar

Stargazers

Ben Forest avatar David Taylor avatar Guillermo G C avatar Chee Aun avatar Kevin Ng avatar Lars Berg avatar HongKheng Yap avatar Michael Anthony avatar Pawel Cyrta avatar Pramod Chavan avatar Kevin Chapelier avatar

Watchers

 avatar James Cloos avatar Michael Anthony 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.