move folded rice stuff sideways, re-add symmetric rice in prep for escape codes

This commit is contained in:
Josh Coalson 2001-03-17 01:07:00 +00:00
parent 4f569c6386
commit b9433f9bcf
3 changed files with 59 additions and 3 deletions

View File

@ -3,7 +3,7 @@
# #
LIB_NAME = libFLAC LIB_NAME = libFLAC
INCLUDES = -I./include -I../../include INCLUDES = -I./include -I../../include -DFOLDED_RICE
DEBUG_CFLAGS = -DFLAC_OVERFLOW_DETECT DEBUG_CFLAGS = -DFLAC_OVERFLOW_DETECT
OBJS = \ OBJS = \

View File

@ -848,7 +848,9 @@ bool encoder_process_subframe_(FLAC__Encoder *encoder, unsigned max_partition_or
if(fixed_residual_bits_per_sample[fixed_order] >= (real)bits_per_sample) if(fixed_residual_bits_per_sample[fixed_order] >= (real)bits_per_sample)
continue; /* don't even try */ continue; /* don't even try */
rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */ rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
#ifdef FOLDED_RICE
rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */ rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
#endif
if(rice_parameter >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)) if(rice_parameter >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN))
rice_parameter = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN) - 1; rice_parameter = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN) - 1;
_candidate_bits = encoder_evaluate_fixed_subframe_(integer_signal, residual[!_best_subframe], encoder->guts->abs_residual, frame_header->blocksize, bits_per_sample, fixed_order, rice_parameter, max_partition_order, subframe[!_best_subframe]); _candidate_bits = encoder_evaluate_fixed_subframe_(integer_signal, residual[!_best_subframe], encoder->guts->abs_residual, frame_header->blocksize, bits_per_sample, fixed_order, rice_parameter, max_partition_order, subframe[!_best_subframe]);
@ -888,7 +890,9 @@ bool encoder_process_subframe_(FLAC__Encoder *encoder, unsigned max_partition_or
if(lpc_residual_bits_per_sample >= (real)bits_per_sample) if(lpc_residual_bits_per_sample >= (real)bits_per_sample)
continue; /* don't even try */ 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 */ rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
#ifdef FOLDED_RICE
rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */ rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
#endif
if(rice_parameter >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)) if(rice_parameter >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN))
rice_parameter = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN) - 1; rice_parameter = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN) - 1;
for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) { for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
@ -1047,7 +1051,12 @@ unsigned encoder_find_best_partition_order_(const int32 residual[], uint32 abs_r
#ifdef ESTIMATE_RICE_BITS #ifdef ESTIMATE_RICE_BITS
#undef ESTIMATE_RICE_BITS #undef ESTIMATE_RICE_BITS
#endif #endif
#ifdef FOLDED_RICE
#define ESTIMATE_RICE_BITS(value, parameter) ((value) >> (parameter)) #define ESTIMATE_RICE_BITS(value, parameter) ((value) >> (parameter))
#else
/* symmetric Rice coding ala Shorten */
#define ESTIMATE_RICE_BITS(value, parameter) ((value) >> (parameter))
#endif
bool encoder_set_partitioned_rice_(const uint32 abs_residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameter, const unsigned partition_order, unsigned parameters[], unsigned *bits) bool encoder_set_partitioned_rice_(const uint32 abs_residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameter, const unsigned partition_order, unsigned parameters[], unsigned *bits)
{ {
@ -1056,14 +1065,24 @@ bool encoder_set_partitioned_rice_(const uint32 abs_residual[], const unsigned r
if(partition_order == 0) { if(partition_order == 0) {
unsigned i; unsigned i;
#ifdef ESTIMATE_RICE_BITS #ifdef ESTIMATE_RICE_BITS
#ifdef FOLDED_RICE
const unsigned rice_parameter_estimate = rice_parameter-1; const unsigned rice_parameter_estimate = rice_parameter-1;
bits_ += (1+rice_parameter) * residual_samples; bits_ += (2+rice_parameter) * residual_samples;
#else
/* symmetric Rice coding ala Shorten */
bits_ += (2+rice_parameter) * residual_samples;
#endif
#endif #endif
parameters[0] = rice_parameter; parameters[0] = rice_parameter;
bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
for(i = 0; i < residual_samples; i++) for(i = 0; i < residual_samples; i++)
#ifdef ESTIMATE_RICE_BITS #ifdef ESTIMATE_RICE_BITS
#ifdef FOLDED_RICE
bits_ += ESTIMATE_RICE_BITS(abs_residual[i], rice_parameter_estimate); bits_ += ESTIMATE_RICE_BITS(abs_residual[i], rice_parameter_estimate);
#else
/* symmetric Rice coding ala Shorten */
bits_ += ESTIMATE_RICE_BITS(abs_residual[i], rice_parameter);
#endif
#else #else
bits_ += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter); bits_ += FLAC__bitbuffer_rice_bits(residual[i], rice_parameter);
#endif #endif
@ -1084,23 +1103,48 @@ bool encoder_set_partitioned_rice_(const uint32 abs_residual[], const unsigned r
for(j = 0; j < partition_samples; j++, k++) for(j = 0; j < partition_samples; j++, k++)
mean += abs_residual[k]; mean += abs_residual[k];
mean /= partition_samples; mean /= partition_samples;
#ifdef ESTIMATE_RICE_BITS
#ifdef FOLDED_RICE
/* calc parameter = floor(log2(mean)) + 1 */ /* calc parameter = floor(log2(mean)) + 1 */
parameter = 0; parameter = 0;
while(mean) { while(mean) {
parameter++; parameter++;
mean >>= 1; mean >>= 1;
} }
#else
/* symmetric Rice coding ala Shorten */
/* calc parameter = floor(log2(mean)) + 1 */
parameter = 0;
mean>>=1;
while(mean) {
parameter++;
mean >>= 1;
}
#endif
#else
#error
#endif
if(parameter > max_parameter) if(parameter > max_parameter)
parameter = max_parameter; parameter = max_parameter;
parameters[i] = parameter; parameters[i] = parameter;
bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; bits_ += FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
#ifdef ESTIMATE_RICE_BITS #ifdef ESTIMATE_RICE_BITS
bits_ += (1+parameter) * partition_samples; #ifdef FOLDED_RICE
bits_ += (2+parameter) * partition_samples;
--parameter; --parameter;
#else
/* symmetric Rice coding ala Shorten */
bits_ += (2+parameter) * partition_samples;
#endif
#endif #endif
for(j = k_last; j < k; j++) for(j = k_last; j < k; j++)
#ifdef ESTIMATE_RICE_BITS #ifdef ESTIMATE_RICE_BITS
#ifdef FOLDED_RICE
bits_ += ESTIMATE_RICE_BITS(abs_residual[j], parameter); bits_ += ESTIMATE_RICE_BITS(abs_residual[j], parameter);
#else
/* symmetric Rice coding ala Shorten */
bits_ += ESTIMATE_RICE_BITS(abs_residual[j], parameter);
#endif
#else #else
bits_ += FLAC__bitbuffer_rice_bits(residual[j], parameter); bits_ += FLAC__bitbuffer_rice_bits(residual[j], parameter);
#endif #endif

View File

@ -326,8 +326,14 @@ bool subframe_add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const int32 re
if(!FLAC__bitbuffer_write_raw_uint32(bb, rice_parameters[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)) if(!FLAC__bitbuffer_write_raw_uint32(bb, rice_parameters[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN))
return false; return false;
for(i = 0; i < residual_samples; i++) { for(i = 0; i < residual_samples; i++) {
#ifdef FOLDED_RICE
if(!FLAC__bitbuffer_write_rice_signed(bb, residual[i], rice_parameters[0])) if(!FLAC__bitbuffer_write_rice_signed(bb, residual[i], rice_parameters[0]))
return false; return false;
#else
/* symmetric Rice coding ala Shorten */
if(!FLAC__bitbuffer_write_symmetric_rice_signed(bb, residual[i], rice_parameters[0]))
return false;
#endif
} }
return true; return true;
} }
@ -342,8 +348,14 @@ bool subframe_add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const int32 re
partition_samples -= predictor_order; partition_samples -= predictor_order;
k += partition_samples; k += partition_samples;
for(j = k_last; j < k; j++) { for(j = k_last; j < k; j++) {
#ifdef FOLDED_RICE
if(!FLAC__bitbuffer_write_rice_signed(bb, residual[j], rice_parameters[i])) if(!FLAC__bitbuffer_write_rice_signed(bb, residual[j], rice_parameters[i]))
return false; return false;
#else
/* symmetric Rice coding ala Shorten */
if(!FLAC__bitbuffer_write_symmetric_rice_signed(bb, residual[j], rice_parameters[i]))
return false;
#endif
} }
k_last = k; k_last = k;
} }