Changes

Jump to: navigation, search

Audio Data API

30 bytes added, 13:33, 2 June 2010
Reading Audio
Audio data is made available via an event-based API. As the audio is played, and therefore decoded, each frame is passed to content scripts for processing after being written to the audio layer--hence the name, '''AudioWritten'''. Playing and pausing the audio all affect the streaming of this raw audio data as well.
Consumers Users of this raw audio data API can register two callbacks on the <audio> or <video> element like in order to consume this data:
<pre>
</pre>
The '''LoadedMetadata''' event is a standard part of HTML5, and has been extended to provide more detailed information about the audio stream. Specifically, developers can obtain the '''number of channels''', '''sample rate per second''', and '''default size of the framebuffer ''' that will be used in audiowritten events. This event is fired once as the media resource is first loaded, and is useful for interpreting or writing the audio data.
The '''AudioWritten''' event provides two pieces of data. The first is a framebuffer (i.e., an array) containing sample data (i.e., floats) for the current frame. The second is the time (e.g., milliseconds) for these samples measured from the start of this framein milliseconds.
The following is an example of how both events might be used:
var time = event.mozTime;
for (var i=0, slen=samples.length; i<slenframeBufferLength; i++) {
// Do something with the audio data as it is played.
processSample(samples[i], channels, rate);
Confirm
656
edits

Navigation menu