Browse code

Split out common routines needed in the atrac1 decoder from atrac3.c to atrac.c.

Originally committed as revision 19796 to svn://svn.ffmpeg.org/ffmpeg/trunk

Benjamin Larsson authored on 2009/09/09 04:25:54
Showing 4 changed files
... ...
@@ -48,7 +48,7 @@ OBJS-$(CONFIG_ASV1_DECODER)            += asv1.o mpeg12data.o
48 48
 OBJS-$(CONFIG_ASV1_ENCODER)            += asv1.o mpeg12data.o
49 49
 OBJS-$(CONFIG_ASV2_DECODER)            += asv1.o mpeg12data.o
50 50
 OBJS-$(CONFIG_ASV2_ENCODER)            += asv1.o mpeg12data.o
51
-OBJS-$(CONFIG_ATRAC3_DECODER)          += atrac3.o
51
+OBJS-$(CONFIG_ATRAC3_DECODER)          += atrac3.o atrac.o
52 52
 OBJS-$(CONFIG_AVS_DECODER)             += avs.o
53 53
 OBJS-$(CONFIG_BETHSOFTVID_DECODER)     += bethsoftvideo.o
54 54
 OBJS-$(CONFIG_BFI_DECODER)             += bfi.o
55 55
new file mode 100644
... ...
@@ -0,0 +1,119 @@
0
+/*
1
+ * Atrac common functions
2
+ * Copyright (c) 2006-2008 Maxim Poliakovski
3
+ * Copyright (c) 2006-2008 Benjamin Larsson
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file libavcodec/atrac.c
24
+ */
25
+
26
+#include <math.h>
27
+#include <stddef.h>
28
+#include <stdio.h>
29
+
30
+#include "avcodec.h"
31
+#include "dsputil.h"
32
+
33
+float sf_table[64];
34
+float qmf_window[48];
35
+
36
+static const float qmf_48tap_half[24] = {
37
+   -0.00001461907, -0.00009205479,-0.000056157569,0.00030117269,
38
+    0.0002422519,  -0.00085293897,-0.0005205574,  0.0020340169,
39
+    0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,
40
+   -0.000061169922,-0.01344162,    0.0024626821,  0.021736089,
41
+   -0.007801671,   -0.034090221,   0.01880949,    0.054326009,
42
+   -0.043596379,   -0.099384367,   0.13207909,    0.46424159
43
+};
44
+
45
+/**
46
+ * Generate common tables
47
+ */
48
+
49
+void atrac_generate_tables(void)
50
+{
51
+    int i;
52
+    float s;
53
+
54
+    /* Generate scale factors */
55
+    if (!sf_table[63])
56
+        for (i=0 ; i<64 ; i++)
57
+            sf_table[i] = pow(2.0, (i - 15) / 3.0);
58
+
59
+    /* Generate the QMF window. */
60
+    if (!qmf_window[47])
61
+        for (i=0 ; i<24; i++) {
62
+            s = qmf_48tap_half[i] * 2.0;
63
+            qmf_window[i] = qmf_window[47 - i] = s;
64
+        }
65
+}
66
+
67
+
68
+/**
69
+ * Quadrature mirror synthesis filter.
70
+ *
71
+ * @param inlo      lower part of spectrum
72
+ * @param inhi      higher part of spectrum
73
+ * @param nIn       size of spectrum buffer
74
+ * @param pOut      out buffer
75
+ * @param delayBuf  delayBuf buffer
76
+ * @param temp      temp buffer
77
+ */
78
+
79
+
80
+void atrac_iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
81
+{
82
+    int   i, j;
83
+    float   *p1, *p3;
84
+
85
+    memcpy(temp, delayBuf, 46*sizeof(float));
86
+
87
+    p3 = temp + 46;
88
+
89
+    /* loop1 */
90
+    for(i=0; i<nIn; i+=2){
91
+        p3[2*i+0] = inlo[i  ] + inhi[i  ];
92
+        p3[2*i+1] = inlo[i  ] - inhi[i  ];
93
+        p3[2*i+2] = inlo[i+1] + inhi[i+1];
94
+        p3[2*i+3] = inlo[i+1] - inhi[i+1];
95
+    }
96
+
97
+    /* loop2 */
98
+    p1 = temp;
99
+    for (j = nIn; j != 0; j--) {
100
+        float s1 = 0.0;
101
+        float s2 = 0.0;
102
+
103
+        for (i = 0; i < 48; i += 2) {
104
+            s1 += p1[i] * qmf_window[i];
105
+            s2 += p1[i+1] * qmf_window[i+1];
106
+        }
107
+
108
+        pOut[0] = s2;
109
+        pOut[1] = s1;
110
+
111
+        p1 += 2;
112
+        pOut += 2;
113
+    }
114
+
115
+    /* Update the delay buffer. */
116
+    memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
117
+}
118
+
0 119
new file mode 100644
... ...
@@ -0,0 +1,38 @@
0
+/*
1
+ * Atrac common data
2
+ * Copyright (c) 2009 Maxim Poliakovski
3
+ * Copyright (c) 2009 Benjamin Larsson
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file libavcodec/atrac1data.h
24
+ * Atrac 1 compatible decoder data
25
+ */
26
+
27
+#ifndef AVCODEC_ATRAC_H
28
+#define AVCODEC_ATRAC_H
29
+
30
+
31
+extern float sf_table[64];
32
+extern float qmf_window[48];
33
+
34
+void atrac_generate_tables(void);
35
+void atrac_iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp);
36
+
37
+#endif /* AVCODEC_ATRAC_H */
... ...
@@ -41,6 +41,7 @@
41 41
 #include "dsputil.h"
