Timbre.js

JavaScript Library for Objective Sound Programming
system requirements: Chrome 14- or Firefox 4-

Audio

Load an audio file and store it to the buffer.

Constructor

audio = T("audio", src="public/audio/sample.ogg,mp3", loop=true).load();

// src  [String]  The url of an audio file to load
// loop [Boolean] Looping
        

Properties

audio.src         // [String]   The url of an audio file to load
audio.loop        // [Boolean]  Looping

audio.currentTime // [Number]   Current position in msec of the buffer
audio.reversed    // [Boolean]  Play backwards

audio.isLoaded    // [Readonly] 'true' when loaded audio and stored
audio.duration    // [Readonly] The duration of the buffer
        

Methods

// Async load an audio file and store it to the buffer
audio.load();


// Return new T("audio") instance which refers to the same buffer
audio.clone();


// Return new T("audio") instance which has the extracted buffer
audio.slice(begin=0, end=1000);
        

Events

// Script to be run when the audio has reach the end
audio.onended = function() {};


// Script to be run when the audio has reach the end and loop
audio.onlooped = function() {};


// Scripts to be run when the meta data is loaded
audio.onloadedmetadata = function(res) {};


// Scripts to be run when an audio data is loaded
// In Firefox, will be kept waiting..
audio.onloadeddata = function(res) {};


// Scripts to be run when an error occurs when the file is being loaded
audio.onerror = function() {};
        

Example: Reversed audio

audio.clone().set("reversed", true).play();
        

Example: Beat from slice audio

audio.slice(280, 280+214).play();
        

See Also:

T("wav")