Re: FLAC frame boundaries and protocol

Miroslav Lichvar <[email protected]> Wed, 6 Mar 2019 11:56:54 +0100
Newsgroups gmane.comp.audio.compression.flac.devel
Message-ID <20190306105654.GO21520@localhost>
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
frame.

-- 
Miroslav Lichvar
_______________________________________________
flac-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/flac-dev