add ESTIMATE_RICE_BITS for speed
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 19 Jan 2001 20:11:59 +0000 (20:11 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 19 Jan 2001 20:11:59 +0000 (20:11 +0000)
src/libFLAC/encoder.c

index c58bf7c..7c415d8 100644 (file)
 #endif
 #define max(x,y) ((x)>(y)?(x):(y))
 
 #endif
 #define max(x,y) ((x)>(y)?(x):(y))
 
+#ifdef ESTIMATE_RICE_BITS
+#undef ESTIMATE_RICE_BITS
+#endif
+#define ESTIMATE_RICE_BITS(value, parameter) (2 + (parameter) + (((unsigned)((value) < 0? -(value) : (value))) >> (parameter)))
+
 typedef struct FLAC__EncoderPrivate {
        unsigned input_capacity;                    /* current size (in samples) of the signal and residual buffers */
        int32 *integer_signal[FLAC__MAX_CHANNELS];  /* the integer version of the input signal */
 typedef struct FLAC__EncoderPrivate {
        unsigned input_capacity;                    /* current size (in samples) of the signal and residual buffers */
        int32 *integer_signal[FLAC__MAX_CHANNELS];  /* the integer version of the input signal */
@@ -903,8 +908,15 @@ bool encoder_set_partitioned_rice_(const int32 residual[], const unsigned residu
                unsigned i;
                parameters[0] = rice_parameter;
                bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
                unsigned i;
                parameters[0] = rice_parameter;
                bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
+#ifdef ESTIMATE_RICE_BITS
+               --rice_parameter;
+#endif
                for(i = 0; i < residual_samples; i++)
                for(i = 0; i < residual_samples; i++)
+#ifdef ESTIMATE_RICE_BITS
+                       bits_ += ESTIMATE_RICE_BITS(residual[i], rice_parameter);
+#else
                        bits_ += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter);
                        bits_ += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter);
+#endif
        }
        else {
                unsigned i, j, k = 0, k_last = 0;
        }
        else {
                unsigned i, j, k = 0, k_last = 0;
@@ -932,8 +944,15 @@ bool encoder_set_partitioned_rice_(const int32 residual[], const unsigned residu
                                parameter = max_parameter;
                        parameters[i] = parameter;
                        bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
                                parameter = max_parameter;
                        parameters[i] = parameter;
                        bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
+#ifdef ESTIMATE_RICE_BITS
+                       --parameter;
+#endif
                        for(j = k_last; j < k; j++)
                        for(j = k_last; j < k; j++)
+#ifdef ESTIMATE_RICE_BITS
+                               bits_ += ESTIMATE_RICE_BITS(residual[j], parameter);
+#else
                                bits_ += FLAC__bitbuffer_rice_bits(residual[j], parameter);
                                bits_ += FLAC__bitbuffer_rice_bits(residual[j], parameter);
+#endif
                        k_last = k;
                }
        }
                        k_last = k;
                }
        }