TIL

OSC Bundles with Timestamps for Precise Audio Scheduling

OSC (Open Sound Control) bundles allow you to schedule messages with precise timestamps, which is essential for audio applications:

# Regular OSC message - executes immediately
message = {"/dirt/play", [{"s", "bd"}, {"gain", 0.8}]}
encoded = :osc.encode(message)
:gen_udp.send(socket, host, port, encoded)

# OSC bundle with timestamp - executes at specified time
latency = 0.02  # 20ms lookahead
time = :osc.now() + latency
encoded = :osc.pack_ts(time, message)
:gen_udp.send(socket, host, port, encoded)

Bundle format:

"#bundle\0"    (8 bytes - header)
<timestamp>    (8 bytes - NTP time)
<size>         (4 bytes - message size)
<message>      (variable - encoded OSC message)

Useful OSC library functions (from waveform’s osc.erl, based on original code by Joe Armstrong):

Choose latency based on use case: