make encoder encode the blocksize and sample rate in the frame header whenever possible, regardless if subset is specified or not

This commit is contained in:
Josh Coalson
2004-07-23 05:15:20 +00:00
parent 63945ecad5
commit 527bdda738
2 changed files with 20 additions and 16 deletions

View File

@@ -36,7 +36,7 @@
#include "bitbuffer.h" #include "bitbuffer.h"
FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitBuffer *bb); FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitBuffer *bb);
FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool streamable_subset, FLAC__bool is_last_block, FLAC__BitBuffer *bb); FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool streamable_subset, FLAC__BitBuffer *bb);
FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb); FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb);
FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb); FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb);
FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb); FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitBuffer *bb);

View File

@@ -183,7 +183,7 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
return true; return true;
} }
FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool streamable_subset, FLAC__bool is_last_block, FLAC__BitBuffer *bb) FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool streamable_subset, FLAC__BitBuffer *bb)
{ {
unsigned u, blocksize_hint, sample_rate_hint; unsigned u, blocksize_hint, sample_rate_hint;
@@ -196,6 +196,8 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool st
return false; return false;
FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE); FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
/* when this assertion holds true, any legal blocksize can be expressed in the frame header */
FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= (1u << FLAC__FRAME_HEADER_BLOCK_SIZE_LEN));
blocksize_hint = 0; blocksize_hint = 0;
switch(header->blocksize) { switch(header->blocksize) {
case 192: u = 1; break; case 192: u = 1; break;
@@ -212,14 +214,14 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool st
case 16384: u = 14; break; case 16384: u = 14; break;
case 32768: u = 15; break; case 32768: u = 15; break;
default: default:
if(streamable_subset || is_last_block) { if(header->blocksize <= 0x100)
if(header->blocksize <= 0x100) blocksize_hint = u = 6;
blocksize_hint = u = 6; else if(header->blocksize <= 0x10000)
else blocksize_hint = u = 7;
blocksize_hint = u = 7; else {
FLAC__ASSERT(0);
return false;
} }
else
u = 0;
break; break;
} }
if(!FLAC__bitbuffer_write_raw_uint32(bb, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN)) if(!FLAC__bitbuffer_write_raw_uint32(bb, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
@@ -237,13 +239,15 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool st
case 48000: u = 10; break; case 48000: u = 10; break;
case 96000: u = 11; break; case 96000: u = 11; break;
default: default:
if(streamable_subset) { if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
if(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 % 10 == 0) sample_rate_hint = u = 14;
sample_rate_hint = u = 14; else if(header->sample_rate <= 0xffff)
else sample_rate_hint = u = 13;
sample_rate_hint = u = 13; else if(streamable_subset) {
FLAC__ASSERT(0);
return false;
} }
else else
u = 0; u = 0;