audiostream.h
Reading an audio file without holding all of it.
#include <sonore/audiostream.h>- 1type
On this page
Design notes
audiofile.h reads a whole file into a vector, which is the right answer for an impulse response, a one-shot, or anything a plugin ships with. It is the wrong answer for a sample library: a two-gigabyte WAV becomes two gigabytes of RAM per instance, and eight instances of a sampler is a session that will not open.
What is missing is a reader that keeps the FILE open and fetches the frames asked for. That is easy and exact for uncompressed formats, where frame N is at a computable byte offset, and it is a different problem entirely for FLAC, MP3 and Ogg, where finding frame N means decoding to it.
So this covers WAV and AIFF, and REFUSES the compressed formats by name rather than pretending. A caller that hands it an MP3 is told to use readAudioFile, which handles that properly, instead of being handed a reader that silently decodes the whole thing on the first read and defeats the purpose of asking.
Types 1
An open audio file, read a range at a time.
Not thread safe, and deliberately not: a std::FILE has one position, and hiding that behind a lock would put a lock in whatever thread a sampler chose to read from. One reader per thread, or one reader and a queue.
The read itself is NOT real-time safe -- it is a seek and a fread, which can block for as long as the disk feels like. That is the nature of reading from a disk and no wrapper changes it; a sampler streams on a worker thread into a ring, exactly as the audio input backend does.