Browse code

Move some mpegaudio functions to new mpegaudiodsp subsystem

This separation allows these functions to be used in a cleaner
fashion from other codecs (e.g. qdm2) and simplifies creating
optimised versions of them.

Signed-off-by: Mans Rullgard <mans@mansr.com>

Mans Rullgard authored on 2011/05/17 00:52:01
Showing 17 changed files
... ...
@@ -952,6 +952,7 @@ CONFIG_LIST="
952 952
     mdct
953 953
     memalign_hack
954 954
     mlib
955
+    mpegaudiodsp
955 956
     network
956 957
     nonfree
957 958
     pic
... ...
@@ -1235,6 +1236,7 @@ symver_if_any="symver_asm_label symver_gnu_asm"
1235 1235
 dct_select="rdft"
1236 1236
 mdct_select="fft"
1237 1237
 rdft_select="fft"
1238
+mpegaudiodsp_select="dct"
1238 1239
 
1239 1240
 # decoders / encoders / hardware accelerators
1240 1241
 aac_decoder_select="mdct sinewin"
... ...
@@ -1286,11 +1288,16 @@ ljpeg_encoder_select="aandct"
1286 1286
 loco_decoder_select="golomb"
1287 1287
 mjpeg_encoder_select="aandct"
1288 1288
 mlp_decoder_select="mlp_parser"
1289
-mp1float_decoder_select="dct"
1290
-mp2float_decoder_select="dct"
1291
-mp3adufloat_decoder_select="dct"
1292
-mp3float_decoder_select="dct"
1293
-mp3on4float_decoder_select="dct"
1289
+mp1_decoder_select="mpegaudiodsp"
1290
+mp2_decoder_select="mpegaudiodsp"
1291
+mp3adu_decoder_select="mpegaudiodsp"
1292
+mp3_decoder_select="mpegaudiodsp"
1293
+mp3on4_decoder_select="mpegaudiodsp"
1294
+mp1float_decoder_select="mpegaudiodsp"
1295
+mp2float_decoder_select="mpegaudiodsp"
1296
+mp3adufloat_decoder_select="mpegaudiodsp"
1297
+mp3float_decoder_select="mpegaudiodsp"
1298
+mp3on4float_decoder_select="mpegaudiodsp"
1294 1299
 mpeg1video_encoder_select="aandct"
1295 1300
 mpeg2video_encoder_select="aandct"
1296 1301
 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
... ...
@@ -1315,7 +1322,7 @@ nellymoser_encoder_select="mdct sinewin"
1315 1315
 png_decoder_select="zlib"
1316 1316
 png_encoder_select="zlib"
1317 1317
 qcelp_decoder_select="lsp"
1318
-qdm2_decoder_select="mdct rdft"
1318
+qdm2_decoder_select="mdct rdft mpegaudiodsp"
1319 1319
 ra_144_encoder_select="lpc"
1320 1320
 rv10_decoder_select="h263_decoder"
1321 1321
 rv10_encoder_select="h263_encoder"
... ...
@@ -40,6 +40,9 @@ OBJS-$(CONFIG_HUFFMAN)                 += huffman.o
40 40
 OBJS-$(CONFIG_LPC)                     += lpc.o
41 41
 OBJS-$(CONFIG_LSP)                     += lsp.o
42 42
 OBJS-$(CONFIG_MDCT)                    += mdct_fixed.o mdct_float.o
43
+OBJS-$(CONFIG_MPEGAUDIODSP)            += mpegaudiodsp.o                \
44
+                                          mpegaudiodsp_fixed.o          \
45
+                                          mpegaudiodsp_float.o
43 46
 RDFT-OBJS-$(CONFIG_HARDCODED_TABLES)   += sin_tables.o
44 47
 OBJS-$(CONFIG_RDFT)                    += rdft.o $(RDFT-OBJS-yes)
45 48
 OBJS-$(CONFIG_SINEWIN)                 += sinewin.o
... ...
@@ -29,6 +29,7 @@
29 29
 #include "avcodec.h"
30 30
 #include "get_bits.h"
31 31
 #include "dsputil.h"
32
+#include "mpegaudiodsp.h"
32 33
 #include "mpegaudio.h"
33 34
 
34 35
 #include "mpc.h"
