WebAudioLoader
Caching Loader and Decoder for audio files to be used with Web Audio.
Usage:
var WebAudioLoader = ; var audioContext = ; var options = context : audioContext cache : true maxCacheSize : 2000 { console; } var wal = options; wal;
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
-
With npm do:
npm install webaudioloader
-
Use browserify:
var WebAudioLoader = require('webaudioloader')
and
browserify myapp.js > bundle.js
-
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 argumentscallback(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 argumentscallback(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;wal;wal;-
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 theonload
callback returns anAudioBuffer
, else it returns anArrayBuffer
.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 argumentscallback(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