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

Pure C++20 MPEG-1 Layer III (MP3) codec - decoder and encoder. More...

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

Go to the source code of this file.

Classes

class  dspark::Mp3File
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Pure C++20 MPEG-1 Layer III (MP3) codec - decoder and encoder.

Full MP3 codec supporting both reading and writing:

Decoder: Decodes MPEG-1 Layer III to normalised float [-1, 1].

  • Sample rates: 32000, 44100, 48000 Hz
  • Mono and stereo (including joint stereo with M/S and intensity)
  • CBR and VBR, ID3v2 tag skipping
  • getInfo() reports the delivery format (32-bit float); MP3 itself has no PCM bit depth

Encoder: Encodes float audio to MPEG-1 Layer III CBR.

  • Bitrates: 32-320 kbps (CBR); AudioFileInfo::bitsPerSample carries the requested bitrate in kbps and snaps to the nearest legal value
  • Mono and stereo; the sample rate snaps to 32000/44100/48000 Hz
  • Analysis polyphase filterbank + MDCT + Huffman coding, rate-controlled by a uniform global-gain search (no psychoacoustic model)
  • Produces standard-compliant MP3 playable by any decoder
Warning
DECODE-ALL ARCHITECTURE: Because MP3 uses a backward-referencing Bit Reservoir, random-access streaming is non-trivial. openRead() decodes the ENTIRE FILE into RAM (input capped at 256 MB). This operation takes time and blocks the thread. NEVER call openRead() 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 Mp3File.h.