[flac-dev] FLAC frame boundaries and protocol
mlichvar at redhat.com
Wed Mar 6 10:56:54 UTC 2019
On Tue, Mar 05, 2019 at 10:26:54PM -0800, Brian Willoughby wrote:
> 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.
The specification says frames are aligned to bytes:
Following the frame header are encoded subframes, one for each
channel, and finally, the frame is zero-padded to a byte boundary.
The problem with finding frame boundaries is that the sync code and
the 8-bit CRC are too short, so the whole frame needs to be parsed
and the 16-bit CRC checked to be reasonably sure it really is a FLAC
More information about the flac-dev