Search guides and the APICtrl K
  1. API reference
  2. Files and codecs

record.h

Recording audio to disk from a plugin, without stalling it.

#include <sonore/record.h>
  • 1type
On this page

Design notes

A threaded writer, and the reason it is a separate thing from "write a file" is the audio callback. Opening a file, growing a buffer and calling fwrite are all things that can block for milliseconds; doing any of them where audio is produced is a dropout. And the obvious alternative -- keep every sample in memory and write at the end -- is what the standalone's --capture used to do, which works for a twenty-second render and turns into gigabytes for a take.

So: the audio thread pushes into a lock-free ring, a background thread drains it to a WAV file, and neither ever waits for the other. When the ring overflows the frames are DROPPED and counted, never overwritten -- a gap in a recording is obvious and recoverable, where a splice of two different moments sounds like the plugin corrupted the take.

Types 1

A WAV file being written while audio is playing.

start() and stop() are MAIN THREAD. write() is the only thing the audio thread touches, and it allocates nothing, locks nothing and never blocks. The audio thread need not stop calling it: stop() waits out a write() in progress, so a take ends and the next one starts while audio runs.

32-bit float, matching writeWav(): a recording is usually the thing a user wants to edit somewhere else, and quantising on the way out is a decision best left to whatever they open it in.

↑↓ to move↵ to openEvery public name in the headers, and every guide