Re: [flac-dev] FLAC frame boundaries and protocol

2019-03-19 Thread Dave Harris

Thanks, guys. Your answers helped and I think I have some ideas now on what to 
do.
On Wednesday, March 6, 2019 Miroslav Lichvar  wrote:
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
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev


Re: [flac-dev] FLAC frame boundaries and protocol

2019-03-06 Thread Miroslav Lichvar
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
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev


Re: [flac-dev] FLAC frame boundaries and protocol

2019-03-05 Thread Brian Willoughby
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  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.
> 
___
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev


[flac-dev] FLAC frame boundaries and protocol

2019-03-05 Thread Dave Harris

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.
___
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev