Confirmed users
656
edits
(5 intermediate revisions by the same user not shown) | |||
Line 71: | Line 71: | ||
channels = event.mozChannels; | channels = event.mozChannels; | ||
rate = event.mozRate; | rate = event.mozRate; | ||
frameBufferLength = event. | frameBufferLength = event.mozFrameBufferLength; | ||
} | } | ||
Line 109: | Line 109: | ||
var canvas = document.getElementById('fft'), | var canvas = document.getElementById('fft'), | ||
ctx = canvas.getContext('2d'), | ctx = canvas.getContext('2d'), | ||
fft; | fft; | ||
function loadedMetadata(event) { | function loadedMetadata(event) { | ||
channels = event.mozChannels | var channels = event.mozChannels, | ||
rate = event.mozRate, | |||
fft = new FFT( | frameBufferLength = event.mozFrameBufferLength; | ||
fft = new FFT(frameBufferLength / channels, rate), | |||
} | } | ||
Line 126: | Line 125: | ||
for (var i = 0, fbl = fb.length / 2; i < fbl; i++ ) { | for (var i = 0, fbl = fb.length / 2; i < fbl; i++ ) { | ||
// Assuming interlaced stereo channels, need to split and merge into a stero-mix mono signal | // Assuming interlaced stereo channels, | ||
// need to split and merge into a stero-mix mono signal | |||
signal[i] = (fb[2*i] + fb[2*i+1]) / 2; | signal[i] = (fb[2*i] + fb[2*i+1]) / 2; | ||
} | } | ||
Line 136: | Line 136: | ||
for (var i = 0; i < fft.spectrum.length; i++ ) { | for (var i = 0; i < fft.spectrum.length; i++ ) { | ||
magnitude = fft.spectrum[i] * 4000; | // multiply spectrum by a zoom value | ||
magnitude = fft.spectrum[i] * 4000; | |||
// Draw rectangle bars for each frequency bin | // Draw rectangle bars for each frequency bin | ||
Line 380: | Line 381: | ||
readonly attribute unsigned long mozChannels; | readonly attribute unsigned long mozChannels; | ||
readonly attribute unsigned long mozRate; | readonly attribute unsigned long mozRate; | ||
readonly attribute unsigned long mozFrameBufferLength; | |||
}; | }; | ||
</pre> | </pre> | ||
The '''mozChannels''' attribute contains a the number of channels in this audio resource (e.g., 2). The '''mozRate''' attribute contains the number of samples per second that will be played, for example 44100. | The '''mozChannels''' attribute contains a the number of channels in this audio resource (e.g., 2). The '''mozRate''' attribute contains the number of samples per second that will be played, for example 44100. The '''mozFrameBufferLength''' attribute contains the number of samples that will be returned in each '''AudioWritten''' event. This number is a total for all channels (e.g., 2 channels * 2048 samples = 4096 total). | ||
===== nsIDOMNotifyAudioWrittenEvent ===== | ===== nsIDOMNotifyAudioWrittenEvent ===== | ||
Line 458: | Line 460: | ||
=== JavaScript Audio Libraries === | === JavaScript Audio Libraries === | ||
We have started work on a JavaScript library to make building audio web apps easier. Details are [[Audio Data API JS Library|here]]. | * We have started work on a JavaScript library to make building audio web apps easier. Details are [[Audio Data API JS Library|here]]. | ||
* [http://github.com/bfirsh/dynamicaudio.js dynamicaudio.js] - An interface for writing audio with a Flash fall back for older browsers. | |||
=== Working Audio Data Demos === | === Working Audio Data Demos === | ||
Line 470: | Line 473: | ||
* FFT visualization (calculated with js) | * FFT visualization (calculated with js) | ||
** http://weare.buildingsky.net/processing/dsp.js/examples/fft.html | ** http://weare.buildingsky.net/processing/dsp.js/examples/fft.html | ||
* Beat Detection (also showing use of WebGL for 3D visualizations) | |||
** http://cubicvr.org/CubicVR.js/bd3/BeatDetektor1HD-13a.html (video [http://vimeo.com/11345262 here]) | |||
** http://cubicvr.org/CubicVR.js/bd3/BeatDetektor2HD-13a.html (video of older version [http://vimeo.com/11345685 here]) | |||
** http://cubicvr.org/CubicVR.js/bd3/BeatDetektor3HD-13a.html (video [http://www.youtube.com/watch?v=OxoFcyKYwr0&fmt=22 here]) | |||
* Writing Audio from JavaScript, Digital Signal Processing | * Writing Audio from JavaScript, Digital Signal Processing | ||
** Csound shaker instrument ported to JavaScript via Processing.js http://scotland.proximity.on.ca/dxr/tmp/audio/shaker/ | ** Csound shaker instrument ported to JavaScript via Processing.js http://scotland.proximity.on.ca/dxr/tmp/audio/shaker/ | ||
==== Demos Needing to be Updated to New API ==== | ==== Demos Needing to be Updated to New API ==== | ||
Line 485: | Line 492: | ||
** http://ondras.zarovi.cz/demos/audio/ | ** http://ondras.zarovi.cz/demos/audio/ | ||
** http://weare.buildingsky.net/processing/beat_detektor/beat_detektor.html | ** http://weare.buildingsky.net/processing/beat_detektor/beat_detektor.html | ||
** http://code.bocoup.com/processing-js/3d-fft/viz.xhtml | ** http://code.bocoup.com/processing-js/3d-fft/viz.xhtml |