minor formatting
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index cc1b544..485c43d 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -74,30 +74,220 @@
static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples);
static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame);
static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame);
-static FLAC__bool process_subframe_(FLAC__StreamEncoder *encoder, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool verbatim_only, const FLAC__FrameHeader *frame_header, unsigned subframe_bps, const FLAC__int32 integer_signal[], const FLAC__real real_signal[], FLAC__Subframe *subframe[2], FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2], FLAC__int32 *residual[2], unsigned *best_subframe, unsigned *best_bits);
-static FLAC__bool add_subframe_(FLAC__StreamEncoder *encoder, const FLAC__FrameHeader *frame_header, unsigned subframe_bps, const FLAC__Subframe *subframe, FLAC__BitBuffer *frame);
-static unsigned evaluate_constant_subframe_(const FLAC__int32 signal, unsigned subframe_bps, FLAC__Subframe *subframe);
-static unsigned evaluate_fixed_subframe_(FLAC__StreamEncoder *encoder, const FLAC__int32 signal[], FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], unsigned blocksize, unsigned subframe_bps, unsigned order, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__Subframe *subframe, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents);
-static unsigned evaluate_lpc_subframe_(FLAC__StreamEncoder *encoder, const FLAC__int32 signal[], FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], const FLAC__real lp_coeff[], unsigned blocksize, unsigned subframe_bps, unsigned order, unsigned qlp_coeff_precision, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__Subframe *subframe, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents);
-static unsigned evaluate_verbatim_subframe_(const FLAC__int32 signal[], unsigned blocksize, unsigned subframe_bps, FLAC__Subframe *subframe);
-static unsigned find_best_partition_order_(struct FLAC__StreamEncoderPrivate *private_, const FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], unsigned residual_samples, unsigned predictor_order, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice);
-static void precompute_partition_info_sums_(const FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order);
-static void precompute_partition_info_escapes_(const FLAC__int32 residual[], unsigned raw_bits_per_partition[], unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order);
+
+static FLAC__bool process_subframe_(
+ FLAC__StreamEncoder *encoder,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool verbatim_only,
+ const FLAC__FrameHeader *frame_header,
+ unsigned subframe_bps,
+ const FLAC__int32 integer_signal[],
+ const FLAC__real real_signal[],
+ FLAC__Subframe *subframe[2],
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
+ FLAC__int32 *residual[2],
+ unsigned *best_subframe,
+ unsigned *best_bits
+);
+
+static FLAC__bool add_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__FrameHeader *frame_header,
+ unsigned subframe_bps,
+ const FLAC__Subframe *subframe,
+ FLAC__BitBuffer *frame
+);
+
+static unsigned evaluate_constant_subframe_(
+ const FLAC__int32 signal,
+ unsigned subframe_bps,
+ FLAC__Subframe *subframe
+);
+
+static unsigned evaluate_fixed_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__int32 signal[],
+ FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ unsigned order,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__Subframe *subframe,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
+);
+
+static unsigned evaluate_lpc_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__int32 signal[],
+ FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ const FLAC__real lp_coeff[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ unsigned order,
+ unsigned qlp_coeff_precision,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__Subframe *subframe,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
+);
+
+static unsigned evaluate_verbatim_subframe_(
+ const FLAC__int32 signal[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ FLAC__Subframe *subframe
+);
+
+static unsigned find_best_partition_order_(
+ struct FLAC__StreamEncoderPrivate *private_,
+ const FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice
+);
+
+static void precompute_partition_info_sums_(
+ const FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned min_partition_order,
+ unsigned max_partition_order
+);
+
+static void precompute_partition_info_escapes_(
+ const FLAC__int32 residual[],
+ unsigned raw_bits_per_partition[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned min_partition_order,
+ unsigned max_partition_order
+);
+
#ifdef DONT_ESTIMATE_RICE_BITS
-static FLAC__bool set_partitioned_rice_(const FLAC__uint32 abs_residual[], const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits);
-static FLAC__bool set_partitioned_rice_with_precompute_(const FLAC__int32 residual[], const FLAC__uint64 abs_residual_partition_sums[], const unsigned raw_bits_per_partition[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, const FLAC__bool search_for_escapes, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits);
+static FLAC__bool set_partitioned_rice_(
+ const FLAC__uint32 abs_residual[],
+ const FLAC__int32 residual[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+);
+
+static FLAC__bool set_partitioned_rice_with_precompute_(
+ const FLAC__int32 residual[],
+ const FLAC__uint64 abs_residual_partition_sums[],
+ const unsigned raw_bits_per_partition[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ const FLAC__bool search_for_escapes,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+);
#else
-static FLAC__bool set_partitioned_rice_(const FLAC__uint32 abs_residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits);
-static FLAC__bool set_partitioned_rice_with_precompute_(const FLAC__uint32 abs_residual[], const FLAC__uint64 abs_residual_partition_sums[], const unsigned raw_bits_per_partition[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, const FLAC__bool search_for_escapes, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits);
+static FLAC__bool set_partitioned_rice_(
+ const FLAC__uint32 abs_residual[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+);
+
+static FLAC__bool set_partitioned_rice_with_precompute_(
+ const FLAC__uint32 abs_residual[],
+ const FLAC__uint64 abs_residual_partition_sums[],
+ const unsigned raw_bits_per_partition[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ const FLAC__bool search_for_escapes,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+);
#endif
+
static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
+
/* verify-related routines: */
-static void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples);
-static void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples);
-static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
-static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
-static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
-static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+static void append_to_verify_fifo_(
+ verify_input_fifo *fifo,
+ const FLAC__int32 * const input[],
+ unsigned input_offset,
+ unsigned channels,
+ unsigned wide_samples
+);
+
+static void append_to_verify_fifo_interleaved_(
+ verify_input_fifo *fifo,
+ const FLAC__int32 input[],
+ unsigned input_offset,
+ unsigned channels,
+ unsigned wide_samples
+);
+
+static FLAC__StreamDecoderReadStatus verify_read_callback_(
+ const FLAC__StreamDecoder *decoder,
+ FLAC__byte buffer[],
+ unsigned *bytes,
+ void *client_data
+);
+
+static FLAC__StreamDecoderWriteStatus verify_write_callback_(
+ const FLAC__StreamDecoder *decoder,
+ const FLAC__Frame *frame,
+ const FLAC__int32 * const buffer[],
+ void *client_data
+);
+
+static void verify_metadata_callback_(
+ const FLAC__StreamDecoder *decoder,
+ const FLAC__StreamMetadata *metadata,
+ void *client_data
+);
+
+static void verify_error_callback_(
+ const FLAC__StreamDecoder *decoder,
+ FLAC__StreamDecoderErrorStatus status,
+ void *client_data
+);
+
/***********************************************************************
*
@@ -1448,7 +1638,24 @@
*/
if(do_independent) {
for(channel = 0; channel < encoder->protected_->channels; channel++) {
- if(!process_subframe_(encoder, min_partition_order, max_partition_order, precompute_partition_sums, false, &frame_header, encoder->private_->subframe_bps[channel], encoder->private_->integer_signal[channel], encoder->private_->real_signal[channel], encoder->private_->subframe_workspace_ptr[channel], encoder->private_->partitioned_rice_contents_workspace_ptr[channel], encoder->private_->residual_workspace[channel], encoder->private_->best_subframe+channel, encoder->private_->best_subframe_bits+channel))
+ if(!
+ process_subframe_(
+ encoder,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ false,
+ &frame_header,
+ encoder->private_->subframe_bps[channel],
+ encoder->private_->integer_signal[channel],
+ encoder->private_->real_signal[channel],
+ encoder->private_->subframe_workspace_ptr[channel],
+ encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
+ encoder->private_->residual_workspace[channel],
+ encoder->private_->best_subframe+channel,
+ encoder->private_->best_subframe_bits+channel
+ )
+ )
return false;
}
}
@@ -1460,7 +1667,24 @@
FLAC__ASSERT(encoder->protected_->channels == 2);
for(channel = 0; channel < 2; channel++) {
- if(!process_subframe_(encoder, min_partition_order, max_partition_order, precompute_partition_sums, false, &frame_header, encoder->private_->subframe_bps_mid_side[channel], encoder->private_->integer_signal_mid_side[channel], encoder->private_->real_signal_mid_side[channel], encoder->private_->subframe_workspace_ptr_mid_side[channel], encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel], encoder->private_->residual_workspace_mid_side[channel], encoder->private_->best_subframe_mid_side+channel, encoder->private_->best_subframe_bits_mid_side+channel))
+ if(!
+ process_subframe_(
+ encoder,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ false,
+ &frame_header,
+ encoder->private_->subframe_bps_mid_side[channel],
+ encoder->private_->integer_signal_mid_side[channel],
+ encoder->private_->real_signal_mid_side[channel],
+ encoder->private_->subframe_workspace_ptr_mid_side[channel],
+ encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
+ encoder->private_->residual_workspace_mid_side[channel],
+ encoder->private_->best_subframe_mid_side+channel,
+ encoder->private_->best_subframe_bits_mid_side+channel
+ )
+ )
return false;
}
}
@@ -1579,7 +1803,22 @@
return true;
}
-FLAC__bool process_subframe_(FLAC__StreamEncoder *encoder, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool verbatim_only, const FLAC__FrameHeader *frame_header, unsigned subframe_bps, const FLAC__int32 integer_signal[], const FLAC__real real_signal[], FLAC__Subframe *subframe[2], FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2], FLAC__int32 *residual[2], unsigned *best_subframe, unsigned *best_bits)
+FLAC__bool process_subframe_(
+ FLAC__StreamEncoder *encoder,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool verbatim_only,
+ const FLAC__FrameHeader *frame_header,
+ unsigned subframe_bps,
+ const FLAC__int32 integer_signal[],
+ const FLAC__real real_signal[],
+ FLAC__Subframe *subframe[2],
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
+ FLAC__int32 *residual[2],
+ unsigned *best_subframe,
+ unsigned *best_bits
+)
{
FLAC__real fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
FLAC__real lpc_residual_bits_per_sample;
@@ -1638,7 +1877,26 @@
#endif
rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
}
- _candidate_bits = evaluate_fixed_subframe_(encoder, integer_signal, residual[!_best_subframe], encoder->private_->abs_residual, encoder->private_->abs_residual_partition_sums, encoder->private_->raw_bits_per_partition, frame_header->blocksize, subframe_bps, fixed_order, rice_parameter, min_partition_order, max_partition_order, precompute_partition_sums, encoder->protected_->do_escape_coding, encoder->protected_->rice_parameter_search_dist, subframe[!_best_subframe], partitioned_rice_contents[!_best_subframe]);
+ _candidate_bits =
+ evaluate_fixed_subframe_(
+ encoder,
+ integer_signal,
+ residual[!_best_subframe],
+ encoder->private_->abs_residual,
+ encoder->private_->abs_residual_partition_sums,
+ encoder->private_->raw_bits_per_partition,
+ frame_header->blocksize,
+ subframe_bps,
+ fixed_order,
+ rice_parameter,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ encoder->protected_->do_escape_coding,
+ encoder->protected_->rice_parameter_search_dist,
+ subframe[!_best_subframe],
+ partitioned_rice_contents[!_best_subframe]
+ );
if(_candidate_bits < _best_bits) {
_best_subframe = !_best_subframe;
_best_bits = _candidate_bits;
@@ -1685,7 +1943,28 @@
rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
}
for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
- _candidate_bits = evaluate_lpc_subframe_(encoder, integer_signal, residual[!_best_subframe], encoder->private_->abs_residual, encoder->private_->abs_residual_partition_sums, encoder->private_->raw_bits_per_partition, encoder->private_->lp_coeff[lpc_order-1], frame_header->blocksize, subframe_bps, lpc_order, qlp_coeff_precision, rice_parameter, min_partition_order, max_partition_order, precompute_partition_sums, encoder->protected_->do_escape_coding, encoder->protected_->rice_parameter_search_dist, subframe[!_best_subframe], partitioned_rice_contents[!_best_subframe]);
+ _candidate_bits =
+ evaluate_lpc_subframe_(
+ encoder,
+ integer_signal,
+ residual[!_best_subframe],
+ encoder->private_->abs_residual,
+ encoder->private_->abs_residual_partition_sums,
+ encoder->private_->raw_bits_per_partition,
+ encoder->private_->lp_coeff[lpc_order-1],
+ frame_header->blocksize,
+ subframe_bps,
+ lpc_order,
+ qlp_coeff_precision,
+ rice_parameter,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ encoder->protected_->do_escape_coding,
+ encoder->protected_->rice_parameter_search_dist,
+ subframe[!_best_subframe],
+ partitioned_rice_contents[!_best_subframe]
+ );
if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
if(_candidate_bits < _best_bits) {
_best_subframe = !_best_subframe;
@@ -1706,7 +1985,13 @@
return true;
}
-FLAC__bool add_subframe_(FLAC__StreamEncoder *encoder, const FLAC__FrameHeader *frame_header, unsigned subframe_bps, const FLAC__Subframe *subframe, FLAC__BitBuffer *frame)
+FLAC__bool add_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__FrameHeader *frame_header,
+ unsigned subframe_bps,
+ const FLAC__Subframe *subframe,
+ FLAC__BitBuffer *frame
+)
{
switch(subframe->type) {
case FLAC__SUBFRAME_TYPE_CONSTANT:
@@ -1740,7 +2025,11 @@
return true;
}
-unsigned evaluate_constant_subframe_(const FLAC__int32 signal, unsigned subframe_bps, FLAC__Subframe *subframe)
+unsigned evaluate_constant_subframe_(
+ const FLAC__int32 signal,
+ unsigned subframe_bps,
+ FLAC__Subframe *subframe
+)
{
subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
subframe->data.constant.value = signal;
@@ -1748,7 +2037,25 @@
return FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe_bps;
}
-unsigned evaluate_fixed_subframe_(FLAC__StreamEncoder *encoder, const FLAC__int32 signal[], FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], unsigned blocksize, unsigned subframe_bps, unsigned order, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__Subframe *subframe, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents)
+unsigned evaluate_fixed_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__int32 signal[],
+ FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ unsigned order,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__Subframe *subframe,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
+)
{
unsigned i, residual_bits;
const unsigned residual_samples = blocksize - order;
@@ -1761,7 +2068,23 @@
subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
subframe->data.fixed.residual = residual;
- residual_bits = find_best_partition_order_(encoder->private_, residual, abs_residual, abs_residual_partition_sums, raw_bits_per_partition, residual_samples, order, rice_parameter, min_partition_order, max_partition_order, precompute_partition_sums, do_escape_coding, rice_parameter_search_dist, &subframe->data.fixed.entropy_coding_method.data.partitioned_rice);
+ residual_bits =
+ find_best_partition_order_(
+ encoder->private_,
+ residual,
+ abs_residual,
+ abs_residual_partition_sums,
+ raw_bits_per_partition,
+ residual_samples,
+ order,
+ rice_parameter,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ do_escape_coding,
+ rice_parameter_search_dist,
+ &subframe->data.fixed.entropy_coding_method.data.partitioned_rice
+ );
subframe->data.fixed.order = order;
for(i = 0; i < order; i++)
@@ -1770,7 +2093,27 @@
return FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + (order * subframe_bps) + residual_bits;
}
-unsigned evaluate_lpc_subframe_(FLAC__StreamEncoder *encoder, const FLAC__int32 signal[], FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], const FLAC__real lp_coeff[], unsigned blocksize, unsigned subframe_bps, unsigned order, unsigned qlp_coeff_precision, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__Subframe *subframe, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents)
+unsigned evaluate_lpc_subframe_(
+ FLAC__StreamEncoder *encoder,
+ const FLAC__int32 signal[],
+ FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ const FLAC__real lp_coeff[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ unsigned order,
+ unsigned qlp_coeff_precision,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__Subframe *subframe,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
+)
{
FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
unsigned i, residual_bits;
@@ -1792,7 +2135,23 @@
subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
subframe->data.lpc.residual = residual;
- residual_bits = find_best_partition_order_(encoder->private_, residual, abs_residual, abs_residual_partition_sums, raw_bits_per_partition, residual_samples, order, rice_parameter, min_partition_order, max_partition_order, precompute_partition_sums, do_escape_coding, rice_parameter_search_dist, &subframe->data.fixed.entropy_coding_method.data.partitioned_rice);
+ residual_bits =
+ find_best_partition_order_(
+ encoder->private_,
+ residual,
+ abs_residual,
+ abs_residual_partition_sums,
+ raw_bits_per_partition,
+ residual_samples,
+ order,
+ rice_parameter,
+ min_partition_order,
+ max_partition_order,
+ precompute_partition_sums,
+ do_escape_coding,
+ rice_parameter_search_dist,
+ &subframe->data.fixed.entropy_coding_method.data.partitioned_rice
+ );
subframe->data.lpc.order = order;
subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
@@ -1804,7 +2163,12 @@
return FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)) + residual_bits;
}
-unsigned evaluate_verbatim_subframe_(const FLAC__int32 signal[], unsigned blocksize, unsigned subframe_bps, FLAC__Subframe *subframe)
+unsigned evaluate_verbatim_subframe_(
+ const FLAC__int32 signal[],
+ unsigned blocksize,
+ unsigned subframe_bps,
+ FLAC__Subframe *subframe
+)
{
subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
@@ -1813,7 +2177,22 @@
return FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + (blocksize * subframe_bps);
}
-unsigned find_best_partition_order_(FLAC__StreamEncoderPrivate *private_, const FLAC__int32 residual[], FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned raw_bits_per_partition[], unsigned residual_samples, unsigned predictor_order, unsigned rice_parameter, unsigned min_partition_order, unsigned max_partition_order, FLAC__bool precompute_partition_sums, FLAC__bool do_escape_coding, unsigned rice_parameter_search_dist, FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice)
+unsigned find_best_partition_order_(
+ FLAC__StreamEncoderPrivate *private_,
+ const FLAC__int32 residual[],
+ FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned raw_bits_per_partition[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned rice_parameter,
+ unsigned min_partition_order,
+ unsigned max_partition_order,
+ FLAC__bool precompute_partition_sums,
+ FLAC__bool do_escape_coding,
+ unsigned rice_parameter_search_dist,
+ FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice
+)
{
FLAC__int32 r;
unsigned residual_bits, best_residual_bits = 0;
@@ -1841,9 +2220,37 @@
for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
#ifdef DONT_ESTIMATE_RICE_BITS
- if(!set_partitioned_rice_with_precompute_(residual, abs_residual_partition_sums+sum, raw_bits_per_partition+sum, residual_samples, predictor_order, rice_parameter, rice_parameter_search_dist, (unsigned)partition_order, do_escape_coding, &private_->partitioned_rice_contents_extra[!best_parameters_index], &residual_bits))
+ if(!
+ set_partitioned_rice_with_precompute_(
+ residual,
+ abs_residual_partition_sums+sum,
+ raw_bits_per_partition+sum,
+ residual_samples,
+ predictor_order,
+ rice_parameter,
+ rice_parameter_search_dist,
+ (unsigned)partition_order,
+ do_escape_coding,
+ &private_->partitioned_rice_contents_extra[!best_parameters_index],
+ &residual_bits
+ )
+ )
#else
- if(!set_partitioned_rice_with_precompute_(abs_residual, abs_residual_partition_sums+sum, raw_bits_per_partition+sum, residual_samples, predictor_order, rice_parameter, rice_parameter_search_dist, (unsigned)partition_order, do_escape_coding, &private_->partitioned_rice_contents_extra[!best_parameters_index], &residual_bits))
+ if(!
+ set_partitioned_rice_with_precompute_(
+ abs_residual,
+ abs_residual_partition_sums+sum,
+ raw_bits_per_partition+sum,
+ residual_samples,
+ predictor_order,
+ rice_parameter,
+ rice_parameter_search_dist,
+ (unsigned)partition_order,
+ do_escape_coding,
+ &private_->partitioned_rice_contents_extra[!best_parameters_index],
+ &residual_bits
+ )
+ )
#endif
{
FLAC__ASSERT(best_residual_bits != 0);
@@ -1861,9 +2268,32 @@
unsigned partition_order;
for(partition_order = min_partition_order; partition_order <= max_partition_order; partition_order++) {
#ifdef DONT_ESTIMATE_RICE_BITS
- if(!set_partitioned_rice_(abs_residual, residual, residual_samples, predictor_order, rice_parameter, rice_parameter_search_dist, partition_order, &private_->partitioned_rice_contents_extra[!best_parameters_index], &residual_bits))
+ if(!
+ set_partitioned_rice_(
+ abs_residual,
+ residual,
+ residual_samples,
+ predictor_order,
+ rice_parameter,
+ rice_parameter_search_dist,
+ partition_order,
+ &private_->partitioned_rice_contents_extra[!best_parameters_index],
+ &residual_bits
+ )
+ )
#else
- if(!set_partitioned_rice_(abs_residual, residual_samples, predictor_order, rice_parameter, rice_parameter_search_dist, partition_order, &private_->partitioned_rice_contents_extra[!best_parameters_index], &residual_bits))
+ if(!
+ set_partitioned_rice_(
+ abs_residual,
+ residual_samples,
+ predictor_order,
+ rice_parameter,
+ rice_parameter_search_dist,
+ partition_order,
+ &private_->partitioned_rice_contents_extra[!best_parameters_index],
+ &residual_bits
+ )
+ )
#endif
{
FLAC__ASSERT(best_residual_bits != 0);
@@ -1891,7 +2321,14 @@
return best_residual_bits;
}
-void precompute_partition_info_sums_(const FLAC__uint32 abs_residual[], FLAC__uint64 abs_residual_partition_sums[], unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order)
+void precompute_partition_info_sums_(
+ const FLAC__uint32 abs_residual[],
+ FLAC__uint64 abs_residual_partition_sums[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned min_partition_order,
+ unsigned max_partition_order
+)
{
int partition_order;
unsigned from_partition, to_partition = 0;
@@ -1938,7 +2375,14 @@
}
}
-void precompute_partition_info_escapes_(const FLAC__int32 residual[], unsigned raw_bits_per_partition[], unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order)
+void precompute_partition_info_escapes_(
+ const FLAC__int32 residual[],
+ unsigned raw_bits_per_partition[],
+ unsigned residual_samples,
+ unsigned predictor_order,
+ unsigned min_partition_order,
+ unsigned max_partition_order
+)
{
int partition_order;
unsigned from_partition, to_partition = 0;
@@ -1998,9 +2442,28 @@
#endif
#ifdef DONT_ESTIMATE_RICE_BITS
-FLAC__bool set_partitioned_rice_(const FLAC__uint32 abs_residual[], const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits)
+FLAC__bool set_partitioned_rice_(
+ const FLAC__uint32 abs_residual[],
+ const FLAC__int32 residual[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+)
#else
-FLAC__bool set_partitioned_rice_(const FLAC__uint32 abs_residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits)
+FLAC__bool set_partitioned_rice_(
+ const FLAC__uint32 abs_residual[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+)
#endif
{
unsigned rice_parameter, partition_bits;
@@ -2174,9 +2637,33 @@
}
#ifdef DONT_ESTIMATE_RICE_BITS
-FLAC__bool set_partitioned_rice_with_precompute_(const FLAC__int32 residual[], const FLAC__uint64 abs_residual_partition_sums[], const unsigned raw_bits_per_partition[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, const FLAC__bool search_for_escapes, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits)
+FLAC__bool set_partitioned_rice_with_precompute_(
+ const FLAC__int32 residual[],
+ const FLAC__uint64 abs_residual_partition_sums[],
+ const unsigned raw_bits_per_partition[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ const FLAC__bool search_for_escapes,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+)
#else
-FLAC__bool set_partitioned_rice_with_precompute_(const FLAC__uint32 abs_residual[], const FLAC__uint64 abs_residual_partition_sums[], const unsigned raw_bits_per_partition[], const unsigned residual_samples, const unsigned predictor_order, const unsigned suggested_rice_parameter, const unsigned rice_parameter_search_dist, const unsigned partition_order, const FLAC__bool search_for_escapes, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, unsigned *bits)
+FLAC__bool set_partitioned_rice_with_precompute_(
+ const FLAC__uint32 abs_residual[],
+ const FLAC__uint64 abs_residual_partition_sums[],
+ const unsigned raw_bits_per_partition[],
+ const unsigned residual_samples,
+ const unsigned predictor_order,
+ const unsigned suggested_rice_parameter,
+ const unsigned rice_parameter_search_dist,
+ const unsigned partition_order,
+ const FLAC__bool search_for_escapes,
+ FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
+ unsigned *bits
+)
#endif
{
unsigned rice_parameter, partition_bits;