|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Complete WAV file reader and writer in pure C++20. More...
#include <WavFile.h>


Public Types | |
| enum class | Encoding { Pcm , Float , ALaw , MuLaw , ImaAdpcm , MsAdpcm } |
| How the samples of the file open for reading are coded. More... | |
| enum class | Rf64Mode { Never , Auto , Always } |
| Container used by the next openWrite(). More... | |
Public Member Functions | |
| ~WavFile () override | |
| void | setRf64Mode (Rf64Mode mode) noexcept |
| Chooses the container of files opened for writing from now on. | |
| Rf64Mode | getRf64Mode () const noexcept |
| Container chosen for files opened for writing. | |
| bool | openRead (const std::filesystem::path &path) override |
| Opens a WAV file for reading. | |
| bool | openWrite (const std::filesystem::path &path, const AudioFileInfo &info) override |
| Opens a WAV file for writing, overwriting if it exists. | |
| AudioFileInfo | getInfo () const override |
| Format of the open file. | |
| Encoding | getEncoding () const noexcept |
| Sample coding of the file open for reading (Pcm when none is). | |
| bool | readSamples (AudioBufferView< float > dest) override |
| Reads samples from the start of the file into the destination view. | |
| bool | readSamples (AudioBufferView< float > dest, int64_t startFrame, int64_t numFrames) override |
| Reads a specific range of sample frames. Useful for chunked streaming. | |
| bool | writeSamples (AudioBufferView< const float > src) override |
| Writes samples from the view to the file. | |
| void | close () override |
| Finalizes file headers and releases system handles. | |
| bool | isOpen () const noexcept override |
| Checks if a valid file handle is currently open. | |
| bool | hasWriteError () const noexcept override |
| True when a write or the header finalisation of the current or most recent writer failed. | |
Public Member Functions inherited from dspark::AudioFile | |
| virtual | ~AudioFile ()=default |
Complete WAV file reader and writer in pure C++20.
Inherits from AudioFile to provide a uniform interface. Handles both standard PCM and IEEE float formats, mono through multi-channel (up to 64 channels), and reads G.711 and IMA/Microsoft ADPCM files.
|
strong |
|
strong |
Container used by the next openWrite().
| Enumerator | |
|---|---|
| Never | Classic RIFF/WAVE, at most 4 GiB (the default). |
| Auto | RIFF with a reserved ds64 slot, promoted to RF64 beyond 4 GiB. |
| Always | RF64 whatever the size. |
|
inlineoverridevirtual |
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.
Implements dspark::AudioFile.
|
inlinenoexcept |
|
inlineoverridevirtual |
Format of the open file.
bitsPerSample is the fmt chunk's wBitsPerSample for PCM and float: the container width for WAVE_FORMAT_EXTENSIBLE (32 for 24-in-32) and the declared depth for a plain header (12 for 12-bit in a 16-bit container). The companded and ADPCM codings report 16, the linear resolution they decode to, so that writing the decoded audio at that depth is lossless; getEncoding() tells them apart from 16-bit PCM.
Implements dspark::AudioFile.
|
inlinenoexcept |
|
inlineoverridevirtualnoexcept |
True when a write or the header finalisation of the current or most recent writer failed.
Remains readable after close() until the next open call.
Reimplemented from dspark::AudioFile.
|
inlineoverridevirtualnoexcept |
Checks if a valid file handle is currently open.
Implements dspark::AudioFile.
|
inlineoverridevirtual |
Opens a WAV file for reading.
| path | Platform-independent path to the WAV file. |
Implements dspark::AudioFile.
|
inlineoverridevirtual |
Opens a WAV file for writing, overwriting if it exists.
The requested format is validated BEFORE the destination is touched: an unsupported format returns false without creating or truncating anything on disk.
| path | Platform-independent output path. |
| info | Configuration for sample rate, bit depth, and channels. |
Implements dspark::AudioFile.
|
inlineoverridevirtual |
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. |
Implements dspark::AudioFile.
|
inlineoverridevirtual |
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. |
Implements dspark::AudioFile.
|
inlinenoexcept |
|
inlineoverridevirtual |
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. |
Implements dspark::AudioFile.