Because I have been watching the Ogg format and Ogg also contains FLAC audio, I have watched the FLAC audio format over the past few days. The detailed parsing of this format is done at http://developer.sourceforge.net/format.html#residual, which is very detailed.
Stream format of FLAC:"FLAC" identifier, four bytes
Metadata_block +
Frame +
Determine whether the audio type of a file is in FLAC format. It starts from the first four bytes of 'F' 'l' a 'C' and then multiple metadata_blocks, each metadata_block identifies the block type in the header. The types include:
Metadata_block_streaminfo
Metadata_block_padding
Metadata_block_application
Metadata_block_seektable
Metadata_block_vorbis_comment
Metadata_block_cuesheet
Metadata_block_picture
Generally, important parameters are included in metadata block_streaminfo to obtain BPS, channel, and sample rate. This helps us to get the total duration of the audio stream.
The frame format of FLAC is as follows:Frame_header
Subframe + (each channel has a sumberframe)
Frame_footer
It should be emphasized that each frame has a synchronization code of 11 1111 1111 1110. The size of the frame header is also uncertain, and there are many information parameters contained in the header, it is helpful for parsing the FLAC format. The length of each frame is also uncertain. It needs to be calculated based on different situations. I will not explain it in detail here. The official website is very detailed and I think it is clearer than my explanation.
FLAC subframe format:
In the subframe_header header, specify the type of this subframe.
Subframe_constant
| Subframe_fixed
| Subframe_lpc
| Subframe_verbatim
If you don't understand it, you can go to the official website or discuss it with me ~