42 42
 #include "bytestream.h"
43 43
 
44
+#include "atrac.h"
44 45
 #include "atrac3data.h"
45 46
 
46 47
 #define JOINT_STEREO    0x12
... ...
@@ -119,68 +120,13 @@ typedef struct {
119 119
 } ATRAC3Context;
120 120
 
121 121
 static DECLARE_ALIGNED_16(float,mdct_window[512]);
122
-static float            qmf_window[48];
123 122
 static VLC              spectral_coeff_tab[7];
124
-static float            SFTable[64];
125 123
 static float            gain_tab1[16];
126 124
 static float            gain_tab2[31];
127 125
 static MDCTContext      mdct_ctx;
128 126
 static DSPContext       dsp;
129 127
 
130 128
 
131
-/* quadrature mirror synthesis filter */
132
-
133
-/**
134
- * Quadrature mirror synthesis filter.
135
- *
136
- * @param inlo      lower part of spectrum
137
- * @param inhi      higher part of spectrum
138
- * @param nIn       size of spectrum buffer
139
- * @param pOut      out buffer
140
- * @param delayBuf  delayBuf buffer
141
- * @param temp      temp buffer
142
- */
143
-
144
-
145
-static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
146
-{
147
-    int   i, j;
148
-    float   *p1, *p3;
149
-
150
-    memcpy(temp, delayBuf, 46*sizeof(float));
151
-
152
-    p3 = temp + 46;
153
-
154
-    /* loop1 */
155
-    for(i=0; i<nIn; i+=2){
156
-        p3[2*i+0] = inlo[i  ] + inhi[i  ];
157
-        p3[2*i+1] = inlo[i  ] - inhi[i  ];
158
-        p3[2*i+2] = inlo[i+1] + inhi[i+1];
159
-        p3[2*i+3] = inlo[i+1] - inhi[i+1];
160
-    }
161
-
162
-    /* loop2 */
163
-    p1 = temp;
164
-    for (j = nIn; j != 0; j--) {
165
-        float s1 = 0.0;
166
-        float s2 = 0.0;
167
-
168
-        for (i = 0; i < 48; i += 2) {
169
-            s1 += p1[i] * qmf_window[i];
170
-            s2 += p1[i+1] * qmf_window[i+1];
171
-        }
172
-
173
-        pOut[0] = s2;
174
-        pOut[1] = s1;
175
-
176
-        p1 += 2;
177
-        pOut += 2;
178
-    }
179
-
180
-    /* Update the delay buffer. */
181
-    memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));
182
-}
183
-
184 129
 /**
185 130
  * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands
186 131
  * caused by the reverse spectra of the QMF.
... ...
@@ -386,7 +332,7 @@ static int decodeSpectrum (GetBitContext *gb, float *pOut)
386 386
             readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth);
387 387
 
388 388
             /* Decode the scale factor for this subband. */
389
-            SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]];
389
+            SF = sf_table[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]];
390 390
 
391 391
             /* Inverse quantize the coefficients. */
392 392
             for (pIn=mantissas ; first<last; first++, pIn++)
... ...
@@ -459,7 +405,7 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent
459 459
                 coded_values = coded_values_per_component + 1;
460 460
                 coded_values = FFMIN(max_coded_values,coded_values);
461 461
 
462
-                scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index];
462
+                scalefactor = sf_table[sfIndx] * iMaxQuant[quant_step_index];
463 463
 
464 464
                 readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values);
465 465
 
... ...
@@ -860,9 +806,9 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf)
860 860
         p2= p1+256;
861 861
         p3= p2+256;
862 862
         p4= p3+256;
863
-        iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf);
864
-        iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf);
865
-        iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf);
863
+        atrac_iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf);
864
+        atrac_iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf);
865
+        atrac_iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf);
866 866
         p1 +=1024;
867 867
     }
868 868
 
... ...
@@ -1038,9 +984,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
1038 1038
 
1039 1039
     init_atrac3_transforms(q);
1040 1040
 
1041
-    /* Generate the scale factors. */
1042
-    for (i=0 ; i<64 ; i++)
1043
-        SFTable[i] = pow(2.0, (i - 15) / 3.0);
1041
+    atrac_generate_tables();
1044 1042
 
1045 1043
     /* Generate gain tables. */
1046 1044
     for (i=0 ; i<16 ; i++)