32
realtime audio on ze web APIs, Demos, Anwendungen Jan Krutisch <[email protected] > für #hhjs, 21.Februar 2011 Montag, 21. Februar 2011

realtime audio on ze web @ hhjs

Embed Size (px)

DESCRIPTION

A brief overview of current direct audio APIs in modern browsers and what to build with it.

Citation preview

Page 1: realtime audio on ze web @ hhjs

realtime audio on ze web

APIs, Demos, AnwendungenJan Krutisch <[email protected]>für #hhjs, 21.Februar 2011

Montag, 21. Februar 2011

Page 2: realtime audio on ze web @ hhjs

Moi.

Montag, 21. Februar 2011

Page 3: realtime audio on ze web @ hhjs

Realtime audio?

Montag, 21. Februar 2011

Page 4: realtime audio on ze web @ hhjs

In/Out

Montag, 21. Februar 2011

Page 5: realtime audio on ze web @ hhjs

Status Quo.

Montag, 21. Februar 2011

Page 6: realtime audio on ze web @ hhjs

nada.

Montag, 21. Februar 2011

Page 7: realtime audio on ze web @ hhjs

flash.

Montag, 21. Februar 2011

Page 8: realtime audio on ze web @ hhjs

horizont.

Montag, 21. Februar 2011

Page 9: realtime audio on ze web @ hhjs

Montag, 21. Februar 2011

Page 10: realtime audio on ze web @ hhjs

Audio Data API

Montag, 21. Februar 2011

Page 11: realtime audio on ze web @ hhjs

<audio/>

Montag, 21. Februar 2011

Page 12: realtime audio on ze web @ hhjs

10 beta

Montag, 21. Februar 2011

Page 13: realtime audio on ze web @ hhjs

Montag, 21. Februar 2011

Page 14: realtime audio on ze web @ hhjs

Montag, 21. Februar 2011

Page 15: realtime audio on ze web @ hhjs

Montag, 21. Februar 2011

Page 16: realtime audio on ze web @ hhjs

Web Audio API

Montag, 21. Februar 2011

Page 17: realtime audio on ze web @ hhjs

AudioContext

Montag, 21. Februar 2011

Page 18: realtime audio on ze web @ hhjs

Das wars.

Montag, 21. Februar 2011

Page 19: realtime audio on ze web @ hhjs

Ja, sorry, ey.

Montag, 21. Februar 2011

Page 20: realtime audio on ze web @ hhjs

Code, or it didn‘t happen

Montag, 21. Februar 2011

Page 21: realtime audio on ze web @ hhjs

<!DOCTYPE html><html> <head> <title>JavaScript Audio Write Example</title> </head> <body> <input type="text" size="4" id="freq" value="440"><label for="hz">Hz</label> <button onclick="start()">play</button> <button onclick="stop()">stop</button>

<script type="text/javascript"> function AudioDataDestination(sampleRate, readFn) { // Initialize the audio output. var audio = new Audio(); audio.mozSetup(1, sampleRate);

var currentWritePosition = 0; var prebufferSize = sampleRate / 2; // buffer 500ms var tail = null;

// The function called with regular interval to populate // the audio output buffer. setInterval(function() { var written; // Check if some data was not written in previous attempts. if(tail) { written = audio.mozWriteAudio(tail); currentWritePosition += written; if(written < tail.length) { // Not all the data was written, saving the tail... tail = tail.slice(written); return; // ... and exit the function. } tail = null; }

// Check if we need add some data to the audio output. var currentPosition = audio.mozCurrentSampleOffset(); var available = currentPosition + prebufferSize - currentWritePosition; if(available > 0) { // Request some sound data from the callback function. var soundData = new Float32Array(available); readFn(soundData);

// Writting the data. written = audio.mozWriteAudio(soundData); if(written < soundData.length) { // Not all the data was written, saving the tail. tail = soundData.slice(written); } currentWritePosition += written; } }, 100); }

// Control and generate the sound.

var frequency = 0, currentSoundSample; var sampleRate = 44100;

function requestSoundData(soundData) { if (!frequency) { return; // no sound selected }

var k = 2* Math.PI * frequency / sampleRate; for (var i=0, size=soundData.length; i<size; i++) { soundData[i] = Math.sin(k * currentSoundSample++); } }

var audioDestination = new AudioDataDestination(sampleRate, requestSoundData);

function start() { currentSoundSample = 0; frequency = parseFloat(document.getElementById("freq").value); }

function stop() { frequency = 0; } </script>

Montag, 21. Februar 2011

Page 22: realtime audio on ze web @ hhjs

[...]

var audio = new Audio(); audio.mozSetup(1, sampleRate);

[...]

written = audio.mozWriteAudio(tail);

[...]

Montag, 21. Februar 2011

Page 23: realtime audio on ze web @ hhjs

https://wiki.mozilla.org/Audio_Data_API#Writing_Audio

Montag, 21. Februar 2011

Page 24: realtime audio on ze web @ hhjs

context = new webkitAudioContext();

var jsNode = context.createJavaScriptNode(8192, 0, 2);

jsNode.connect(context.destination);

jsNode.onaudioprocess = requestSoundData;

Montag, 21. Februar 2011

Page 25: realtime audio on ze web @ hhjs

Anwendungen

Montag, 21. Februar 2011

Page 26: realtime audio on ze web @ hhjs

Musik

Montag, 21. Februar 2011

Page 27: realtime audio on ze web @ hhjs

Spiele

Montag, 21. Februar 2011

Page 28: realtime audio on ze web @ hhjs

(Build and they will come)

Montag, 21. Februar 2011

Page 29: realtime audio on ze web @ hhjs

Meine kleine Ecke

Montag, 21. Februar 2011

Page 30: realtime audio on ze web @ hhjs

http://webloop.pixelpoke.de

Montag, 21. Februar 2011

Page 31: realtime audio on ze web @ hhjs

http://github.com/halfbyte/soundbridge.js

Montag, 21. Februar 2011

Page 32: realtime audio on ze web @ hhjs

soundbridge = SoundBridge(2, 44100, '..');

[...] soundbridge.setCallback(calc); soundbridge.play();}, 1000);

Montag, 21. Februar 2011