|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Abstract base class for audio file readers and writers. More...
#include <AudioFile.h>

Public Member Functions | |
| virtual | ~AudioFile ()=default |
| virtual bool | openRead (const std::filesystem::path &path)=0 |
| Opens a file for reading. | |
| virtual bool | openWrite (const std::filesystem::path &path, const AudioFileInfo &info)=0 |
| Opens a file for writing, creating it or overwriting if it exists. | |
| virtual AudioFileInfo | getInfo () const =0 |
| Retrieves metadata of the currently opened file. | |
| virtual bool | readSamples (AudioBufferView< float > dest)=0 |
| Reads samples from the start of the file into the destination view. | |
| virtual bool | readSamples (AudioBufferView< float > dest, int64_t startFrame, int64_t numFrames)=0 |
| Reads a specific range of sample frames. Useful for chunked streaming. | |
| virtual bool | writeSamples (AudioBufferView< const float > src)=0 |
| Writes samples from the view to the file. | |
| virtual void | close ()=0 |
| Finalizes file headers and releases system handles. | |
| virtual bool | isOpen () const noexcept=0 |
| Checks if a valid file handle is currently open. | |
| virtual bool | hasWriteError () const noexcept |
| Reports whether the current or most recent writer hit an I/O failure. | |
Abstract base class for audio file readers and writers.
Provides a uniform API to transfer audio to/from AudioBufferView objects. Samples are normalized to the [-1.0, 1.0] float range: implementations convert to/from the stored bit depth transparently.
Definition at line 110 of file AudioFile.h.
|
virtualdefault |
|
pure virtual |
Finalizes file headers and releases system handles.
Safe to call multiple times. Implementations invoke this from their destructor, so an open file is always finalized; call it explicitly, then hasWriteError(), when you need to know that a written file is complete (a destructor cannot report failure), or to release the file before the object dies.
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Retrieves metadata of the currently opened file.
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
inlinevirtualnoexcept |
Reports whether the current or most recent writer hit an I/O failure.
Covers every writeSamples() call and the header finalisation that close() performs, so checking it after close() tells whether the file on disk is complete. The status survives close() and is cleared by the next openRead() or openWrite(). Readers, and implementations that never write, report false.
Reimplemented in dspark::Mp3File, and dspark::WavFile.
Definition at line 206 of file AudioFile.h.
|
pure virtualnoexcept |
Checks if a valid file handle is currently open.
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Opens a file for reading.
Any previously open file is closed first.
| path | File path using C++20 std::filesystem (handles UTF-8/cross-platform safely). |
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Opens a file for writing, creating it or overwriting if it exists.
Any previously open file is closed first.
| path | File path. |
| info | Desired output format metadata. |
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Reads samples from the start of the file into the destination view.
Reads up to min(view length, file length) frames into up to min(view channels, file channels) channels. Excess buffer space and channels beyond those present in the file are left untouched.
| dest | Buffer view to receive the audio data. |
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Reads a specific range of sample frames. Useful for chunked streaming.
The requested range must lie entirely within the file (startFrame >= 0, numFrames > 0, startFrame + numFrames <= numSamples); out-of-range requests return false without reading. As with the full-file overload, the transfer is clamped to the view's capacity.
| dest | Buffer view to receive the audio data. |
| startFrame | The absolute frame index in the file to start reading from. |
| numFrames | The number of frames to read. |
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Writes samples from the view to the file.
Converts float [-1.0, 1.0] back to the native bit-depth defined in openWrite(). May be called repeatedly to append blocks (streaming writes).
| src | Buffer view containing the data to write. |
Implemented in dspark::FlacFile, dspark::Mp3File, and dspark::WavFile.