... ...
@@ -51,7 +52,8 @@ static void mpc_synth(MPCContext *c, int16_t *out, int channels)
51 51
     for(ch = 0;  ch < channels; ch++){
52 52
         samples_ptr = samples + ch;
53 53
         for(i = 0; i < SAMPLES_PER_BAND; i++) {
54
-            ff_mpa_synth_filter_fixed(c->synth_buf[ch], &(c->synth_buf_offset[ch]),
54
+            ff_mpa_synth_filter_fixed(&c->mpadsp,
55
+                                c->synth_buf[ch], &(c->synth_buf_offset[ch]),
55 56
                                 ff_mpa_synth_window_fixed, &dither_state,
56 57
                                 samples_ptr, channels,
57 58
                                 c->sb_samples[ch][i]);
... ...
@@ -52,6 +52,7 @@ typedef struct {
52 52
 
53 53
 typedef struct {
54 54
     DSPContext dsp;
55
+    MPADSPContext mpadsp;
55 56
     GetBitContext gb;
56 57
     int IS, MSS, gapless;
57 58
     int lastframelen;
... ...
@@ -29,7 +29,7 @@
29 29
 #include "avcodec.h"
30 30
 #include "get_bits.h"
31 31
 #include "dsputil.h"
32
-#include "mpegaudio.h"
32
+#include "mpegaudiodsp.h"
33 33
 #include "libavutil/audioconvert.h"
34 34
 
35 35
 #include "mpc.h"
... ...
@@ -68,6 +68,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
68 68
     memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
69 69
     av_lfg_init(&c->rnd, 0xDEADBEEF);
70 70
     dsputil_init(&c->dsp, avctx);
71
+    ff_mpadsp_init(&c->mpadsp);
71 72
     c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);
72 73
     ff_mpc_init();
73 74
     init_get_bits(&gb, buf, 128);
... ...
@@ -29,7 +29,7 @@
29 29
 #include "avcodec.h"
30 30
 #include "get_bits.h"
31 31
 #include "dsputil.h"
32
-#include "mpegaudio.h"
32
+#include "mpegaudiodsp.h"
33 33
 #include "libavutil/audioconvert.h"
34 34
 
35 35
 #include "mpc.h"
... ...
@@ -120,6 +120,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
120 120
     memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
121 121
     av_lfg_init(&c->rnd, 0xDEADBEEF);
122 122
     dsputil_init(&c->dsp, avctx);
123
+    ff_mpadsp_init(&c->mpadsp);
123 124
 
124 125
     ff_mpc_init();
125 126
 
... ...
@@ -33,7 +33,6 @@
33 33
 #include "avcodec.h"
34 34
 #include "get_bits.h"
35 35
 #include "dsputil.h"
36
-#include "dct.h"
37 36
 
38 37
 /* max frame size, in samples */
39 38
 #define MPA_FRAME_SIZE 1152
... ...
@@ -69,7 +68,6 @@
69 69
 typedef float OUT_INT;
70 70
 #else
71 71
 typedef int16_t OUT_INT;
72
-#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
73 72
 #endif
74 73
 
75 74
 #if CONFIG_FLOAT
... ...
@@ -142,11 +140,7 @@ typedef struct MPADecodeContext {
142 142
     int dither_state;
143 143
     int error_recognition;
144 144
     AVCodecContext* avctx;
145
-#if CONFIG_FLOAT
146
-    DCTContext dct;
147
-#endif
148
-    void (*apply_window_mp3)(MPA_INT *synth_buf, MPA_INT *window,
149
-                             int *dither_state, OUT_INT *samples, int incr);
145
+    MPADSPContext mpadsp;
150 146
 } MPADecodeContext;
151 147
 
152 148
 /* layer 3 huffman tables */
... ...
@@ -158,22 +152,6 @@ typedef struct HuffTable {
158 158
 
159 159
 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
160 160
 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
161
-extern MPA_INT ff_mpa_synth_window_fixed[];
162
-void ff_mpa_synth_init_fixed(MPA_INT *window);
163
-void ff_mpa_synth_filter_fixed(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
164
-                         MPA_INT *window, int *dither_state,
165
-                         OUT_INT *samples, int incr,
166
-                         INTFLOAT sb_samples[SBLIMIT]);
167
-
168
-void ff_mpa_synth_init_float(MPA_INT *window);
169
-void ff_mpa_synth_filter_float(MPADecodeContext *s,
170
-                         MPA_INT *synth_buf_ptr, int *synth_buf_offset,
171
-                         MPA_INT *window, int *dither_state,
172
-                         OUT_INT *samples, int incr,
173
-                         INTFLOAT sb_samples[SBLIMIT]);
174
-
175
-void ff_mpegaudiodec_init_mmx(MPADecodeContext *s);
176
-void ff_mpegaudiodec_init_altivec(MPADecodeContext *s);
177 161
 
178 162
 /* fast header check for resync */
179 163
 static inline int ff_mpa_check_header(uint32_t header){
... ...
@@ -29,7 +29,7 @@
29 29
 #include "get_bits.h"
30 30
 #include "dsputil.h"
31 31
 #include "mathops.h"
32
-#include "dct32.h"
32
+#include "mpegaudiodsp.h"
33 33
 
34 34
 /*
35 35
  * TODO:
... ...
@@ -68,8 +68,6 @@
68 68
 #include "mpegaudiodectab.h"
69 69
 
70 70
 static void RENAME(compute_antialias)(MPADecodeContext *s, GranuleDef *g);
71
-static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
72
-                               int *dither_state, OUT_INT *samples, int incr);
73 71
 
74 72
 /* vlc structure for decoding layer 3 huffman tables */
75 73
 static VLC huff_vlc[16];
... ...
@@ -119,8 +117,6 @@ static const int32_t scale_factor_mult2[3][3] = {
119 119
     SCALE_GEN(4.0 / 9.0), /* 9 steps */
120 120
 };
121 121
 
122
-DECLARE_ALIGNED(16, MPA_INT, RENAME(ff_mpa_synth_window))[512+256];
123
-
124 122
 /**
125 123
  * Convert region offsets to region sizes and truncate
126 124
  * size to big_values.
... ...
@@ -259,14 +255,8 @@ static av_cold int decode_init(AVCodecContext * avctx)
259 259
     int i, j, k;
260 260
 
261 261
     s->avctx = avctx;
262
-    s->apply_window_mp3 = apply_window_mp3_c;
263
-#if HAVE_MMX && CONFIG_FLOAT
264
-    ff_mpegaudiodec_init_mmx(s);
265
-#endif
266
-#if CONFIG_FLOAT
267
-    ff_dct_init(&s->dct, 5, DCT_II);
268
-#endif
269
-    if (HAVE_ALTIVEC && CONFIG_FLOAT) ff_mpegaudiodec_init_altivec(s);
262
+
263
+    ff_mpadsp_init(&s->mpadsp);
270 264
 
271 265
     avctx->sample_fmt= OUT_FMT;
272 266
     s->error_recognition= avctx->error_recognition;
... ...
@@ -461,183 +451,6 @@ static av_cold int decode_init(AVCodecContext * avctx)
461 461
     return 0;
462 462
 }
463 463
 
464
-
465
-#if CONFIG_FLOAT
466
-static inline float round_sample(float *sum)
467
-{
468
-    float sum1=*sum;
469
-    *sum = 0;
470
-    return sum1;
471
-}
472
-
473
-/* signed 16x16 -> 32 multiply add accumulate */
474
-#define MACS(rt, ra, rb) rt+=(ra)*(rb)
475
-
476
-/* signed 16x16 -> 32 multiply */
477
-#define MULS(ra, rb) ((ra)*(rb))
478
-
479
-#define MLSS(rt, ra, rb) rt-=(ra)*(rb)
480
-
481
-#else
482
-
483
-static inline int round_sample(int64_t *sum)
484
-{
485
-    int sum1;
486
-    sum1 = (int)((*sum) >> OUT_SHIFT);
487
-    *sum &= (1<<OUT_SHIFT)-1;
488
-    return av_clip_int16(sum1);
489
-}
490
-
491
-#   define MULS(ra, rb) MUL64(ra, rb)
492
-#   define MACS(rt, ra, rb) MAC64(rt, ra, rb)
493
-#   define MLSS(rt, ra, rb) MLS64(rt, ra, rb)
494
-#endif
495
-
496
-#define SUM8(op, sum, w, p)               \
497
-{                                         \
498
-    op(sum, (w)[0 * 64], (p)[0 * 64]);    \
499
-    op(sum, (w)[1 * 64], (p)[1 * 64]);    \
500
-    op(sum, (w)[2 * 64], (p)[2 * 64]);    \
501
-    op(sum, (w)[3 * 64], (p)[3 * 64]);    \
502
-    op(sum, (w)[4 * 64], (p)[4 * 64]);    \
503
-    op(sum, (w)[5 * 64], (p)[5 * 64]);    \
504
-    op(sum, (w)[6 * 64], (p)[6 * 64]);    \
505
-    op(sum, (w)[7 * 64], (p)[7 * 64]);    \
506
-}
507
-
508
-#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
509
-{                                               \
510
-    INTFLOAT tmp;\
511
-    tmp = p[0 * 64];\
512
-    op1(sum1, (w1)[0 * 64], tmp);\
513
-    op2(sum2, (w2)[0 * 64], tmp);\
514
-    tmp = p[1 * 64];\
515
-    op1(sum1, (w1)[1 * 64], tmp);\
516
-    op2(sum2, (w2)[1 * 64], tmp);\
517
-    tmp = p[2 * 64];\
518
-    op1(sum1, (w1)[2 * 64], tmp);\
519
-    op2(sum2, (w2)[2 * 64], tmp);\
520
-    tmp = p[3 * 64];\
521
-    op1(sum1, (w1)[3 * 64], tmp);\
522
-    op2(sum2, (w2)[3 * 64], tmp);\
523
-    tmp = p[4 * 64];\
524
-    op1(sum1, (w1)[4 * 64], tmp);\
525
-    op2(sum2, (w2)[4 * 64], tmp);\
526
-    tmp = p[5 * 64];\
527
-    op1(sum1, (w1)[5 * 64], tmp);\
528
-    op2(sum2, (w2)[5 * 64], tmp);\
529
-    tmp = p[6 * 64];\
530
-    op1(sum1, (w1)[6 * 64], tmp);\
531
-    op2(sum2, (w2)[6 * 64], tmp);\
532
-    tmp = p[7 * 64];\
533
-    op1(sum1, (w1)[7 * 64], tmp);\
534
-    op2(sum2, (w2)[7 * 64], tmp);\
535
-}
536
-
537
-void av_cold RENAME(ff_mpa_synth_init)(MPA_INT *window)
538
-{
539
-    int i, j;
540
-
541
-    /* max = 18760, max sum over all 16 coefs : 44736 */
542
-    for(i=0;i<257;i++) {
543
-        INTFLOAT v;
544
-        v = ff_mpa_enwindow[i];
545
-#if CONFIG_FLOAT
546
-        v *= 1.0 / (1LL<<(16 + FRAC_BITS));
547
-#endif
548
-        window[i] = v;
549
-        if ((i & 63) != 0)
550
-            v = -v;
551
-        if (i != 0)
552
-            window[512 - i] = v;
553
-    }
554
-
555
-    // Needed for avoiding shuffles in ASM implementations
556
-    for(i=0; i < 8; i++)
557
-        for(j=0; j < 16; j++)
558
-            window[512+16*i+j] = window[64*i+32-j];
559
-
560
-    for(i=0; i < 8; i++)
561
-        for(j=0; j < 16; j++)
562
-            window[512+128+16*i+j] = window[64*i+48-j];
563
-}
564
-
565
-static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
566
-                               int *dither_state, OUT_INT *samples, int incr)
567
-{
568
-    register const MPA_INT *w, *w2, *p;
569
-    int j;
570
-    OUT_INT *samples2;
571
-#if CONFIG_FLOAT
572
-    float sum, sum2;
573
-#else
574
-    int64_t sum, sum2;
575
-#endif
576
-
577
-    /* copy to avoid wrap */
578
-    memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
579
-
580
-    samples2 = samples + 31 * incr;
581
-    w = window;
582
-    w2 = window + 31;
583
-
584
-    sum = *dither_state;
585
-    p = synth_buf + 16;
586
-    SUM8(MACS, sum, w, p);
587
-    p = synth_buf + 48;
588
-    SUM8(MLSS, sum, w + 32, p);
589
-    *samples = round_sample(&sum);
590
-    samples += incr;
591
-    w++;
592
-
593
-    /* we calculate two samples at the same time to avoid one memory
594
-       access per two sample */
595
-    for(j=1;j<16;j++) {
596
-        sum2 = 0;
597
-        p = synth_buf + 16 + j;
598
-        SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
599
-        p = synth_buf + 48 - j;
600
-        SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
601
-
602
-        *samples = round_sample(&sum);
603
-        samples += incr;
604
-        sum += sum2;
605
-        *samples2 = round_sample(&sum);
606
-        samples2 -= incr;
607
-        w++;
608
-        w2--;
609
-    }
610
-
611
-    p = synth_buf + 32;
612
-    SUM8(MLSS, sum, w + 32, p);
613
-    *samples = round_sample(&sum);
614
-    *dither_state= sum;
615
-}
616
-
617
-
618
-/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
619
-   32 samples. */
620
-/* XXX: optimize by avoiding ring buffer usage */
621
-#if !CONFIG_FLOAT
622
-void ff_mpa_synth_filter_fixed(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
623
-                         MPA_INT *window, int *dither_state,
624
-                         OUT_INT *samples, int incr,
625
-                         INTFLOAT sb_samples[SBLIMIT])
626
-{
627
-    register MPA_INT *synth_buf;
628
-    int offset;
629
-
630
-    offset = *synth_buf_offset;
631
-    synth_buf = synth_buf_ptr + offset;
632
-
633
-    ff_dct32_fixed(synth_buf, sb_samples);
634
-    apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);
635
-
636
-    offset = (offset - 32) & 511;
637
-    *synth_buf_offset = offset;
638
-}
639
-#endif
640
-
641 464
 #define C3 FIXHR(0.86602540378443864676/2)
642 465
 
643 466
 /* 0.5 / cos(pi*(2*i+1)/36) */
... ...
@@ -1915,9 +1728,7 @@ static int mp_decode_frame(MPADecodeContext *s,
1915 1915
         samples_ptr = samples + ch;
1916 1916
         for(i=0;i<nb_frames;i++) {
1917 1917
             RENAME(ff_mpa_synth_filter)(
1918
-#if CONFIG_FLOAT
1919
-                         s,
1920
-#endif
1918
+                         &s->mpadsp,
1921 1919
                          s->synth_buf[ch], &(s->synth_buf_offset[ch]),
1922 1920
                          RENAME(ff_mpa_synth_window), &s->dither_state,
1923 1921
                          samples_ptr, s->nb_channels,
... ...
@@ -22,25 +22,6 @@
22 22
 #define CONFIG_FLOAT 1
23 23
 #include "mpegaudiodec.c"
24 24
 
25
-void ff_mpa_synth_filter_float(MPADecodeContext *s, float *synth_buf_ptr,
26
-                               int *synth_buf_offset,
27
-                               float *window, int *dither_state,
28
-                               float *samples, int incr,
29
-                               float sb_samples[SBLIMIT])
30
-{
31
-    float *synth_buf;
32
-    int offset;
33
-
34
-    offset = *synth_buf_offset;
35
-    synth_buf = synth_buf_ptr + offset;
36
-
37
-    s->dct.dct32(synth_buf, sb_samples);
38
-    s->apply_window_mp3(synth_buf, window, dither_state, samples, incr);
39
-
40
-    offset = (offset - 32) & 511;
41
-    *synth_buf_offset = offset;
42
-}
43
-
44 25
 static void compute_antialias_float(MPADecodeContext *s,
45 26
                               GranuleDef *g)
46 27
 {
47 28
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+/*
1
+ * Copyright (c) 2011 Mans Rullgard
2
+ *
3
+ * This file is part of Libav.
4
+ *
5
+ * Libav is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Libav is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with Libav; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "config.h"
21
+#include "mpegaudiodsp.h"
22
+#include "dct.h"
23
+#include "dct32.h"
24
+
25
+void ff_mpadsp_init(MPADSPContext *s)
26
+{
27
+    DCTContext dct;
28
+
29
+    ff_dct_init(&dct, 5, DCT_II);
30
+
31
+    s->apply_window_float = ff_mpadsp_apply_window_float;
32
+    s->apply_window_fixed = ff_mpadsp_apply_window_fixed;
33
+
34
+    s->dct32_float = dct.dct32;
35
+    s->dct32_fixed = ff_dct32_fixed;
36
+
37
+    if (HAVE_MMX)     ff_mpadsp_init_mmx(s);
38
+    if (HAVE_ALTIVEC) ff_mpadsp_init_altivec(s);
39
+}
0 40
new file mode 100644
... ...
@@ -0,0 +1,63 @@
0
+/*
1
+ * This file is part of Libav.
2
+ *
3
+ * Libav is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * Libav is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with Libav; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#ifndef AVCODEC_MPEGAUDIODSP_H
19
+#define AVCODEC_MPEGAUDIODSP_H
20
+
21
+#include <stdint.h>
22
+
23
+typedef struct MPADSPContext {
24
+    void (*apply_window_float)(float *synth_buf, float *window,
25
+                               int *dither_state, float *samples, int incr);
26
+    void (*apply_window_fixed)(int32_t *synth_buf, int32_t *window,
27
+                               int *dither_state, int16_t *samples, int incr);
28
+    void (*dct32_float)(float *dst, const float *src);
29
+    void (*dct32_fixed)(int *dst, const int *src);
30
+} MPADSPContext;
31
+
32
+void ff_mpadsp_init(MPADSPContext *s);
33
+
34
+extern int32_t ff_mpa_synth_window_fixed[];
35
+extern float   ff_mpa_synth_window_float[];
36
+
37
+void ff_mpa_synth_filter_fixed(MPADSPContext *s,
38
+                               int32_t *synth_buf_ptr, int *synth_buf_offset,
39
+                               int32_t *window, int *dither_state,
40
+                               int16_t *samples, int incr,
41
+                               int *sb_samples);
42
+
43
+void ff_mpa_synth_filter_float(MPADSPContext *s,
44
+                               float *synth_buf_ptr, int *synth_buf_offset,
45
+                               float *window, int *dither_state,
46
+                               float *samples, int incr,
47
+                               float *sb_samples);
48
+
49
+void ff_mpadsp_init_mmx(MPADSPContext *s);
50
+void ff_mpadsp_init_altivec(MPADSPContext *s);
51
+
52
+void ff_mpa_synth_init_float(float *window);
53
+void ff_mpa_synth_init_fixed(int32_t *window);
54
+
55
+void ff_mpadsp_apply_window_float(float *synth_buf, float *window,
56
+                                  int *dither_state, float *samples,
57
+                                  int incr);
58
+void ff_mpadsp_apply_window_fixed(int32_t *synth_buf, int32_t *window,
59
+                                  int *dither_state, int16_t *samples,
60
+                                  int incr);
61
+
62
+#endif
0 63
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+/*
1
+ * This file is part of Libav.
2
+ *
3
+ * Libav is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * Libav is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with Libav; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#define CONFIG_FLOAT 0
19
+#include "mpegaudiodsp_template.c"
0 20
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+/*
1
+ * This file is part of Libav.
2
+ *
3
+ * Libav is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * Libav is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with Libav; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#define CONFIG_FLOAT 1
19
+#include "mpegaudiodsp_template.c"
0 20
new file mode 100644
... ...
@@ -0,0 +1,205 @@
0
+/*
1
+ * Copyright (c) 2001, 2002 Fabrice Bellard
2
+ *
3
+ * This file is part of Libav.
4
+ *
5
+ * Libav is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Libav is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with Libav; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include <stdint.h>
21
+
22
+#include "libavutil/mem.h"
23
+#include "dct32.h"
24
+#include "mathops.h"
25
+#include "mpegaudiodsp.h"
26
+#include "mpegaudio.h"
27
+#include "mpegaudiodata.h"
28
+
29
+#if CONFIG_FLOAT
30
+#define RENAME(n) n##_float
31
+
32
+static inline float round_sample(float *sum)
33
+{
34
+    float sum1=*sum;
35
+    *sum = 0;
36
+    return sum1;
37
+}
38
+
39
+#define MACS(rt, ra, rb) rt+=(ra)*(rb)
40
+#define MULS(ra, rb) ((ra)*(rb))
41
+#define MLSS(rt, ra, rb) rt-=(ra)*(rb)
42
+
43
+#else
44
+
45
+#define RENAME(n) n##_fixed
46
+#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
47
+
48
+static inline int round_sample(int64_t *sum)
49
+{
50
+    int sum1;
51
+    sum1 = (int)((*sum) >> OUT_SHIFT);
52
+    *sum &= (1<<OUT_SHIFT)-1;
53
+    return av_clip_int16(sum1);
54
+}
55
+
56
+#   define MULS(ra, rb) MUL64(ra, rb)
57
+#   define MACS(rt, ra, rb) MAC64(rt, ra, rb)
58
+#   define MLSS(rt, ra, rb) MLS64(rt, ra, rb)
59
+#endif
60
+
61
+DECLARE_ALIGNED(16, MPA_INT, RENAME(ff_mpa_synth_window))[512+256];
62
+
63
+#define SUM8(op, sum, w, p)               \
64
+{                                         \
65
+    op(sum, (w)[0 * 64], (p)[0 * 64]);    \
66
+    op(sum, (w)[1 * 64], (p)[1 * 64]);    \
67
+    op(sum, (w)[2 * 64], (p)[2 * 64]);    \
68
+    op(sum, (w)[3 * 64], (p)[3 * 64]);    \
69
+    op(sum, (w)[4 * 64], (p)[4 * 64]);    \
70
+    op(sum, (w)[5 * 64], (p)[5 * 64]);    \
71
+    op(sum, (w)[6 * 64], (p)[6 * 64]);    \
72
+    op(sum, (w)[7 * 64], (p)[7 * 64]);    \
73
+}
74
+
75
+#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
76
+{                                               \
77
+    INTFLOAT tmp;\
78
+    tmp = p[0 * 64];\
79
+    op1(sum1, (w1)[0 * 64], tmp);\
80
+    op2(sum2, (w2)[0 * 64], tmp);\
81
+    tmp = p[1 * 64];\
82
+    op1(sum1, (w1)[1 * 64], tmp);\
83
+    op2(sum2, (w2)[1 * 64], tmp);\
84
+    tmp = p[2 * 64];\
85
+    op1(sum1, (w1)[2 * 64], tmp);\
86
+    op2(sum2, (w2)[2 * 64], tmp);\
87
+    tmp = p[3 * 64];\
88
+    op1(sum1, (w1)[3 * 64], tmp);\
89
+    op2(sum2, (w2)[3 * 64], tmp);\
90
+    tmp = p[4 * 64];\
91
+    op1(sum1, (w1)[4 * 64], tmp);\
92
+    op2(sum2, (w2)[4 * 64], tmp);\
93
+    tmp = p[5 * 64];\
94
+    op1(sum1, (w1)[5 * 64], tmp);\
95
+    op2(sum2, (w2)[5 * 64], tmp);\
96
+    tmp = p[6 * 64];\
97
+    op1(sum1, (w1)[6 * 64], tmp);\
98
+    op2(sum2, (w2)[6 * 64], tmp);\
99
+    tmp = p[7 * 64];\
100
+    op1(sum1, (w1)[7 * 64], tmp);\
101
+    op2(sum2, (w2)[7 * 64], tmp);\
102
+}
103
+
104
+void RENAME(ff_mpadsp_apply_window)(MPA_INT *synth_buf, MPA_INT *window,
105
+                                  int *dither_state, OUT_INT *samples,
106
+                                  int incr)
107
+{
108
+    register const MPA_INT *w, *w2, *p;
109
+    int j;
110
+    OUT_INT *samples2;
111
+#if CONFIG_FLOAT
112
+    float sum, sum2;
113
+#else
114
+    int64_t sum, sum2;
115
+#endif
116
+
117
+    /* copy to avoid wrap */
118
+    memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
119
+
120
+    samples2 = samples + 31 * incr;
121
+    w = window;
122
+    w2 = window + 31;
123
+
124
+    sum = *dither_state;
125
+    p = synth_buf + 16;
126
+    SUM8(MACS, sum, w, p);
127
+    p = synth_buf + 48;
128
+    SUM8(MLSS, sum, w + 32, p);
129
+    *samples = round_sample(&sum);
130
+    samples += incr;
131
+    w++;
132
+
133
+    /* we calculate two samples at the same time to avoid one memory
134
+       access per two sample */
135
+    for(j=1;j<16;j++) {
136
+        sum2 = 0;
137
+        p = synth_buf + 16 + j;
138
+        SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
139
+        p = synth_buf + 48 - j;
140
+        SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
141
+
142
+        *samples = round_sample(&sum);
143
+        samples += incr;
144
+        sum += sum2;
145
+        *samples2 = round_sample(&sum);
146
+        samples2 -= incr;
147
+        w++;
148
+        w2--;
149
+    }
150
+
151
+    p = synth_buf + 32;
152
+    SUM8(MLSS, sum, w + 32, p);
153
+    *samples = round_sample(&sum);
154
+    *dither_state= sum;
155
+}
156
+
157
+/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
158
+   32 samples. */
159
+void RENAME(ff_mpa_synth_filter)(MPADSPContext *s, MPA_INT *synth_buf_ptr,
160
+                                 int *synth_buf_offset,
161
+                                 MPA_INT *window, int *dither_state,
162
+                                 OUT_INT *samples, int incr,
163
+                                 MPA_INT *sb_samples)
164
+{
165
+    MPA_INT *synth_buf;
166
+    int offset;
167
+
168
+    offset = *synth_buf_offset;
169
+    synth_buf = synth_buf_ptr + offset;
170
+
171
+    s->RENAME(dct32)(synth_buf, sb_samples);
172
+    s->RENAME(apply_window)(synth_buf, window, dither_state, samples, incr);
173
+
174
+    offset = (offset - 32) & 511;
175
+    *synth_buf_offset = offset;
176
+}
177
+
178
+void av_cold RENAME(ff_mpa_synth_init)(MPA_INT *window)
179
+{
180
+    int i, j;
181
+
182
+    /* max = 18760, max sum over all 16 coefs : 44736 */
183
+    for(i=0;i<257;i++) {
184
+        INTFLOAT v;
185
+        v = ff_mpa_enwindow[i];
186
+#if CONFIG_FLOAT
187
+        v *= 1.0 / (1LL<<(16 + FRAC_BITS));
188
+#endif
189
+        window[i] = v;
190
+        if ((i & 63) != 0)
191
+            v = -v;
192
+        if (i != 0)
193
+            window[512 - i] = v;
194
+    }
195
+
196
+    // Needed for avoiding shuffles in ASM implementations
197
+    for(i=0; i < 8; i++)
198
+        for(j=0; j < 16; j++)
199
+            window[512+16*i+j] = window[64*i+32-j];
200
+
201
+    for(i=0; i < 8; i++)
202
+        for(j=0; j < 16; j++)
203
+            window[512+128+16*i+j] = window[64*i+48-j];
204
+}
... ...
@@ -21,9 +21,8 @@
21 21
 
22 22
 #include "dsputil_altivec.h"
23 23
 #include "util_altivec.h"
24
-
25
-#define CONFIG_FLOAT 1
26
-#include "libavcodec/mpegaudio.h"
24
+#include "libavcodec/dsputil.h"
25
+#include "libavcodec/mpegaudiodsp.h"
27 26
 
28 27
 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
29 28
 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
... ...
@@ -124,7 +123,7 @@ static void apply_window_mp3(float *in, float *win, int *unused, float *out,
124 124
     *out = sum;
125 125
 }
126 126
 
127
-void ff_mpegaudiodec_init_altivec(MPADecodeContext *s)
127
+void ff_mpadsp_init_altivec(MPADSPContext *s)
128 128
 {
129
-    s->apply_window_mp3 = apply_window_mp3;
129
+    s->apply_window_float = apply_window_mp3;
130 130
 }
... ...
@@ -39,6 +39,7 @@
39 39
 #include "get_bits.h"
40 40
 #include "dsputil.h"
41 41
 #include "rdft.h"
42
+#include "mpegaudiodsp.h"
42 43
 #include "mpegaudio.h"
43 44
 
44 45
 #include "qdm2data.h"
... ...
@@ -170,6 +171,7 @@ typedef struct {
170 170
     float output_buffer[1024];
171 171
 
172 172
     /// Synthesis filter
173
+    MPADSPContext mpadsp;
173 174
     DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512*2];
174 175
     int synth_buf_offset[MPA_MAX_CHANNELS];
175 176
     DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT];
... ...
@@ -1616,7 +1618,8 @@ static void qdm2_synthesis_filter (QDM2Context *q, int index)
1616 1616
         OUT_INT *samples_ptr = samples + ch;
1617 1617
 
1618 1618
         for (i = 0; i < 8; i++) {
1619
-            ff_mpa_synth_filter_fixed(q->synth_buf[ch], &(q->synth_buf_offset[ch]),
1619
+            ff_mpa_synth_filter_fixed(&q->mpadsp,
1620
+                q->synth_buf[ch], &(q->synth_buf_offset[ch]),
1620 1621
                 ff_mpa_synth_window_fixed, &dither_state,
1621 1622
                 samples_ptr, q->nb_channels,
1622 1623
                 q->sb_samples[ch][(8 * index) + i]);
... ...
@@ -1863,6 +1866,7 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
1863 1863
     }
1864 1864
 
1865 1865
     ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R);
1866
+    ff_mpadsp_init(&s->mpadsp);
1866 1867
 
1867 1868
     qdm2_init(s);
1868 1869
 
... ...
@@ -21,9 +21,8 @@
21 21
 
22 22
 #include "libavutil/cpu.h"
23 23
 #include "libavutil/x86_cpu.h"
24
-
25
-#define CONFIG_FLOAT 1
26
-#include "libavcodec/mpegaudio.h"
24
+#include "libavcodec/dsputil.h"
25
+#include "libavcodec/mpegaudiodsp.h"
27 26
 
28 27
 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
29 28
 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
... ...
@@ -148,11 +147,11 @@ static void apply_window_mp3(float *in, float *win, int *unused, float *out,
148 148
     *out = sum;
149 149
 }
150 150
 
151
-void ff_mpegaudiodec_init_mmx(MPADecodeContext *s)
151
+void ff_mpadsp_init_mmx(MPADSPContext *s)
152 152
 {
153 153
     int mm_flags = av_get_cpu_flags();
154 154
 
155 155
     if (mm_flags & AV_CPU_FLAG_SSE2) {
156
-        s->apply_window_mp3 = apply_window_mp3;
156
+        s->apply_window_float = apply_window_mp3;
157 157
     }
158 158
 }