[flac-dev] Exact FLAC subset constraints

Барт Гопник bart.gopnik at gmail.com
Mon Jan 13 05:24:07 PST 2014


>>>>>>>>> I'm misleading about FLAC subset constraints... Please help me
>>>>>>>>> understand exact FLAC subset limitation.
>>>>>>>>>
>>>>>>>>> From https://www.xiph.org/flac/documentation_tools_flac.html#flac_options_blocksize:
>>>>>>>>>
>>>>>>>>> Subset streams must use one of
>>>>>>>>> 192/576/1152/2304/4608/256/512/1024/2048/4096 (and 8192/16384 if the
>>>>>>>>> sample rate is >48kHz). The reference encoder uses the same block size
>>>>>>>>> for the entire stream.
>>>>>>>>>
>>>>>>>>> From https://www.xiph.org/flac/format.html#subset:
>>>>>>>>>
>>>>>>>>> The blocksize must be <=16384; if the sample rate is <= 48000Hz, the
>>>>>>>>> blocksize must be <=4608.
>>>>>>>>>
>>>>>>>>> Finally, "one of 192/576/1152/2304/4608/256/512/1024/2048/4096" or
>>>>>>>>> just (simply) "<=4608", "one of 8192/16384" or just "<=16384"?
>>>>>>>>>
>>>>>>>>> Maximum (4608) value and any intermediate values are not one of
>>>>>>>>> 192/576/1152/2304/4608/256/512/1024/2048/4096.
>>>>>>>>>
>>>>>>>>> The first statement is more restricted.
>>>>>>>>>
>>>>>>>>> Is the word "must" to be interpreted as described in RFC 2119
>>>>>>>>> (http://www.ietf.org/rfc/rfc2119.txt)?
>>>>>>>>>
>>>>>>>>> The second question:
>>>>>>>>>
>>>>>>>>> From https://www.xiph.org/flac/documentation_format_overview.html:
>>>>>>>>>
>>>>>>>>> The reference encoder uses a single block size for the whole stream
>>>>>>>>> but the FLAC format does not require it.
>>>>>>>>>
>>>>>>>>> Should stream MUST have constant (fixed) block size (if blocksize
>>>>>>>>> satisfies all restrictions from first question) to be subset?
>>>>>>>>>
>>>>>>>>> Is variable block size stream (if blocksize satisfies all restrictions
>>>>>>>>> from first question) be subset?
>>>>>>>>>
>>>>>>>>> The third question:
>>>>>>>>>
>>>>>>>>> Is FLAC files compressed by FFMPEG with "-compression_level 12" switch
>>>>>>>>> are subset?


>>>>>>>> I don't understand what it is you don't get about those blocksizes. For
>>>>>>>> subset streams, the blocksize has to be one of 576/1152/2304/4608 or
>>>>>>>> 256/512/1024/2048/4096 if the samplerate is lower then or equal to
>>>>>>>> 48kHz, if higher, 8192 and 16384 are allowed too. If you use any other
>>>>>>>> blocksize, the stream is not subset compliant.
>>>>>>>>
>>>>>>>> Considering the fixed or variable blocksize stuff, the subset does not
>>>>>>>> restrict that, so using a variable blocksize is technically subset
>>>>>>>> compliant. However, flake does warn when using variable blocksizes that
>>>>>>>> the stream is not subset compliant. The thing is, it's not in the
>>>>>>>> reference encoder, so probably most (hardware) decoders haven't been
>>>>>>>> tested with it. If you want to be safe, you should probably restrict
>>>>>>>> yourself to a fixed-blocksize stream.
>>>>>>>>
>>>>>>>> Finally, ffmpeg level 12 is not subset compliant.


>>>>>>> I mean that the first statement [Subset streams must use one of
>>>>>>> 192/576/1152/2304/4608/256/512/1024/2048/4096 (and 8192/16384 if the
>>>>>>> sample rate is >48kHz).] published on
>>>>>>> https://www.xiph.org/flac/documentation_tools_flac.html#flac_options_blocksize
>>>>>>> page IS NOT EQUAL to second statement [The blocksize bits in the frame
>>>>>>> header must be 0001-1110. The blocksize must be <=16384; if the sample
>>>>>>> rate is <= 48000Hz, the blocksize must be <=4608.] published on
>>>>>>> https://www.xiph.org/flac/format.html#subset page.
>>>>>>>
>>>>>>> What statement (first or second) is right?
>>>>>>>
>>>>>>> 0001-1110 mean 0110 and 0111 too??? (0110 mean "get 8 bit
>>>>>>> (blocksize-1) from end of header", 0111 mean "get 16 bit (blocksize-1)
>>>>>>> from end of header")
>>>>>>>
>>>>>>> Why you don't use STRICT block size checking in
>>>>>>> FLAC__format_blocksize_is_subset() like this:
>>>>>>>
>>>>>>> FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned
>>>>>>> blocksize, unsigned sample_rate)
>>>>>>> {
>>>>>>>         if(blocksize == 192 || blocksize == 576 || blocksize == 1152
>>>>>>> || blocksize == 2304 || blocksize == 4608 || blocksize == 256 ||
>>>>>>> blocksize == 512 || blocksize == 1024 || blocksize == 2048 ||
>>>>>>> blocksize == 4096 || (sample_rate > 48000 && (blocksize == 8192 ||
>>>>>>> blocksize == 16384)))
>>>>>>>                 return true;
>>>>>>>         else
>>>>>>>                 return false;
>>>>>>> }
>>>>>>>
>>>>>>> instead of
>>>>>>>
>>>>>>> FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned
>>>>>>> blocksize, unsigned sample_rate)
>>>>>>> {
>>>>>>>         if(blocksize > 16384)
>>>>>>>                 return false;
>>>>>>>         else if(sample_rate <= 48000 && blocksize > 4608)
>>>>>>>                 return false;
>>>>>>>         else
>>>>>>>                 return true;
>>>>>>> }
>>>>>>>
>>>>>>> FLAC__format_blocksize_is_subset from format.c IS NOT EQUAL to my
>>>>>>> code. E.g. FLAC__format_blocksize_is_subset(1536, 44100) from format.c
>>>>>>> returns true, but 1536 is not subset blocksize because 1536 is not one
>>>>>>> of 192/576/1152/2304/4608/256/512/1024/2048/4096!


