DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
WavFile.h File Reference

High-performance, pure C++ WAV file reader/writer. More...

#include "AudioFile.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <type_traits>
#include <vector>
Include dependency graph for WavFile.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::WavFile
 Complete WAV file reader and writer in pure C++20. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

High-performance, pure C++ WAV file reader/writer.

Provides bit-accurate parsing and encoding of standard and Extensible WAV files with cache-friendly channel-major conversion loops.

Supports the following formats:

  • PCM integer: 8-bit unsigned, 16-bit, 24-bit, 32-bit signed
  • IEEE float: 32-bit and 64-bit floating-point
  • WAVE_FORMAT_EXTENSIBLE wrappers of both, including reduced-precision containers (e.g. 24 valid bits stored left-justified in a 32-bit container): samples are decoded by container width, which reproduces the reduced precision exactly.

Floating-point conversions to integer formats apply correct mathematical rounding to avoid DC offsets and harmonic distortion caused by simple truncation. Endianness is handled safely via byte-wise reconstruction to avoid Undefined Behavior (UB) on non-x86 architectures.

The writer targets classic RIFF/WAVE, whose 32-bit sizes cap a file at 4 GiB: writeSamples() refuses (returns false) any write that would overflow that limit instead of silently corrupting the header.

Warning
File operations allocate memory internally (for chunk buffers) and block the thread pending disk I/O. NEVER call open, read, or write methods from the real-time audio thread.

Threading: owner-managed. One instance serves one file from one thread at a time; no internal synchronization (see AudioFile.h).

Dependencies: IO/AudioFile.h (Core/AudioBuffer.h, Core/AudioSpec.h).

Definition in file WavFile.h.