mach icon indicating copy to clipboard operation
mach copied to clipboard

proposal: FLAC decoding

Open desttinghim opened this issue 3 years ago • 0 comments

FLAC is a losslessly compressed audio format. There are two ways to get this supported: find a C library with no libc dependency and set up a build process for it, or the fun way, which is to implement it in Zig :smile:

For option one, mackron's dr_ libs look interesting, but I have not tried to use them.

For option two I have some notes on what needs to be figured out. This is the specification I am referencing.

  • Metadata decoding - a lot of the metadata is specific to music, so not all of it may be necessary to decode. Ideally We would expose all of the information so the developer can choose what is relevant to them
    • Stream info - Mandatory, specifies the encoding of the data
    • Seektable - Informs the decoder of the byte offset of specific frame headers useful if seeking is needed
    • Vorbis Comment - stores textual information. Might be useful
    • Cuesheet - stores offset of tracks within the file, mostly useful for storing an entire album in one file
    • Picture - FLAC files can store icons, album art, CD covers, and more. Not generally applicable to games ( unless the game developer wants to make a music player in game )
  • Frames - I still need to read through this part of the Specification more thoroughly so I can understand how the audio data is actually encoded. The basic gist I've gotten is that FLAC has a prediction function per frame and it then stores the difference between the predicted value and the actual value. All samples are processed and stored as integers to prevent floating point precision loss
    • Prediction methods
      • Verbatim - this is just PCM samples
      • Constant - TODO
      • Fixed Linear predictor - TODO
      • FIR Linear prediction - TODO
    • Residual Coding - TODO

desttinghim avatar Sep 20 '22 17:09 desttinghim