changeset 11885:0e777af9160a libavcodec

Factorize the mpegaudio windowing code in a function and call it by a function pointer. Should allow for ASM optimizations.
author vitor
date Sat, 19 Jun 2010 09:56:05 +0000
parents d62a89be5458
children 2d81202be6e2
files mpegaudio.h mpegaudiodec.c
diffstat 2 files changed, 68 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mpegaudio.h	Fri Jun 18 20:07:43 2010 +0000
+++ b/mpegaudio.h	Sat Jun 19 09:56:05 2010 +0000
@@ -156,6 +156,8 @@
     int dither_state;
     int error_recognition;
     AVCodecContext* avctx;
+    void (*apply_window_mp3)(MPA_INT *synth_buf, MPA_INT *window,
+                             int *dither_state, OUT_INT *samples, int incr);
 } MPADecodeContext;
 
 /* layer 3 huffman tables */
@@ -175,7 +177,8 @@
                          INTFLOAT sb_samples[SBLIMIT]);
 
 void ff_mpa_synth_init_float(MPA_INT *window);
-void ff_mpa_synth_filter_float(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
+void ff_mpa_synth_filter_float(MPADecodeContext *s,
+                         MPA_INT *synth_buf_ptr, int *synth_buf_offset,
                          MPA_INT *window, int *dither_state,
                          OUT_INT *samples, int incr,
                          INTFLOAT sb_samples[SBLIMIT]);
--- a/mpegaudiodec.c	Fri Jun 18 20:07:43 2010 +0000
+++ b/mpegaudiodec.c	Sat Jun 19 09:56:05 2010 +0000
@@ -69,6 +69,8 @@
 
 static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g);
 static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g);
+static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
+                               int *dither_state, OUT_INT *samples, int incr);
 
 /* vlc structure for decoding layer 3 huffman tables */
 static VLC huff_vlc[16];
@@ -305,6 +307,7 @@
     int i, j, k;
 
     s->avctx = avctx;
+    s->apply_window_mp3 = apply_window_mp3_c;
 
     avctx->sample_fmt= OUT_FMT;
     s->error_recognition= avctx->error_recognition;
@@ -836,41 +839,20 @@
     }
 }
 
-/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
-   32 samples. */
-/* XXX: optimize by avoiding ring buffer usage */
-void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
-                         MPA_INT *window, int *dither_state,
-                         OUT_INT *samples, int incr,
-                         INTFLOAT sb_samples[SBLIMIT])
+static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
+                               int *dither_state, OUT_INT *samples, int incr)
 {
-    register MPA_INT *synth_buf;
     register const MPA_INT *w, *w2, *p;
-    int j, offset;
+    int j;
     OUT_INT *samples2;
 #if CONFIG_FLOAT
     float sum, sum2;
 #elif FRAC_BITS <= 15
-    int32_t tmp[32];
     int sum, sum2;
 #else
     int64_t sum, sum2;
 #endif
 
-    offset = *synth_buf_offset;
-    synth_buf = synth_buf_ptr + offset;
-
-#if FRAC_BITS <= 15 && !CONFIG_FLOAT
-    dct32(tmp, sb_samples);
-    for(j=0;j<32;j++) {
-        /* NOTE: can cause a loss in precision if very high amplitude
-           sound */
-        synth_buf[j] = av_clip_int16(tmp[j]);
-    }
-#else
-    dct32(synth_buf, sb_samples);
-#endif
-
     /* copy to avoid wrap */
     memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
 
@@ -909,10 +891,63 @@
     SUM8(MLSS, sum, w + 32, p);
     *samples = round_sample(&sum);
     *dither_state= sum;
+}
+
+
+/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
+   32 samples. */
+/* XXX: optimize by avoiding ring buffer usage */
+#if CONFIG_FLOAT
+void ff_mpa_synth_filter_float(MPADecodeContext *s, float *synth_buf_ptr,
+                               int *synth_buf_offset,
+                               float *window, int *dither_state,
+                               float *samples, int incr,
+                               float sb_samples[SBLIMIT])
+{
+    float *synth_buf;
+    int offset;
+
+    offset = *synth_buf_offset;
+    synth_buf = synth_buf_ptr + offset;
+
+    dct32(synth_buf, sb_samples);
+    s->apply_window_mp3(synth_buf, window, dither_state, samples, incr);
 
     offset = (offset - 32) & 511;
     *synth_buf_offset = offset;
 }
+#else
+void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
+                         MPA_INT *window, int *dither_state,
+                         OUT_INT *samples, int incr,
+                         INTFLOAT sb_samples[SBLIMIT])
+{
+    register MPA_INT *synth_buf;
+    int offset;
+#if FRAC_BITS <= 15
+    int32_t tmp[32];
+#endif
+
+    offset = *synth_buf_offset;
+    synth_buf = synth_buf_ptr + offset;
+
+#if FRAC_BITS <= 15 && !CONFIG_FLOAT
+    dct32(tmp, sb_samples);
+    for(j=0;j<32;j++) {
+        /* NOTE: can cause a loss in precision if very high amplitude
+           sound */
+        synth_buf[j] = av_clip_int16(tmp[j]);
+    }
+#else
+    dct32(synth_buf, sb_samples);
+#endif
+
+    apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);
+
+    offset = (offset - 32) & 511;
+    *synth_buf_offset = offset;
+}
+#endif
 
 #define C3 FIXHR(0.86602540378443864676/2)
 
@@ -2227,7 +2262,11 @@
     for(ch=0;ch<s->nb_channels;ch++) {
         samples_ptr = samples + ch;
         for(i=0;i<nb_frames;i++) {
-            RENAME(ff_mpa_synth_filter)(s->synth_buf[ch], &(s->synth_buf_offset[ch]),
+            RENAME(ff_mpa_synth_filter)(
+#if CONFIG_FLOAT
+                         s,
+#endif
+                         s->synth_buf[ch], &(s->synth_buf_offset[ch]),
                          RENAME(ff_mpa_synth_window), &s->dither_state,
                          samples_ptr, s->nb_channels,
                          s->sb_samples[ch][i]);