>>>>>> I think you've found a bug, Bart.
>>>>>>
>>>>>> flac 1.2.1 did not have any FLAC__format_blocksize_is_subset() function, so
>>>>>> the source you're seeing in format.c must be new. If the format
>>>>>> documentation you linked to is correct, then either the specifications are
>>>>>> self-contradictory, or the code is not implementing the subset checks as
>>>>>> described. My interpretation is that blocksize bits of 0110 and 0111 would
>>>>>> not be included in the subset. The whole point of the subset is to have a
>>>>>> small and finite list of values so that embedded decoders do not have to
>>>>>> deal with every possible block size.
>>>>>>
>>>>>> This bears further investigation.


>>>>> FLAC__format_blocksize_is_subset() was introduced by commit #8ab0138
>>>>> (https://gitorious.org/flac/flac/commit/8ab013837d379d3d1fa84eac5420faec41852fd7)
>>>>> over 5 years ago and available in the latest stable release 1.3.0.
>>>>>
>>>>> It would be nice if the official FLAC documentation used common
>>>>> adopted (used) math notation: math intervals (left-open, right-open,
>>>>> open, left-closed, right-closed, closed) e.g. "[0010, 0101] ∪ [1000,
>>>>> 1110]" or simply math sets e.g. "{0010, 0011, 0100, 0101, 1000, 1001,
>>>>> 1010, 1011, 1100, 1101, 1110}" (if number of elements in not too big)
>>>>> instead of current nonstrict notation e.g. "0001-1110" to
>>>>> disambiguate.
>>>>>
>>>>> There are other ambiguities in official FLAC documentation.
>>>>>
>>>>> It would be nice if FLAC project had its own doc wiki.
>>>>>
>>>>> Should I open a bug ticket?
>>>>>
>>>>> Please keep me informed on your investigation.


>>>> I agree. Please keep up informed.


>>> Any progress?


>> http://git.xiph.org/?p=flac.git;a=commit;h=09229aa967251ce840e43d300d27a915495e75db
>> commit 2007-07-31, author: Josh Coalson, committer: Josh Coalson
>>
>> "document blocksize strategy bit, RESIDUAL_CODING_METHOD_PARTITIONED_RICE2, new
>> subset sample rates, subset clarification, variable blocksize clarification"
>>
>> Before:
>> "The blocksize bits in the frame header must be 0001-0101 or 1000-1110,
>> specifying a fixed-blocksize stream (the exception being the last block as
>> described in the table) and a few allowable blocksizes. This also means that
>> the STREAMINFO metadata block must specify equal mininum and maximum
>> blocksizes. If the sample rate is <= 48000Hz, the blocksize must be <=4608,
>> i.e. blocksize bits 0001-0101 or 1000-1100."
>>
>> After:
>> "The blocksize bits in the frame header must be 0001-1110. The blocksize must
>> be <=16384; if the sample rate is <= 48000Hz, the blocksize must be <=4608."


> Also found this:
>
> http://lists.xiph.org/pipermail/flac-dev/2008-May/002550.html
> http://lists.xiph.org/pipermail/flac-dev/2008-May/002559.html


Well, finally, any block size from following math interval [16, 191] ∪
[193, 255] ∪ [257, 511] ∪ [513, 575] ∪ [577, 1023] ∪ [1025, 1151] ∪
[1153, 2047] ∪ [2049, 2303] ∪ [2305, 4095] ∪ [4097, 4607] is subset,
or not? If sample rate > 48 kHz, any block size from following math
interval [16, 191] ∪ [193, 255] ∪ [257, 511] ∪ [513, 575] ∪ [577,
1023] ∪ [1025, 1151] ∪ [1153, 2047] ∪ [2049, 2303] ∪ [2305, 4095] ∪
[4097, 4607] ∪ [4609, 8191] ∪ [8193, 16383] is subset, or not?

In other words, for example, 1536 is subset block size, or not?


More information about the flac-dev mailing list