Class thl::audio_io::AudioFileWriter#
-
class AudioFileWriter#
Encodes a planar buffer to an audio file using miniaudio.
Samples are written as 32-bit float. The buffer is interleaved in fixed-size blocks, so long buffers are never duplicated in memory.
This class has no mutable state, so multiple instances may be used concurrently on different threads.
Public Functions
-
AudioFileWriter() = default#
-
~AudioFileWriter() = default#
-
bool write_to_file(const std::string &file_path, const core::ConstBufferView &buffer, double sample_rate, AudioEncodingFormat format = AudioEncodingFormat::WAV)#
Write
buffertofile_pathas a 32-bit float RIFF WAV file.The audio is first written to a uniquely named, exclusively created staging file next to
file_pathand renamed over it only once every write, seek and close has succeeded, so a failed export never alters an existing file.Returns false without touching the file system when:
formatis not WAV (the bundled miniaudio encoder only supports WAV),the channel count is 0 or above MA_MAX_CHANNELS,
sample_ratedoes not round to [1, 384000] Hz, the range the bundled WAV decoder reads,the audio would exceed the 4 GiB RIFF size limit (about 23 minutes for 16 channels at 48 kHz).
- Returns:
true on success, false otherwise.
-
AudioFileWriter() = default#