change to use 64-bit functions when needed to avoid overflow

This commit is contained in:
Josh Coalson 2001-03-30 00:45:22 +00:00
parent 4b2a27db4c
commit eef5670adc

View File

@ -23,6 +23,7 @@
#include <string.h> /* 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;