Search guides and the APICtrl K
  1. API reference
  2. Files and codecs

audiofile_codecs.h

The lossy decoders, vendored.

#include <sonore/audiofile_codecs.h>

    Design notes

    WAV, AIFF and FLAC we decode ourselves: their formats are simple enough that our own code is verifiable SAMPLE-EXACT against reference material, and owning them is worth something. MP3 and Vorbis are the opposite case (thousands of lines of Huffman tables, IMDCT and codebooks with zero differentiation in them), so they are vendored from the two public-domain implementations everyone uses:

    minimp3    (lieff):        CC0, public domain
    stb_vorbis (Sean Barrett): public domain / MIT, dual

    Both are permissive in the way this SDK requires: nothing propagates to a customer's product, which is the whole reason this SDK exists at all.

    The implementations are pulled into an ANONYMOUS NAMESPACE so every translation unit gets its own internal-linkage copy. A header-only SDK that emitted external symbols from a vendored .c would collide the moment a plugin was built from two source files.

    Which needs their extern "C" blocks switched off (SONORE_CODEC_CPP_LINKAGE, a local change in both files). A function with C language linkage is one function by its bare name whatever namespace declares it, and MSVC gave these external linkage inside the anonymous namespace all the same: two source files including audiofile.h failed to link, 18 times over (mp3dec_init already defined...), and so did a standalone with a second file, and a plugin beside its own copy of either codec. With C++ linkage the anonymous namespace does what this paragraph says.

    And what the two files define for themselves -- TRUE, FALSE, a float M_PI, their configuration and include guards -- does not outlive them: a user's own M_PI or minimp3.h after this header is theirs, not ours.

    Nothing public is declared here: the header supports the others in its area, and its notes above say how.

    ↑↓ to move↵ to openEvery public name in the headers, and every guide