[flac-dev] FLAC frame boundaries and protocol

Brian Willoughby brianw at audiobanshee.com
Wed Mar 6 06:26:54 UTC 2019


Hello Dave.

Frames start with a 14-bit sync code, which is 13 “one" bits and 1 “zero" bit. Subframes start with a 1-bit padding of “zero." Keep in mind that FLAC is a bit stream, not a byte stream, so that 14-bit frame sync can happen anywhere in a pair of bytes. You can’t simply scan memory bytes for a frame sync, at least not unless you allow for 8 variations, apply bit masks, and allow for non-word-address-aligned matches.

Whenever I have a question about the FLAC format, I always start by typing http://flac.sourceforge.net/ into my browser, which redirects to https://xiph.org/flac/ these days.

There part you’re looking for is here:

https://xiph.org/flac/format.html#blocking

As for reference code, I recommend using the FLAC library. In other words, include the headers and link to the library, calling the API as it was designed. Don’t write your own code, that’s just asking for mistakes. I have not used the FLAC++ library, so I don’t know whether it has any peculiar issues. I’ve always used the Standard C FLAC library, and never have any trouble. You do have to pay attention to the sample format, particularly the bit justification for larger samples like 24-bit audio. I remember being interested in streaming, as opposed to file-based compression, but I can’t recall whether I ever finished that project.

Brian Willoughby


On Mar 5, 2019, at 10:36 AM, Dave Harris <dmwharris at verizon.net> wrote:
> Hello,
> 
> I've set up and have been reading through the FLAC reference implementation source code on Windows and stepping through it in the debugger.   I've been trying to understand how the protocol knows where the subframe and frame boundaries are. Is there a good tutorial that discusses the ins and outs of the flac protocol? Also, is there a piece of the reference code that shows how frame and subframe boundaries are calculated?
> 
> Thanks.
> 


More information about the flac-dev mailing list