remove FLAC__SYMMETRIC_RICE code
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 5 May 2005 00:42:31 +0000 (00:42 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 5 May 2005 00:42:31 +0000 (00:42 +0000)
src/libFLAC/bitbuffer.c
src/libFLAC/include/private/bitbuffer.h
src/libFLAC/stream_decoder.c
src/libFLAC/stream_encoder.c
src/libFLAC/stream_encoder_framing.c

index 8f5aefa..9aa0742 100644 (file)
@@ -908,127 +908,6 @@ unsigned FLAC__bitbuffer_golomb_bits_unsigned(unsigned uval, unsigned parameter)
 }
 #endif /* UNUSED */
 
-#ifdef FLAC__SYMMETRIC_RICE
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed(FLAC__BitBuffer *bb, int val, unsigned parameter)
-{
-       unsigned total_bits, interesting_bits, msbs;
-       FLAC__uint32 pattern;
-
-       FLAC__ASSERT(0 != bb);
-       FLAC__ASSERT(0 != bb->buffer);
-       FLAC__ASSERT(parameter <= 31);
-
-       /* init pattern with the unary end bit and the sign bit */
-       if(val < 0) {
-               pattern = 3;
-               val = -val;
-       }
-       else
-               pattern = 2;
-
-       msbs = val >> parameter;
-       interesting_bits = 2 + parameter;
-       total_bits = interesting_bits + msbs;
-       pattern <<= parameter;
-       pattern |= (val & ((1<<parameter)-1)); /* the binary LSBs */
-
-       if(total_bits <= 32) {
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, pattern, total_bits))
-                       return false;
-       }
-       else {
-               /* write the unary MSBs */
-               if(!FLAC__bitbuffer_write_zeroes(bb, msbs))
-                       return false;
-               /* write the unary end bit, the sign bit, and binary LSBs */
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, pattern, interesting_bits))
-                       return false;
-       }
-       return true;
-}
-
-#if 0 /* UNUSED */
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed_guarded(FLAC__BitBuffer *bb, int val, unsigned parameter, unsigned max_bits, FLAC__bool *overflow)
-{
-       unsigned total_bits, interesting_bits, msbs;
-       FLAC__uint32 pattern;
-
-       FLAC__ASSERT(0 != bb);
-       FLAC__ASSERT(0 != bb->buffer);
-       FLAC__ASSERT(parameter <= 31);
-
-       *overflow = false;
-
-       /* init pattern with the unary end bit and the sign bit */
-       if(val < 0) {
-               pattern = 3;
-               val = -val;
-       }
-       else
-               pattern = 2;
-
-       msbs = val >> parameter;
-       interesting_bits = 2 + parameter;
-       total_bits = interesting_bits + msbs;
-       pattern <<= parameter;
-       pattern |= (val & ((1<<parameter)-1)); /* the binary LSBs */
-
-       if(total_bits <= 32) {
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, pattern, total_bits))
-                       return false;
-       }
-       else if(total_bits > max_bits) {
-               *overflow = true;
-               return true;
-       }
-       else {
-               /* write the unary MSBs */
-               if(!FLAC__bitbuffer_write_zeroes(bb, msbs))
-                       return false;
-               /* write the unary end bit, the sign bit, and binary LSBs */
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, pattern, interesting_bits))
-                       return false;
-       }
-       return true;
-}
-#endif /* UNUSED */
-
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed_escape(FLAC__BitBuffer *bb, int val, unsigned parameter)
-{
-       unsigned total_bits, val_bits;
-       FLAC__uint32 pattern;
-
-       FLAC__ASSERT(0 != bb);
-       FLAC__ASSERT(0 != bb->buffer);
-       FLAC__ASSERT(parameter <= 31);
-
-       val_bits = FLAC__bitmath_silog2(val);
-       total_bits = 2 + parameter + 5 + val_bits;
-
-       if(total_bits <= 32) {
-               pattern = 3;
-               pattern <<= (parameter + 5);
-               pattern |= val_bits;
-               pattern <<= val_bits;
-               pattern |= (val & ((1 << val_bits) - 1));
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, pattern, total_bits))
-                       return false;
-       }
-       else {
-               /* write the '-0' escape code first */
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, 3u << parameter, 2+parameter))
-                       return false;
-               /* write the length */
-               if(!FLAC__bitbuffer_write_raw_uint32(bb, val_bits, 5))
-                       return false;
-               /* write the value */
-               if(!FLAC__bitbuffer_write_raw_int32(bb, val, val_bits))
-                       return false;
-       }
-       return true;
-}
-#endif /* ifdef FLAC__SYMMETRIC_RICE */
-
 FLAC__bool FLAC__bitbuffer_write_rice_signed(FLAC__BitBuffer *bb, int val, unsigned parameter)
 {
        unsigned total_bits, interesting_bits, msbs, uval;
@@ -2086,36 +1965,6 @@ FLaC__INLINE FLAC__bool FLAC__bitbuffer_read_unary_unsigned(FLAC__BitBuffer *bb,
 }
 #endif
 
-#ifdef FLAC__SYMMETRIC_RICE
-FLAC__bool FLAC__bitbuffer_read_symmetric_rice_signed(FLAC__BitBuffer *bb, int *val, unsigned parameter, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data)
-{
-       FLAC__uint32 sign = 0, lsbs = 0, msbs = 0;
-
-       FLAC__ASSERT(0 != bb);
-       FLAC__ASSERT(0 != bb->buffer);
-       FLAC__ASSERT(parameter <= 31);
-
-       /* read the unary MSBs and end bit */
-       if(!FLAC__bitbuffer_read_unary_unsigned(bb, &msbs, read_callback, client_data))
-               return false;
-
-       /* read the sign bit */
-       if(!FLAC__bitbuffer_read_bit_to_uint32(bb, &sign, read_callback, client_data))
-               return false;
-
-       /* read the binary LSBs */
-       if(!FLAC__bitbuffer_read_raw_uint32(bb, &lsbs, parameter, read_callback, client_data))
-               return false;
-
-       /* compose the value */
-       *val = (msbs << parameter) | lsbs;
-       if(sign)
-               *val = -(*val);
-
-       return true;
-}
-#endif /* ifdef FLAC__SYMMETRIC_RICE */
-
 FLAC__bool FLAC__bitbuffer_read_rice_signed(FLAC__BitBuffer *bb, int *val, unsigned parameter, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data)
 {
        FLAC__uint32 lsbs = 0, msbs = 0;
index 4ce5957..b1f8bf0 100644 (file)
@@ -105,13 +105,6 @@ unsigned FLAC__bitbuffer_rice_bits(int val, unsigned parameter);
 unsigned FLAC__bitbuffer_golomb_bits_signed(int val, unsigned parameter);
 unsigned FLAC__bitbuffer_golomb_bits_unsigned(unsigned val, unsigned parameter);
 #endif
-#ifdef FLAC__SYMMETRIC_RICE
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed(FLAC__BitBuffer *bb, int val, unsigned parameter);
-#if 0 /* UNUSED */
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed_guarded(FLAC__BitBuffer *bb, int val, unsigned parameter, unsigned max_bits, FLAC__bool *overflow);
-#endif
-FLAC__bool FLAC__bitbuffer_write_symmetric_rice_signed_escape(FLAC__BitBuffer *bb, int val, unsigned parameter);
-#endif
 FLAC__bool FLAC__bitbuffer_write_rice_signed(FLAC__BitBuffer *bb, int val, unsigned parameter);
 #if 0 /* UNUSED */
 FLAC__bool FLAC__bitbuffer_write_rice_signed_guarded(FLAC__BitBuffer *bb, int val, unsigned parameter, unsigned max_bits, FLAC__bool *overflow);
@@ -143,9 +136,6 @@ FLAC__bool FLAC__bitbuffer_read_raw_uint32_little_endian(FLAC__BitBuffer *bb, FL
 FLAC__bool FLAC__bitbuffer_skip_bits_no_crc(FLAC__BitBuffer *bb, unsigned bits, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
 FLAC__bool FLAC__bitbuffer_read_byte_block_aligned_no_crc(FLAC__BitBuffer *bb, FLAC__byte *val, unsigned nvals, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data); /* val may be 0 to skip bytes instead of reading them */ /* WATCHOUT: does not CRC the read data! */
 FLAC__bool FLAC__bitbuffer_read_unary_unsigned(FLAC__BitBuffer *bb, unsigned *val, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data);
-#ifdef FLAC__SYMMETRIC_RICE
-FLAC__bool FLAC__bitbuffer_read_symmetric_rice_signed(FLAC__BitBuffer *bb, int *val, unsigned parameter, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data);
-#endif
 FLAC__bool FLAC__bitbuffer_read_rice_signed(FLAC__BitBuffer *bb, int *val, unsigned parameter, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data);
 FLAC__bool FLAC__bitbuffer_read_rice_signed_block(FLAC__BitBuffer *bb, int vals[], unsigned nvals, unsigned parameter, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data);
 #if 0 /* UNUSED */
index 845ff90..e235dc0 100644 (file)
@@ -2101,18 +2101,10 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigne
                        return false; /* the read_callback_ sets the state for us */
                partitioned_rice_contents->parameters[partition] = rice_parameter;
                if(rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
-#ifdef FLAC__SYMMETRIC_RICE
-                       for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
-                               if(!FLAC__bitbuffer_read_symmetric_rice_signed(decoder->private_->input, &i, rice_parameter, read_callback_, decoder))
-                                       return false; /* the read_callback_ sets the state for us */
-                               residual[sample] = i;
-                       }
-#else
                        u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
                        if(!FLAC__bitbuffer_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter, read_callback_, decoder))
                                return false; /* the read_callback_ sets the state for us */
                        sample += u;
-#endif
                }
                else {
                        if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN, read_callback_, decoder))
index 33debfc..8ae4ba4 100644 (file)
@@ -2235,9 +2235,7 @@ FLAC__bool process_subframe_(
                                                continue; /* don't even try */
                                        rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
 #endif
-#ifndef FLAC__SYMMETRIC_RICE
                                        rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
-#endif
                                        if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
 #ifdef DEBUG_VERBOSE
                                                fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
@@ -2295,9 +2293,7 @@ FLAC__bool process_subframe_(
                                                        if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
                                                                continue; /* don't even try */
                                                        rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
-#ifndef FLAC__SYMMETRIC_RICE
                                                        rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
-#endif
                                                        if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
 #ifdef DEBUG_VERBOSE
                                                                fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
@@ -2895,23 +2891,15 @@ FLAC__bool set_partitioned_rice_(
                for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
 #endif
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                       partition_bits = (2+rice_parameter) * residual_samples;
-#else
                        const unsigned rice_parameter_estimate = rice_parameter-1;
                        partition_bits = (1+rice_parameter) * residual_samples;
-#endif
 #else
                        partition_bits = 0;
 #endif
                        partition_bits += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
                        for(i = 0; i < residual_samples; i++) {
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                               partition_bits += VARIABLE_RICE_BITS(abs_residual[i], rice_parameter);
-#else
                                partition_bits += VARIABLE_RICE_BITS(abs_residual[i], rice_parameter_estimate);
-#endif
 #else
                                partition_bits += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter); /* NOTE: we will need to pass in residual[] in addition to abs_residual[] */
 #endif
@@ -2944,18 +2932,6 @@ FLAC__bool set_partitioned_rice_(
                        for(partition_sample = 0; partition_sample < partition_samples; residual_sample++, partition_sample++)
                                mean += abs_residual[residual_sample];
                        residual_sample = save_residual_sample;
-#ifdef FLAC__SYMMETRIC_RICE
-                       mean += partition_samples >> 1; /* for rounding effect */
-                       mean /= partition_samples;
-
-                       /* calc rice_parameter = floor(log2(mean)) */
-                       rice_parameter = 0;
-                       mean>>=1;
-                       while(mean) {
-                               rice_parameter++;
-                               mean >>= 1;
-                       }
-#else
                        /* we are basically calculating the size in bits of the
                         * average residual magnitude in the partition:
                         *   rice_parameter = floor(log2(mean/partition_samples))
@@ -2966,7 +2942,6 @@ FLAC__bool set_partitioned_rice_(
                         */
                        for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
                                ;
-#endif
                        if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
 #ifdef DEBUG_VERBOSE
                                fprintf(stderr, "clipping rice_parameter (%u -> %u) @3\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
@@ -2995,12 +2970,8 @@ FLAC__bool set_partitioned_rice_(
                        for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
 #endif
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                               partition_bits = (2+rice_parameter) * partition_samples;
-#else
                                const unsigned rice_parameter_estimate = rice_parameter-1;
                                partition_bits = (1+rice_parameter) * partition_samples;
-#endif
 #else
                                partition_bits = 0;
 #endif
@@ -3008,11 +2979,7 @@ FLAC__bool set_partitioned_rice_(
                                save_residual_sample = residual_sample;
                                for(partition_sample = 0; partition_sample < partition_samples; residual_sample++, partition_sample++) {
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                                       partition_bits += VARIABLE_RICE_BITS(abs_residual[residual_sample], rice_parameter);
-#else
                                        partition_bits += VARIABLE_RICE_BITS(abs_residual[residual_sample], rice_parameter_estimate);
-#endif
 #else
                                        partition_bits += FLAC__bitbuffer_rice_bits(residual[residual_sample], rice_parameter); /* NOTE: we will need to pass in residual[] in addition to abs_residual[] */
 #endif
@@ -3104,23 +3071,15 @@ FLAC__bool set_partitioned_rice_with_precompute_(
                for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
 #endif
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                       partition_bits = (2+rice_parameter) * residual_samples;
-#else
                        const unsigned rice_parameter_estimate = rice_parameter-1;
                        partition_bits = (1+rice_parameter) * residual_samples;
-#endif
 #else
                        partition_bits = 0;
 #endif
                        partition_bits += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
                        for(i = 0; i < residual_samples; i++) {
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                               partition_bits += VARIABLE_RICE_BITS(abs_residual[i], rice_parameter);
-#else
                                partition_bits += VARIABLE_RICE_BITS(abs_residual[i], rice_parameter_estimate);
-#endif
 #else
                                partition_bits += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter); /* NOTE: we will need to pass in residual[] instead of abs_residual[] */
 #endif
@@ -3157,18 +3116,6 @@ FLAC__bool set_partitioned_rice_with_precompute_(
                                        partition_samples -= predictor_order;
                        }
                        mean = abs_residual_partition_sums[partition];
-#ifdef FLAC__SYMMETRIC_RICE
-                       mean += partition_samples >> 1; /* for rounding effect */
-                       mean /= partition_samples;
-
-                       /* calc rice_parameter = floor(log2(mean)) */
-                       rice_parameter = 0;
-                       mean>>=1;
-                       while(mean) {
-                               rice_parameter++;
-                               mean >>= 1;
-                       }
-#else
                        /* we are basically calculating the size in bits of the
                         * average residual magnitude in the partition:
                         *   rice_parameter = floor(log2(mean/partition_samples))
@@ -3179,7 +3126,6 @@ FLAC__bool set_partitioned_rice_with_precompute_(
                         */
                        for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
                                ;
-#endif
                        if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
 #ifdef DEBUG_VERBOSE
                                fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
@@ -3208,12 +3154,8 @@ FLAC__bool set_partitioned_rice_with_precompute_(
                        for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
 #endif
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                               partition_bits = (2+rice_parameter) * partition_samples;
-#else
                                const unsigned rice_parameter_estimate = rice_parameter-1;
                                partition_bits = (1+rice_parameter) * partition_samples;
-#endif
 #else
                                partition_bits = 0;
 #endif
@@ -3221,11 +3163,7 @@ FLAC__bool set_partitioned_rice_with_precompute_(
                                save_residual_sample = residual_sample;
                                for(partition_sample = 0; partition_sample < partition_samples; residual_sample++, partition_sample++) {
 #ifdef VARIABLE_RICE_BITS
-#ifdef FLAC__SYMMETRIC_RICE
-                                       partition_bits += VARIABLE_RICE_BITS(abs_residual[residual_sample], rice_parameter);
-#else
                                        partition_bits += VARIABLE_RICE_BITS(abs_residual[residual_sample], rice_parameter_estimate);
-#endif
 #else
                                        partition_bits += FLAC__bitbuffer_rice_bits(residual[residual_sample], rice_parameter); /* NOTE: we will need to pass in residual[] instead of abs_residual[] */
 #endif
index 36bf952..e568808 100644 (file)
@@ -443,13 +443,8 @@ FLAC__bool add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const FLAC__int32
                        return false;
                if(rice_parameters[0] < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
                        for(i = 0; i < residual_samples; i++) {
-#ifdef FLAC__SYMMETRIC_RICE
-                               if(!FLAC__bitbuffer_write_symmetric_rice_signed(bb, residual[i], rice_parameters[0]))
-                                       return false;
-#else
                                if(!FLAC__bitbuffer_write_rice_signed(bb, residual[i], rice_parameters[0]))
                                        return false;
-#endif
                        }
                }
                else {
@@ -475,13 +470,8 @@ FLAC__bool add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const FLAC__int32
                        k += partition_samples;
                        if(rice_parameters[i] < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
                                for(j = k_last; j < k; j++) {
-#ifdef FLAC__SYMMETRIC_RICE
-                                       if(!FLAC__bitbuffer_write_symmetric_rice_signed(bb, residual[j], rice_parameters[i]))
-                                               return false;
-#else
                                        if(!FLAC__bitbuffer_write_rice_signed(bb, residual[j], rice_parameters[i]))
                                                return false;
-#endif
                                }
                        }
                        else {