add bps checks so we can use miroslav's mmx versions of some routines
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 31 May 2001 20:53:19 +0000 (20:53 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 31 May 2001 20:53:19 +0000 (20:53 +0000)
src/libFLAC/encoder.c
src/libFLAC/stream_decoder.c

index 137c959..3db4332 100644 (file)
@@ -77,6 +77,7 @@ typedef struct FLAC__EncoderPrivate {
        unsigned (*local_fixed_compute_best_predictor)(const int32 data[], unsigned data_len, real residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
        void (*local_lpc_compute_autocorrelation)(const real data[], unsigned data_len, unsigned lag, real autoc[]);
        void (*local_lpc_compute_residual_from_qlp_coefficients)(const int32 data[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 residual[]);
+       void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const int32 data[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 residual[]);
        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);
@@ -329,6 +330,7 @@ FLAC__EncoderState FLAC__encoder_init(FLAC__Encoder *encoder, FLAC__EncoderWrite
        encoder->guts->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
        encoder->guts->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
        encoder->guts->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
+       encoder->guts->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
        /* now override with asm where appropriate */
 #ifndef FLAC__NO_ASM
        FLAC__ASSERT(encoder->guts->cpuinfo.use_asm);
@@ -364,17 +366,16 @@ fprintf(stderr,"@@@ got _asm_i386 of lpc_compute_autocorrelation()\n");}
 {//@@@
                encoder->guts->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_i386_mmx_cmov;
 fprintf(stderr,"@@@ got _asm_i386_mmx_cmov of fixed_compute_best_predictor()\n");}
-#if 0
-       /* @@@ MMX version needs bps check */
-       if(encoder->guts->cpuinfo.data.ia32.mmx && @@@bps check here@@@)
-{//@@@
-               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_i386_mmx;
-fprintf(stderr,"@@@ got _asm_i386_mmx of lpc_compute_residual_from_qlp_coefficients()\n");}
-       else
-#endif
-{//@@@
+       if(encoder->guts->cpuinfo.data.ia32.mmx) {
                encoder->guts->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_i386;
-fprintf(stderr,"@@@ got _asm_i386 of lpc_compute_residual_from_qlp_coefficients()\n");}
+               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_i386_mmx;
+fprintf(stderr,"@@@ got _asm_i386_mmx of lpc_compute_residual_from_qlp_coefficients()\n");
+       }
+       else {
+               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_i386;
+               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_i386;
+fprintf(stderr,"@@@ got _asm_i386 of lpc_compute_residual_from_qlp_coefficients()\n");
+       }
 #endif
 #endif
 #endif
@@ -1101,7 +1102,10 @@ unsigned encoder_evaluate_lpc_subframe_(FLAC__Encoder *encoder, const int32 sign
        if(ret != 0)
                return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
 
-       encoder->guts->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
+       if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
+               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
+       else
+               encoder->guts->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
 
        subframe->type = FLAC__SUBFRAME_TYPE_LPC;
 
index 44ac5c1..910b3ee 100644 (file)
@@ -34,6 +34,7 @@ typedef struct FLAC__StreamDecoderPrivate {
        void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data);
        void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
        void (*local_lpc_restore_signal)(const int32 residual[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 data[]);
+       void (*local_lpc_restore_signal_16bit)(const int32 residual[], unsigned data_len, const int32 qlp_coeff[], unsigned order, int lp_quantization, int32 data[]);
        void *client_data;
        FLAC__BitBuffer input;
        int32 *output[FLAC__MAX_CHANNELS];
@@ -166,23 +167,23 @@ FLAC__StreamDecoderState FLAC__stream_decoder_init(
        FLAC__cpu_info(&decoder->guts->cpuinfo);
        /* first default to the non-asm routines */
        decoder->guts->local_lpc_restore_signal = FLAC__lpc_restore_signal;
+       decoder->guts->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
        /* now override with asm where appropriate */
 #ifndef FLAC__NO_ASM
        FLAC__ASSERT(decoder->guts->cpuinfo.use_asm);
 #ifdef FLAC__CPU_IA32
        FLAC__ASSERT(decoder->guts->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
 #ifdef FLAC__HAS_NASM
-#if 0
-       /* @@@ MMX version needs bps check */
-       if(decoder->guts->cpuinfo.data.ia32.mmx && @@@bps check here@@@)
-{//@@@
-               decoder->guts->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_i386_mmx;
-fprintf(stderr,"@@@ got _asm_i386_mmx of lpc_restore_signal()\n");}
-       else
-#endif
-{//@@@
+       if(decoder->guts->cpuinfo.data.ia32.mmx) {
                decoder->guts->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_i386;
-fprintf(stderr,"@@@ got _asm_i386 of lpc_restore_signal()\n");}
+               decoder->guts->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_i386_mmx;
+fprintf(stderr,"@@@ got _asm_i386_mmx of lpc_restore_signal()\n");
+       }
+       else {
+               decoder->guts->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_i386;
+               decoder->guts->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_i386;
+fprintf(stderr,"@@@ got _asm_i386 of lpc_restore_signal()\n");
+       }
 #endif
 #endif
 #endif
@@ -1301,7 +1302,10 @@ bool stream_decoder_read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned ch
 
        /* decode the subframe */
        memcpy(decoder->guts->output[channel], subframe->warmup, sizeof(int32) * order);
-       decoder->guts->local_lpc_restore_signal(decoder->guts->residual[channel], decoder->guts->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->guts->output[channel]+order);
+       if(bps <= 16 && subframe->qlp_coeff_precision <= 16)
+               decoder->guts->local_lpc_restore_signal_16bit(decoder->guts->residual[channel], decoder->guts->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->guts->output[channel]+order);
+       else
+               decoder->guts->local_lpc_restore_signal(decoder->guts->residual[channel], decoder->guts->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->guts->output[channel]+order);
 
        return true;
 }