Audio Data API Review Version: Difference between revisions

Jump to navigation Jump to search
Line 291: Line 291:
<audio id="a1"  
<audio id="a1"  
       src="song.ogg"  
       src="song.ogg"  
       onloadedmetadata="loadedMetadata(event);"
       onloadedmetadata="loadedMetadata();"
       onaudiowritten="audioWritten(event);"
       onaudiowritten="audioWritten(event);"
       controls="controls">
       controls="controls">
Line 300: Line 300:
     buffer = [];
     buffer = [];


function loadedMetadata(event) {
function loadedMetadata() {
   // Mute a1 audio.
   // Mute a1 audio.
   a1.volume = 0;
   a1.volume = 0;
   // Setup a2 to be identical to a1, and play through there.
   // Setup a2 to be identical to a1, and play through there.
   a2.mozSetup(event.mozChannels, event.mozSampleRate, 1);
   a2.mozSetup(a1.mozChannels, a1.mozSampleRate, 1);
}
}


Line 329: Line 329:
</pre>
</pre>


Audio data written using the '''mozWriteAudio()''' method needs to be written at a regular interval in equal portions, in order to keep a little ahead of the current sample offset (current sample offset of hardware can be obtained with '''mozCurrentSampleOffset()'''), where a little means something on the order of 500ms of samples.  For example, if working with 2 channels at 44100 samples per second, and a writing interval chosen that is equal to 100ms, and a pre-buffer equal to 500ms, one would write an array of (2 * 44100 / 10) = 8820 samples, and a total of (currentSampleOffset + 2 * 44100 / 2).
Audio data written using the '''mozWriteAudio()''' method needs to be written at a regular interval in equal portions, in order to keep a little ahead of the current sample offset (current sample offset of hardware can be obtained with '''mozCurrentSampleOffset()'''), where a little means something on the order of 500ms of samples.  For example, if working with 2 channels at 44100 samples per second, a writing interval of 100ms, and a pre-buffer equal to 500ms, one would write an array of (2 * 44100 / 10) = 8820 samples, and a total of (currentSampleOffset + 2 * 44100 / 2).


===== Complete Example: Creating a Web Based Tone Generator =====
===== Complete Example: Creating a Web Based Tone Generator =====
Confirmed users
656

edits

Navigation menu