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>

Collaboration diagram for zrythm::utils::audio::AudioFile:

Public Member Functions

 AudioFile (fs::path filepath, bool for_writing=false)
 Creates a new instance of an AudioFile for the given path.
 AudioFile (AudioFile &&other) noexcept=default
AudioFileoperator= (AudioFile &&other) noexcept=default
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.

Data Fields

fs::path filepath_
 Absolute path.
AudioFileMetadata metadata_
std::unique_ptr< juce::AudioFormatReader > reader_
std::unique_ptr< juce::AudioFormatWriter > writer_
bool for_writing_ = false

Detailed Description

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

Definition at line 47 of file audio_file.h.

Constructor & Destructor Documentation

◆ AudioFile()

zrythm::utils::audio::AudioFile::AudioFile ( fs::path filepath,
bool for_writing = false )
inline

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

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

Definition at line 58 of file audio_file.h.

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.

Field Documentation

◆ filepath_

fs::path zrythm::utils::audio::AudioFile::filepath_

Absolute path.

Definition at line 117 of file audio_file.h.

◆ for_writing_

bool zrythm::utils::audio::AudioFile::for_writing_ = false

Definition at line 124 of file audio_file.h.

◆ metadata_

AudioFileMetadata zrythm::utils::audio::AudioFile::metadata_

Definition at line 119 of file audio_file.h.

◆ reader_

std::unique_ptr<juce::AudioFormatReader> zrythm::utils::audio::AudioFile::reader_

Definition at line 121 of file audio_file.h.

◆ writer_

std::unique_ptr<juce::AudioFormatWriter> zrythm::utils::audio::AudioFile::writer_

Definition at line 122 of file audio_file.h.


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