mirror of https://github.com/xiph/flac
Add support in the encoder for up to 20 bit sample rates
Now that many DACs support up to 768kHz, add support for these sample rates to the encoder. Files produced with these sample rates are already decodable by the reference decoder. Update documentation and tests accordingly.
This commit is contained in:
parent
f7e77f627a
commit
24629435bb
|
@ -278,7 +278,7 @@
|
||||||
<br />
|
<br />
|
||||||
FLAC supports linear PCM samples with a resolution between 4 and 32 bits per sample. FLAC does not support floating point samples. In some cases it is possible to losslessly transform samples from an incompatible range to a FLAC-compatible range before encoding.<br />
|
FLAC supports linear PCM samples with a resolution between 4 and 32 bits per sample. FLAC does not support floating point samples. In some cases it is possible to losslessly transform samples from an incompatible range to a FLAC-compatible range before encoding.<br />
|
||||||
<br />
|
<br />
|
||||||
FLAC supports linear sample rates from 1Hz - 655350Hz in 1Hz increments.<br />
|
FLAC supports linear sample rates from 1Hz - 1048575Hz in 1Hz increments.<br />
|
||||||
<br />
|
<br />
|
||||||
<a name="general__samples_fp"><b>Will FLAC ever support floating-point samples?</b></a><br />
|
<a name="general__samples_fp"><b>Will FLAC ever support floating-point samples?</b></a><br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -523,7 +523,7 @@
|
||||||
<20>
|
<20>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Sample rate in Hz. Though 20 bits are available, the maximum sample rate is limited by the structure of frame headers to 655350Hz. Also, a value of 0 is invalid.
|
Sample rate in Hz. 20 bits are available, the maximum sample rate being 1048575Hz. Also, a value of 0 is invalid.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -125,7 +125,7 @@ extern "C" {
|
||||||
* ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
|
* ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
|
||||||
* as to why.
|
* as to why.
|
||||||
*/
|
*/
|
||||||
#define FLAC__MAX_SAMPLE_RATE (655350u)
|
#define FLAC__MAX_SAMPLE_RATE (1048575u)
|
||||||
|
|
||||||
/** The maximum LPC order permitted by the format. */
|
/** The maximum LPC order permitted by the format. */
|
||||||
#define FLAC__MAX_LPC_ORDER (32u)
|
#define FLAC__MAX_LPC_ORDER (32u)
|
||||||
|
|
|
@ -218,12 +218,10 @@ FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(uint32_t blocksize, uint32_
|
||||||
|
|
||||||
FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate)
|
FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate)
|
||||||
{
|
{
|
||||||
if(
|
if( // sample rate is not subset if
|
||||||
!FLAC__format_sample_rate_is_valid(sample_rate) ||
|
!FLAC__format_sample_rate_is_valid(sample_rate) || // sample rate is invalid or
|
||||||
(
|
sample_rate >= ((1u << 16) * 10) || // sample rate is larger then or equal to 655360 or
|
||||||
sample_rate >= (1u << 16) &&
|
(sample_rate >= (1u << 16) && sample_rate % 10 != 0) //sample rate is >= 65536 and not divisible by 10
|
||||||
!(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,10 +853,10 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
||||||
encoder->private_->loose_mid_side_stereo_frames = (uint32_t)((double)encoder->protected_->sample_rate * 0.4 / (double)encoder->protected_->blocksize + 0.5);
|
encoder->private_->loose_mid_side_stereo_frames = (uint32_t)((double)encoder->protected_->sample_rate * 0.4 / (double)encoder->protected_->blocksize + 0.5);
|
||||||
#else
|
#else
|
||||||
/* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */
|
/* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */
|
||||||
/* sample rate can be up to 655350 Hz, and thus use 20 bits, so we do the multiply÷ by hand */
|
/* sample rate can be up to 1048575 Hz, and thus use 20 bits, so we do the multiply÷ by hand */
|
||||||
FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
|
FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 1048575);
|
||||||
FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
|
FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
|
||||||
FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
|
FLAC__ASSERT(encoder->protected_->sample_rate <= 1048575);
|
||||||
FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
|
FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
|
||||||
encoder->private_->loose_mid_side_stereo_frames = (uint32_t)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
|
encoder->private_->loose_mid_side_stereo_frames = (uint32_t)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -278,7 +278,7 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWrit
|
||||||
default:
|
default:
|
||||||
if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
|
if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
|
||||||
sample_rate_hint = u = 12;
|
sample_rate_hint = u = 12;
|
||||||
else if(header->sample_rate % 10 == 0)
|
else if(header->sample_rate <= 655350 && header->sample_rate % 10 == 0)
|
||||||
sample_rate_hint = u = 14;
|
sample_rate_hint = u = 14;
|
||||||
else if(header->sample_rate <= 0xffff)
|
else if(header->sample_rate <= 0xffff)
|
||||||
sample_rate_hint = u = 13;
|
sample_rate_hint = u = 13;
|
||||||
|
|
|
@ -65,11 +65,14 @@ static struct {
|
||||||
{ 500010 , true , true },
|
{ 500010 , true , true },
|
||||||
{ 655349 , true , false },
|
{ 655349 , true , false },
|
||||||
{ 655350 , true , true },
|
{ 655350 , true , true },
|
||||||
{ 655351 , false, false },
|
{ 655351 , true , false },
|
||||||
{ 655360 , false, false },
|
{ 655360 , true , false },
|
||||||
{ 700000 , false, false },
|
{ 700000 , true , false },
|
||||||
{ 700010 , false, false },
|
{ 700010 , true , false },
|
||||||
{ 1000000, false, false },
|
{ 705600 , true , false },
|
||||||
|
{ 768000 , true , false },
|
||||||
|
{ 1000000, true , false },
|
||||||
|
{ 1048575, true , false },
|
||||||
{ 1100000, false, false }
|
{ 1100000, false, false }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue