+ All Categories
Home > Technology > Web & sound

Web & sound

Date post: 08-Jan-2017
Category:
Upload: takashi-toyoshima
View: 828 times
Download: 0 times
Share this document with a friend
19
Web & Sound Playing with Sound APIs recently introduced to the Web
Transcript
Page 1: Web & sound

Web & SoundPlaying with Sound APIs recently introduced to the Web

Page 2: Web & sound

Overview + Demo

Page 3: Web & sound

New Sound APIs

◇ Web Audio (http://webaudio.github.io/web-audio-api/)

■ Real-time audio synthesis○ cf. SuperCollider, Pure Data, Max/MSP

■ SFX (Pan, Delay, Filter, etc)◇ Web MIDI (http://webaudio.github.io/web-midi-api/)

■ Real-time communication○ Web ⇄ Musical Instruments

● Synths, DJ and lighting controllers◇ WebRTC (http://w3c.github.io/webrtc-pc/)

■ Camera & Microphone

Page 4: Web & sound

Web Audio Demo

◇ Web Audio Playground (http://webaudioplayground.appspot.com/)

■ Straight-forward GUI wrapper◇ WebPd (https://github.com/sebpiq/WebPd)

■ Pure Data clone◇ CoffeeCollider (https://github.com/mohayonao/CoffeeCollider)

■ Coffee Script + SuperCollider◇ T’SS JS edition (https://github.com/toyoshim/tss)

■ Chiptune sound emulation (demo, tsdsp)

Page 5: Web & sound

MIDI is old, and new◇ 30th anniversary◇ MIDI is not only SMF but a protocol

■ SMF: Standard MIDI File○ Protocol dump file with timestamps

■ Real-time communication - lighting and more○ 冨田勲×初音ミク「イーハトーヴ」@ YouTube

◇ De facto for music production tools■ Software Synth in DAW: Audio Unit, VSTi, DXi■ Hardware: DIN, USB, FireWire, RTP, Bluetooth(*)

○ (*): supported by Yosemite, Windows 10, Android M

Page 6: Web & sound

Web MIDI Demo

◇ Physical controller for online sound systems■ Web Audio Synth v2 (http://aikelab.net/websynthv2/)

■ Web FM Synthesizer (http://www.taktech.org/takm/WebFMSynth/)

■ Online DAW: audiotool (http://www.audiotool.com/)

■ Online VJ: MajVj (GGT 2014 demo)

◇ Demo and Productions by YAMAHA■ Pocket Miku (Product page & Web App)

■ Web Music Platform (toyoshim’s fork)

■ Reface + Soundmondo (Product page)○ Social to share your sound and music via Web MIDI

Page 7: Web & sound

WebRTC

◇ microphone■ getUserMedia({audio:true}, …)

○ Can connect to Web Audio via createMediaStreamSource()

◇ camera■ getUserMedia({video: true}... )

○ Can use it as a texture for WebGL

Page 8: Web & sound

Web Apps be Secure!

◇ Hardware is hard to use securely■ What happens on WebGL?

○ Need GPU process and GPU command validator■ Recent APIs to use hardware

○ Permission prompt (infobar/bubble UI)○ Secure origin, e.g. https or localhost, is mandatory

■ Real P0 issue happened on Web MIDI○ Microsoft GS Wavetable SW Synth crashes

● on receiving a special valid sequence● outside Chrome sandbox, inside the driver

Page 10: Web & sound

Lesson: Web Audio 1

◇ Simple sine wave

var audio = new AudioContext();

var osc = audio.createOscillator();

osc.frequency.value = 440; // in Hz

osc.connect(audio.destination);

osc.start(0);

Page 11: Web & sound

Lesson: Web Audio 2◇ Other nodes

■ Audio source○ AudioBufferSourceNode (from Audio resources, e.g., mp3, m4a)○ MediaElementAudioSourceNode (from DOM media object)○ MediaStreamSource (from microphone via getUserMedia)○ ScriptProcessorNode (deprecated) => AudioWorkerNodeProcessor (from JS)○ OscillatorNode (from various kinds of oscillators)

■ Effect○ GainNode○ DelayNode○ (Stereo)PannerNode / AudioListener○ ConvolverNode (e.g., Vocoder, Reverb, and so on)○ DynamicsCompressorNode / WaveShaperNode○ BuquadFilterNode (e.g., LPF, HPF, BPF, and so on)

■ Misc○ AnalyserNode (FFT)○ ChannelSplitterNode / ChannelMergerNode (Mixer)

Page 12: Web & sound

Lesson: Web MIDI 1

◇ Device Query

var promise = navigator.requestMIDIAccess();

promise.then(function(midi) {

for (var input of midi.inputs.values())

console.log(input); // MIDIInput

for (var output of midi.outputs.values())

console.log(output); // MIDIOutput

});

Page 13: Web & sound

Lesson: Web MIDI 2

◇ MIDIInput

for (var input of midi.inputs.values())

input.onmidimessage = handler;

function handler (e) {

// Single MIDI message in Array.

console.log(e.data);

}

Page 14: Web & sound

Lesson: Web MIDI 3

◇ MIDIOutput

for (var output of midi.outputs.values()) {

// Send single MIDI message or multiple

// MIDI messages.

output.send([0x90, 0x40, 0x7f]); // Note ON

}

Page 15: Web & sound

Lesson: Promise◇ New replacement for callbacks

foo(successCallback, errorCallback);↓

foo().then(successCallback, errorCallback);

foo().then(bar)

.then(baz)

.catch(qux);

◇ Chaining

Promise.all([foo(),

bar()])

.then(baz, qux);

◇ Wait multiple async functions

Page 16: Web & sound

Lesson: Maplike◇ readonly maplike<DOMString, MIDIInput> inputs◇ readonly maplike<DOMString, MIDIOutput> outputs

◇ keys() … MIDIPort.id is used as an unique key◇ values() … MIDIInput / MIDIOutput

for (var input of inputs.values()) { // New syntax for ES6 iterable}

Page 17: Web & sound

Lesson: Web MIDI 4

◇ Hotplug

midi.onstatechange = function (e) {

var newport = e.port;

if (newport.state == “connected”)

console.log(newport.name + “ is attached”;

else if (newport.state == “disconnected”)

console.log(newport.name + “ is detached”;

};

Page 18: Web & sound

Fine ||

Page 19: Web & sound

References

◇ Slide template■ from Slides Carnival

○ http://www.slidescarnival.com/imogen-free-presentation-template/399


Recommended