make encoder encode the blocksize and sample rate in the frame header whenever possib...
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:15:20 +0000 (05:15 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:15:20 +0000 (05:15 +0000)
src/libFLAC/include/private/stream_encoder_framing.h
src/libFLAC/stream_encoder_framing.c

index 7f2c534..359fddc 100644 (file)
@@ -36,7 +36,7 @@
 #include "bitbuffer.h"
 
 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_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);
index d0fa50c..c537a1e 100644 (file)
@@ -183,7 +183,7 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
        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;
 
@@ -196,6 +196,8 @@ FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__bool st
                return false;
 
        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;
        switch(header->blocksize) {
                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 32768: u = 15; break;
                default:
-                       if(streamable_subset || is_last_block) {
-                               if(header->blocksize <= 0x100)
-                                       blocksize_hint = u = 6;
-                               else
-                                       blocksize_hint = u = 7;
+                       if(header->blocksize <= 0x100)
+                               blocksize_hint = u = 6;
+                       else if(header->blocksize <= 0x10000)
+                               blocksize_hint = u = 7;
+                       else {
+                               FLAC__ASSERT(0);
+                               return false;
                        }
-                       else
-                               u = 0;
                        break;
        }
        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 96000: u = 11; break;
                default:
-                       if(streamable_subset) {
-                               if(header->sample_rate % 1000 == 0)
-                                       sample_rate_hint = u = 12;
-                               else if(header->sample_rate % 10 == 0)
-                                       sample_rate_hint = u = 14;
-                               else
-                                       sample_rate_hint = u = 13;
+                       if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
+                               sample_rate_hint = u = 12;
+                       else if(header->sample_rate % 10 == 0)
+                               sample_rate_hint = u = 14;
+                       else if(header->sample_rate <= 0xffff)
+                               sample_rate_hint = u = 13;
+                       else if(streamable_subset) {
+                               FLAC__ASSERT(0);
+                               return false;
                        }
                        else
                                u = 0;