|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
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. | |
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 106 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 when you need the write error-checked (a destructor cannot report failure) or the file released before the object dies.
Implemented in dspark::Mp3File, and dspark::WavFile.
|
pure virtual |
Retrieves metadata of the currently opened file.
Implemented in dspark::Mp3File, and dspark::WavFile.
|
pure virtualnoexcept |
Checks if a valid file handle is currently open.
Implemented in 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::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::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::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::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::Mp3File, and dspark::WavFile.