From eef5670adc892b8fe687dbc0551e16ad06626660 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 30 Mar 2001 00:45:22 +0000 Subject: [PATCH] change to use 64-bit functions when needed to avoid overflow --- src/libFLAC/encoder.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libFLAC/encoder.c b/src/libFLAC/encoder.c index d14ae8d0..d47c5ef6 100644 --- a/src/libFLAC/encoder.c +++ b/src/libFLAC/encoder.c @@ -23,6 +23,7 @@ #include /* for memcpy() */ #include "FLAC/encoder.h" #include "private/bitbuffer.h" +#include "private/bitmath.h" #include "private/crc.h" #include "private/encoder_framing.h" #include "private/fixed.h" @@ -68,6 +69,7 @@ typedef struct FLAC__EncoderPrivate { unsigned current_sample_number; unsigned current_frame_number; struct MD5Context md5context; + bool use_slow; /* use slow 64-bit versions of some functions */ FLAC__EncoderWriteStatus (*write_callback)(const FLAC__Encoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); void (*metadata_callback)(const FLAC__Encoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data); void *client_data; @@ -361,6 +363,11 @@ FLAC__EncoderState FLAC__encoder_init(FLAC__Encoder *encoder, FLAC__EncoderWrite encoder->guts->current_sample_number = 0; encoder->guts->current_frame_number = 0; + if(encoder->bits_per_sample + FLAC__bitmath_ilog2(encoder->blocksize)+1 > 30) + encoder->guts->use_slow = true; + else + encoder->guts->use_slow = false; + if(!encoder_resize_buffers_(encoder, encoder->blocksize)) { /* the above function sets the state for us in case of an error */ return encoder->state; @@ -868,7 +875,10 @@ bool encoder_process_subframe_(FLAC__Encoder *encoder, unsigned max_partition_or if(!verbatim_only && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) { /* check for constant subframe */ - guess_fixed_order = FLAC__fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); + if(encoder->guts->use_slow) + guess_fixed_order = FLAC__fixed_compute_best_predictor_slow(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); + else + guess_fixed_order = FLAC__fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); if(fixed_residual_bits_per_sample[1] == 0.0) { /* the above means integer_signal+FLAC__MAX_FIXED_ORDER is constant, now we just have to check the warmup samples */ unsigned i, signal_is_constant = true;