mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
V2: Use a single definition of MIN and MAX in sources
This commit is contained in:
committed by
Erik de Castro Lopo
parent
d30fe60fc6
commit
f029625591
@@ -60,6 +60,7 @@
|
||||
#include "private/lpc.h"
|
||||
#include "private/md5.h"
|
||||
#include "private/memory.h"
|
||||
#include "private/macros.h"
|
||||
#if FLAC__HAS_OGG
|
||||
#include "private/ogg_helper.h"
|
||||
#include "private/ogg_mapping.h"
|
||||
@@ -71,16 +72,6 @@
|
||||
#define FLaC__INLINE
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#define min(x,y) ((x)<(y)?(x):(y))
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#define max(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
/* Exact Rice codeword length calculation is off by default. The simple
|
||||
* (and fast) estimation (of how many bits a residual value will be
|
||||
* encoded with) in this encoder is very good, almost always yielding
|
||||
@@ -691,7 +682,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
||||
if(encoder->protected_->bits_per_sample < 16) {
|
||||
/* @@@ need some data about how to set this here w.r.t. blocksize and sample rate */
|
||||
/* @@@ until then we'll make a guess */
|
||||
encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
|
||||
encoder->protected_->qlp_coeff_precision = flac_max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
|
||||
}
|
||||
else if(encoder->protected_->bits_per_sample == 16) {
|
||||
if(encoder->protected_->blocksize <= 192)
|
||||
@@ -880,7 +871,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
|
||||
encoder->private_->current_frame_number = 0;
|
||||
|
||||
encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
|
||||
encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
|
||||
encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(flac_max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
|
||||
encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
|
||||
|
||||
/*
|
||||
@@ -1971,7 +1962,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
|
||||
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
|
||||
|
||||
do {
|
||||
const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
|
||||
const unsigned n = flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
|
||||
|
||||
if(encoder->protected_->verify)
|
||||
append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
|
||||
@@ -2034,7 +2025,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
|
||||
*/
|
||||
do {
|
||||
if(encoder->protected_->verify)
|
||||
append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
|
||||
append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
|
||||
|
||||
/* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
|
||||
for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
|
||||
@@ -2069,7 +2060,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
|
||||
*/
|
||||
do {
|
||||
if(encoder->protected_->verify)
|
||||
append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
|
||||
append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
|
||||
|
||||
/* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
|
||||
for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
|
||||
@@ -2411,8 +2402,8 @@ FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC
|
||||
FLAC__bitwriter_clear(encoder->private_->frame);
|
||||
|
||||
if(samples > 0) {
|
||||
encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
|
||||
encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
|
||||
encoder->private_->streaminfo.data.stream_info.min_framesize = flac_min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
|
||||
encoder->private_->streaminfo.data.stream_info.max_framesize = flac_max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -2499,7 +2490,7 @@ FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
|
||||
* when the encoder goes back to write metadata, 'current_frame'
|
||||
* will drop back to 0.
|
||||
*/
|
||||
encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
|
||||
encoder->private_->frames_written = flac_max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
|
||||
}
|
||||
else
|
||||
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
|
||||
@@ -2510,7 +2501,7 @@ FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const
|
||||
/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */
|
||||
void update_metadata_(const FLAC__StreamEncoder *encoder)
|
||||
{
|
||||
FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
|
||||
FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
|
||||
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
|
||||
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
|
||||
const unsigned min_framesize = metadata->data.stream_info.min_framesize;
|
||||
@@ -2675,7 +2666,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
|
||||
FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
|
||||
FLAC__STREAM_SYNC_LENGTH
|
||||
;
|
||||
FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
|
||||
FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
|
||||
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
|
||||
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
|
||||
const unsigned min_framesize = metadata->data.stream_info.min_framesize;
|
||||
@@ -2926,9 +2917,9 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fracti
|
||||
}
|
||||
else {
|
||||
max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
|
||||
max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
|
||||
max_partition_order = flac_min(max_partition_order, encoder->protected_->max_residual_partition_order);
|
||||
}
|
||||
min_partition_order = min(min_partition_order, max_partition_order);
|
||||
min_partition_order = flac_min(min_partition_order, max_partition_order);
|
||||
|
||||
/*
|
||||
* Setup the frame
|
||||
@@ -3332,8 +3323,8 @@ FLAC__bool process_subframe_(
|
||||
min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
|
||||
/* try to ensure a 32-bit datapath throughout for 16bps(+1bps for side channel) or less */
|
||||
if(subframe_bps <= 17) {
|
||||
max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
|
||||
max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
|
||||
max_qlp_coeff_precision = flac_min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
|
||||
max_qlp_coeff_precision = flac_max(max_qlp_coeff_precision, min_qlp_coeff_precision);
|
||||
}
|
||||
else
|
||||
max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
|
||||
@@ -3577,7 +3568,7 @@ unsigned evaluate_lpc_subframe_(
|
||||
if(subframe_bps <= 16) {
|
||||
FLAC__ASSERT(order > 0);
|
||||
FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
|
||||
qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
|
||||
qlp_coeff_precision = flac_min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
|
||||
}
|
||||
|
||||
ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
|
||||
@@ -3681,7 +3672,7 @@ unsigned find_best_partition_order_(
|
||||
const unsigned blocksize = residual_samples + predictor_order;
|
||||
|
||||
max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
|
||||
min_partition_order = min(min_partition_order, max_partition_order);
|
||||
min_partition_order = flac_min(min_partition_order, max_partition_order);
|
||||
|
||||
precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
|
||||
|
||||
@@ -3735,7 +3726,7 @@ unsigned find_best_partition_order_(
|
||||
unsigned partition;
|
||||
|
||||
/* save best parameters and raw_bits */
|
||||
FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
|
||||
FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, flac_max(6u, best_partition_order));
|
||||
memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
|
||||
if(do_escape_coding)
|
||||
memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
|
||||
@@ -3887,7 +3878,7 @@ void precompute_partition_info_escapes_(
|
||||
for(i = 0; i < partitions; i++) {
|
||||
m = raw_bits_per_partition[from_partition];
|
||||
from_partition++;
|
||||
raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
|
||||
raw_bits_per_partition[to_partition] = flac_max(m, raw_bits_per_partition[from_partition]);
|
||||
from_partition++;
|
||||
to_partition++;
|
||||
}
|
||||
@@ -3965,7 +3956,7 @@ FLAC__bool set_partitioned_rice_(
|
||||
FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
|
||||
FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
|
||||
|
||||
FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
|
||||
FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order));
|
||||
parameters = partitioned_rice_contents->parameters;
|
||||
raw_bits = partitioned_rice_contents->raw_bits;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user