Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::audio::AudioFile Class Reference

RAII class to read and write audio files (or their metadata). More...

#include <src/utils/audio_file.h>

Public Member Functions

 AudioFile (std::filesystem::path filepath, bool for_writing=false)
 Creates a new instance of an AudioFile for the given path.
 AudioFile (AudioFile &&other) noexcept
AudioFile & operator= (AudioFile &&other) noexcept
AudioFileMetadata read_metadata ()
 Reads the metadata for the specified file.
void read_samples_interleaved (bool in_parts, float *samples, size_t start_from, size_t num_frames_to_read)
 Reads the file into an internal float array (interleaved).
void read_full (zrythm::utils::audio::AudioBuffer &buffer, std::optional< size_t > samplerate)
 Simple blocking API for reading and optionally resampling audio files.

Detailed Description

RAII class to read and write audio files (or their metadata).

Definition at line 43 of file audio_file.h.

Constructor & Destructor Documentation

◆ AudioFile()

zrythm::utils::audio::AudioFile::AudioFile ( std::filesystem::path filepath,
bool for_writing = false )

Creates a new instance of an AudioFile for the given path.

Parameters
filepathPath to the file.
for_writingWhether to create the file for writing.

Member Function Documentation

◆ read_full()

void zrythm::utils::audio::AudioFile::read_full ( zrythm::utils::audio::AudioBuffer & buffer,
std::optional< size_t > samplerate )

Simple blocking API for reading and optionally resampling audio files.

Only to be used on small files.

Parameters
[out]bufferBuffer to store the result to. Its internal buffers may be re-allocated.
samplerateIf specified, the audio will be resampled to the given samplerate.
Exceptions
ZrythmExceptionon error.

◆ read_metadata()

AudioFileMetadata zrythm::utils::audio::AudioFile::read_metadata ( )

Reads the metadata for the specified file.

Exceptions
ZrythmExceptionon error.

◆ read_samples_interleaved()

void zrythm::utils::audio::AudioFile::read_samples_interleaved ( bool in_parts,
float * samples,
size_t start_from,
size_t num_frames_to_read )

Reads the file into an internal float array (interleaved).

Parameters
samplesSamples to fill in.
in_partsWhether to read the file in parts. If true, start_from and num_frames_to_read must be specified.
samples[out]Pre-allocated frame array. Caller must ensure there is enough space (ie, number of frames * number of channels).
Exceptions
ZrythmExceptionon error.

The documentation for this class was generated from the following file: