sound.run

sound

run(dev, mx, opts) -> task/fn

Run the audio writer task on the LEV event loop

Spawns a task into the running lev.run. The task waits until the device takes a period, fills one from the mixer, and writes it. With no voices playing it writes silence, so the stream never runs dry. A device with a wait method, the pulse one, is waited on through it; any other is waited on writable through dev:fd().

opts fielddefaultdescription
timeout0.1seconds between checks of cancel
cancelnila lev.cancel_token; the task ends when it fires
name"sound_writer"task name
spawntruefalse returns the task body as a function, for the caller to run
statsnila table the task counts in: periods played, underruns recovered

The task never resets stats; the caller owns it. An underrun loses the period that met it. The task prepares the stream again and fills the next period fresh. So periods counts what played and underruns what did not. The task ends on a device error other than an underrun or a full ring.