Audio Device Client Better and Faster Audio I/O on Web Hongchan - - PowerPoint PPT Presentation

audio device client
SMART_READER_LITE
LIVE PREVIEW

Audio Device Client Better and Faster Audio I/O on Web Hongchan - - PowerPoint PPT Presentation

Audio Device Client Better and Faster Audio I/O on Web Hongchan Choi Google Chrome Web Audio API Spec Editor (Audio WG) Proposal: Audio Device Client Work-in-progress! (in Audio CG) Proposal: Audio Device Client Low-level audio I/O


slide-1
SLIDE 1

Audio Device Client

Better and Faster Audio I/O on Web

Hongchan Choi

Google Chrome Web Audio API Spec Editor (Audio WG)

slide-2
SLIDE 2

Proposal: Audio Device Client

  • Work-in-progress! (in Audio CG)
slide-3
SLIDE 3

Proposal: Audio Device Client

  • Low-level audio I/O
  • Better access to hardware
  • A dedicated scope runs on RT thread
slide-4
SLIDE 4

"But... why?"

slide-5
SLIDE 5

"To close the App Gap for audio."

slide-6
SLIDE 6

Mac OS Linux Windows Web Platform

Core Audio PulseAudio

  • r Jack

(ALSA) WASAPI

  • r ASIO

?

slide-7
SLIDE 7

"Web Audio API?"

slide-8
SLIDE 8

Issues: Web Audio API (around 2013)

  • Extensibility (W3C TAG review, 1st round)
  • No AudioNode subclassing
  • ScriptProcessorNode unfit for purpose
slide-9
SLIDE 9

Audio Worklet

slide-10
SLIDE 10

Audio Worklet Processor

User code

Audio Worklet Node audio callback processor.js (audio thread) index.js (main thread)

slide-11
SLIDE 11

"How do I port X with it?"

slide-12
SLIDE 12

Case study 1: Audio Worklet + WASM

slide-13
SLIDE 13

Problems: Audio Worklet + WASM

  • Web Audio API render quantum == 128 sample frames

(less than 3ms at 44.1Khz)

  • Not suitable for large-scale audio application
slide-14
SLIDE 14

Case study 2: AW + SAB + WASM Worker

slide-15
SLIDE 15

Worker

SharedArrayBuffer (Audio Data)

Input Buffer

AudioWorklet Processor

Output Buffer

SharedArrayBuffer (States)

Wait/Wake, Buffer indexes

slide-16
SLIDE 16

Problems: AW + SAB + WASM Worker

  • Low thread priority of Worker
  • Overly complex setup for a basic task
slide-17
SLIDE 17
  • Low-level audio I/O
  • Isochronous callback-based audio I/O
  • Suitable for WASM-powered audio processing

Proposal: Audio Device Client

slide-18
SLIDE 18
  • Better access to hardware
  • Configurable render block size, sample rate, and I/O channels
  • Constraints-based hardware configuration

Proposal: Audio Device Client

slide-19
SLIDE 19
  • A dedicated scope runs on RT thread (if permitted)
  • No more complex plumbing and thread hops
  • For optimum WASM-powered audio processing

Proposal: Audio Device Client

slide-20
SLIDE 20
  • Game audio engine
  • Pro-audio applications (music production)
  • Client-side spatialization (AR/VR)
  • Teleconference

Potential Use Cases

slide-21
SLIDE 21

Code Examples

slide-22
SLIDE 22

Setting up device constraints

/* async scope: main global scope */ const devices = await navigator.mediaDevices.enumerateDevices(); // Scenario: device #0 and #2 are audio input and // output devices respectively. const constraints = { inputDeviceId: devices[0].deviceId,

  • utputDeviceId: devices[2].deviceId,

sampleRate: 32000, callbackBufferSize: 512, inputChannelCount: 2,

  • utputChannelCount: 6,

};

slide-23
SLIDE 23

AudioDeviceClient

/* async scope: main global scope */ const client = await navigator.mediaDevices.getAudioDeviceClient(constraints); await client.addModule('my-client.js'); client.start(); // when the application ended client.stop();

slide-24
SLIDE 24

AudioDeviceClientGlobalScope

/* my-client.js: AudioDeviceClientGlobalScope */ import Engine from './my-audio-engine.js'; /** * @params {Array<Float32Array>} input * @params {Array<Float32Array>} output */ const process = (input, output) => { Engine.process(input, output); }; setDeviceCallback(process);

slide-25
SLIDE 25

Design issues: Integration

  • WASM
  • AudioContext
  • WebRTC
slide-26
SLIDE 26

Security/Privacy Concerns

  • Real-time priority thread
  • Mitigation: ADC only can be spawned by "top-level document".
  • Autoplay policy and secure context by default
slide-27
SLIDE 27

github.com/WebAudio/web-audio-cg

(explainer, IDL, code examples, and issue tracker)