HTML and CSS Reference
In-Depth Information
controls>
</audio>
<pre id="raw">hello</pre>
<script>
function audioAvailable(event) {
var frameBuffer = event.frameBuffer;
var t = event.time;
var text = "Samples at: " + t + "\n"
text += frameBuffer[0] + " " + frameBuffer[1]
raw.innerHTML = text;
}
var raw = document.getElementById('raw')
var audio = document.getElementById('audio-element');
audio.addEventListener('MozAudioAvailable', audioAvailable,
false);
</script>
</body>
</html>
It's important to understand that audio can be represented textually, because the Audio Data
API can be used to actually generate sound, as well as play sound. Another example that Moz-
illa provides, shown in Example 4-8 , produces a tone—though in fact, a rather annoying tone.
Example4-8.Generating a tone using the Audio Data API
<!doctype html>
<html>
<head>
<title>Generating audio in real time</title>
<script type="text/javascript">
function playTone() {
var output = new Audio();
output.mozSetup(1, 44100);
var samples = new Float32Array(22050);
var len = samples.length;
for (var i = 0; i < samples.length ; i++) {
samples[i] = Math.sin( i / 20 );
}
output.mozWriteAudio(samples);
}
</script>
</head>
<body>
Search WWH ::




Custom Search