Académique Documents
Professionnel Documents
Culture Documents
13 march 2010
A. Ratchov (AsiaBSDCon)
13 march 2010
1 / 31
Outline
1
Design choices
Kernel vs. user-space implementation
Formats & algorithms to support
Examples
Conclusion
A. Ratchov (AsiaBSDCon)
13 march 2010
2 / 31
Introduction
A. Ratchov (AsiaBSDCon)
13 march 2010
3 / 31
Consequences
Clock source (each sample is a clock tick).
Can be streamed (samples can be buffered).
A. Ratchov (AsiaBSDCon)
13 march 2010
4 / 31
What is MIDI?
Consequences
Not a clock source, but can carry clock ticks.
Usable to control audio (start, stop, volume).
A. Ratchov (AsiaBSDCon)
13 march 2010
5 / 31
audio
application
audio
subsystem
audio
hardware
audio
application
A. Ratchov (AsiaBSDCon)
13 march 2010
6 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
7 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
8 / 31
Example
Headphones (channels 0,1) for telephony.
Speakers (channels 2,3) for music.
Remark : mixing two streams is trivial at this stage.
A. Ratchov (AsiaBSDCon)
13 march 2010
9 / 31
Unix philosophy
Write programs that do one thing and do it well. Write
programs to work together.
Doug McIlroy
To work together, audio programs must:
Be synchronized.
Communicate.
This is the role of audio and MIDI subsystems.
A. Ratchov (AsiaBSDCon)
13 march 2010
10 / 31
Error recovery
Isolation
Correctness
A. Ratchov (AsiaBSDCon)
13 march 2010
11 / 31
Design considerations
A. Ratchov (AsiaBSDCon)
13 march 2010
12 / 31
Responsiveness
Latency in processing events e.g., how long it takes to read a block
from disk.
For any audio subsystem:
The CPU usage is negligible.
Performance is not a concern.
Delays causes the sound to stutter.
Responsiveness is of first importance.
A. Ratchov (AsiaBSDCon)
13 march 2010
13 / 31
What is latency?
The time between a program produces samples and the time they are
played.
Samples are buffered.
Buffers are consumed at fixed rate (sample rate).
The latency is the buffer usage.
No extra latency
Whether buffers are located in kernel or user space doesnt matter for
the latency.
A. Ratchov (AsiaBSDCon)
13 march 2010
14 / 31
Fixing stuttering
Write programs that dont block.
Give enough CPU to programs.
A. Ratchov (AsiaBSDCon)
13 march 2010
15 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
16 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
17 / 31
Overview
Audio server
Very simple.
Mimics kernel APIs (read, write, ...).
No need to handle synchronization and error recovery.
A. Ratchov (AsiaBSDCon)
13 march 2010
18 / 31
13 march 2010
19 / 31
in
decode
resamp.
mix
play
in
socket1
device
socket2
out
demux
out
A. Ratchov (AsiaBSDCon)
encode
record
resamp.
13 march 2010
20 / 31
decode
resamp.
mix
file2
file3
demux
file4
A. Ratchov (AsiaBSDCon)
encode
resamp.
13 march 2010
21 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
22 / 31
A. Ratchov (AsiaBSDCon)
13 march 2010
23 / 31
start signal
A. Ratchov (AsiaBSDCon)
actual start
time
13 march 2010
24 / 31
Why?
Allows MIDI-aware software (or hardware!) to be synchronized to
non-MIDI-aware audio programs.
Typical scenario:
The user manipulates a MIDI sequencer.
The sequencer controls audio streams.
The audio server sends feedback to the sequencer.
The sequencer stays in sync to audio streams.
Simple programs work together to achieve a complex task.
A. Ratchov (AsiaBSDCon)
13 march 2010
25 / 31
Examples
A. Ratchov (AsiaBSDCon)
13 march 2010
26 / 31
audio
recorder
MIDI
thru box
audio
server
audio
hardware
audio
player
clock
(MTC)
volume
start/stop (MMC)
start, stop, relocate... (MMC)
MIDI
keyboard
MIDI
sequencer
MIDI
sythesizer
Without the audio server and the MIDI thru box, the same task would
require a monolithic application.
A. Ratchov (AsiaBSDCon)
13 march 2010
27 / 31
Integration in OpenBSD
Single binary to start the server on the default device:
$ aucat -l
No configuration file, options are on the command line:
E.g., to create spkr and hp subdevices:
$ aucat -l -c 0:1 -s spkr -c 2:3 -s hp
Audio player, recorder and off-line conversion utility:
$ aucat -i file_to_play.wav
Devices can be either hardware (character devices) or software
subdevices (server connections) new naming scheme is required:
<type>:<unit>[.subdevice]
E.g., aucat:0.hp, rmidi:5, midithru:0, . . .
A. Ratchov (AsiaBSDCon)
13 march 2010
28 / 31
audio
player
MIDI
thru box
audio
server
audio
hardware
audio
player
volume
start/stop (MMC)
MIDI
thru box
MIDI
controller
A. Ratchov (AsiaBSDCon)
13 march 2010
29 / 31
audio
player
MIDI
thru box
audio
server
audio
hardware
audio
player
volume
start/stop (MMC)
MIDI
thru box
MIDI
controller
A. Ratchov (AsiaBSDCon)
13 march 2010
29 / 31
audio
player
MIDI
thru box
audio
server
audio
hardware
audio
player
volume
start/stop (MMC)
MIDI
sequencer
MIDI
controller
A. Ratchov (AsiaBSDCon)
13 march 2010
29 / 31
Future work
A. Ratchov (AsiaBSDCon)
13 march 2010
30 / 31
Conclusion
Very simple framework (hopefully!).
User-space implementation.
Single binary, no configuration file.
A. Ratchov (AsiaBSDCon)
13 march 2010
31 / 31