diff flacenc.c @ 5737:efa3c1f9259a libavcodec

sse2 version of compute_autocorr(). 4x faster than c (somehow, even though doubles only allow 2x simd). overal flac encoding: 15-50% faster on core2, 4-11% on k8, 3-13% on p4.
author lorenm
date Sat, 29 Sep 2007 22:31:18 +0000
parents c2f88af57c16
children c1a4aae5adb4
line wrap: on
line diff
--- a/flacenc.c	Sat Sep 29 15:20:22 2007 +0000
+++ b/flacenc.c	Sat Sep 29 22:31:18 2007 +0000
@@ -22,6 +22,7 @@
 #include "avcodec.h"
 #include "bitstream.h"
 #include "crc.h"
+#include "dsputil.h"
 #include "golomb.h"
 #include "lls.h"
 
@@ -107,6 +108,7 @@
     FlacFrame frame;
     CompressionOptions options;
     AVCodecContext *avctx;
+    DSPContext dsp;
 } FlacEncodeContext;
 
 static const int flac_samplerates[16] = {
@@ -177,6 +179,8 @@
 
     s->avctx = avctx;
 
+    dsputil_init(&s->dsp, avctx);
+
     if(avctx->sample_fmt != SAMPLE_FMT_S16) {
         return -1;
     }
@@ -604,8 +608,8 @@
  * Calculates autocorrelation data from audio samples
  * A Welch window function is applied before calculation.
  */
-static void compute_autocorr(const int32_t *data, int len, int lag,
-                             double *autoc)
+void ff_flac_compute_autocorr(const int32_t *data, int len, int lag,
+                              double *autoc)
 {
     int i, j;
     double tmp[len + lag + 1];
@@ -747,7 +751,8 @@
 /**
  * Calculate LPC coefficients for multiple orders
  */
-static int lpc_calc_coefs(const int32_t *samples, int blocksize, int max_order,
+static int lpc_calc_coefs(FlacEncodeContext *s,
+                          const int32_t *samples, int blocksize, int max_order,
                           int precision, int32_t coefs[][MAX_LPC_ORDER],
                           int *shift, int use_lpc, int omethod)
 {
@@ -760,7 +765,7 @@
     assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER);
 
     if(use_lpc == 1){
-        compute_autocorr(samples, blocksize, max_order, autoc);
+        s->dsp.flac_compute_autocorr(samples, blocksize, max_order, autoc);
 
         compute_lpc_coefs(autoc, max_order, lpc, ref);
     }else{
@@ -1017,7 +1022,7 @@
     }
 
     /* LPC */
-    opt_order = lpc_calc_coefs(smp, n, max_order, precision, coefs, shift, ctx->options.use_lpc, omethod);
+    opt_order = lpc_calc_coefs(ctx, smp, n, max_order, precision, coefs, shift, ctx->options.use_lpc, omethod);
 
     if(omethod == ORDER_METHOD_2LEVEL ||
        omethod == ORDER_METHOD_4LEVEL ||