annotate libfaad2/sbr_qmf.c @ 10922:4ee99b640bfb

sync
author nauj27
date Sun, 21 Sep 2003 21:51:38 +0000
parents e989150f8216
children 3185f64f6350
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: sbr_qmf.c,v 1.5 2003/07/29 08:20:13 menno Exp $
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "sbr_dct.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "sbr_qmf.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "sbr_syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 qmfa_info *qmfa_init(uint8_t channels)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 int16_t n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 int size = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 qmfa_info *qmfa = (qmfa_info*)malloc(sizeof(qmfa_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 qmfa->x = (real_t*)malloc(channels * 10 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 memset(qmfa->x, 0, channels * 10 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 qmfa->channels = channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 if (channels == 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 for (n = 0; n < 32; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 qmfa->post_exp_re[n] = cos((M_PI/32.)*(0.75*n + 0.375));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 qmfa->post_exp_im[n] = sin((M_PI/32.)*(0.75*n + 0.375));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 } else if (channels == 64) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 for (n = 0; n < 2*channels; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 qmfa->pre_exp_re[n] = cos(M_PI*n/(2.*channels));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 qmfa->pre_exp_im[n] = sin(M_PI*n/(2.*channels));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 for (n = 0; n < 64; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 qmfa->post_exp_re[n] = cos(M_PI*(2*n+1)/(2.*128.));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 qmfa->post_exp_im[n] = sin(M_PI*(2*n+1)/(2.*128.));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 return qmfa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 void qmfa_end(qmfa_info *qmfa)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 if (qmfa)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 if (qmfa->x) free(qmfa->x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 free(qmfa);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 void sbr_qmf_analysis_32(qmfa_info *qmfa, const real_t *input,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 qmf_t *X, uint8_t offset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 uint8_t l;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 real_t u[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 real_t x[64], y[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 real_t y[32];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 const real_t *inptr = input;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 /* qmf subsample l */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 for (l = 0; l < 32; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 int16_t n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 /* shift input buffer x */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 memmove(qmfa->x + 32, qmfa->x, (320-32)*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 /* add new samples to input buffer x */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 for (n = 32 - 1; n >= 0; n--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 qmfa->x[n] = (*inptr++) >> 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 qmfa->x[n] = *inptr++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 /* window and summation to create array u */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 for (n = 0; n < 64; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 u[n] = MUL_R_C(qmfa->x[n], qmf_c_2[n]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 MUL_R_C(qmfa->x[n + 64], qmf_c_2[n + 64]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 MUL_R_C(qmfa->x[n + 128], qmf_c_2[n + 128]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 MUL_R_C(qmfa->x[n + 192], qmf_c_2[n + 192]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 MUL_R_C(qmfa->x[n + 256], qmf_c_2[n + 256]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 /* calculate 32 subband samples by introducing X */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 y[0] = u[48];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 for (n = 1; n < 16; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 y[n] = u[n+48] + u[48-n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 for (n = 16; n < 32; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 y[n] = -u[n-16] + u[48-n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 DCT3_32_unscaled(u, y);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 for (n = 0; n < 32; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 QMF_RE(X[((l + offset)<<5) + n]) = u[n] << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 QMF_RE(X[((l + offset)<<5) + n]) = 2. * u[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 if (fabs(QMF_RE(X[((l + offset)<<5) + n])) > pow(2,20))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 printf("%f\n", QMF_RE(X[((l + offset)<<5) + n]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 x[0] = u[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 x[63] = u[32];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 for (n = 2; n < 64; n += 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 x[n-1] = u[(n>>1)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 x[n] = -u[64-(n>>1)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 DCT4_64(y, x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 for (n = 0; n < 32; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 QMF_RE(X[((l + offset)<<5) + n]) = y[n] << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 QMF_IM(X[((l + offset)<<5) + n]) = -y[63-n] << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 QMF_RE(X[((l + offset)<<5) + n]) = 2. * y[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 QMF_IM(X[((l + offset)<<5) + n]) = -2. * y[63-n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 if (fabs(QMF_RE(X[((l + offset)<<5) + n])) > pow(2,20))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 printf("%f\n", QMF_RE(X[((l + offset)<<5) + n]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 if (fabs(QMF_IM(X[((l + offset)<<5) + n])) > pow(2,20))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 printf("%f\n", QMF_IM(X[((l + offset)<<5) + n]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 qmfs_info *qmfs_init(uint8_t channels)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 int size = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 qmfs_info *qmfs = (qmfs_info*)malloc(sizeof(qmfs_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 qmfs->v = (real_t*)malloc(channels * 20 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 memset(qmfs->v, 0, channels * 20 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 qmfs->channels = channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 return qmfs;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 void qmfs_end(qmfs_info *qmfs)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 if (qmfs)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 if (qmfs->v) free(qmfs->v);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 free(qmfs);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 void sbr_qmf_synthesis_32(qmfs_info *qmfs, const complex_t *X,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 real_t *output)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 uint8_t l;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 int16_t n, k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 real_t w[320];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 complex_t x[128];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 real_t *outptr = output;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 /* qmf subsample l */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 for (l = 0; l < 32; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 /* shift buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 for (n = 640 - 1; n >= 64; n--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 qmfs->v[n] = qmfs->v[n - 64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 /* calculate 64 samples */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 memset(x, 0, 2*64*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 for (k = 0; k < 32; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 real_t er, ei, Xr, Xi;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 er = qmfs->pre_exp_re[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 ei = qmfs->pre_exp_im[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 Xr = RE(X[l * 32 + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 Xi = IM(X[l * 32 + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 RE(x[k]) = Xr * er - Xi * ei;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 IM(x[k]) = Xi * er + Xr * ei;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 cfftb(qmfs->cffts, x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 for (n = 0; n < 64; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 real_t er, ei;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 er = qmfs->post_exp_re[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 ei = qmfs->post_exp_im[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 qmfs->v[n] = RE(x[n]) * er - IM(x[n]) * ei;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 for (n = 0; n < 5; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 for (k = 0; k < 32; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 w[64 * n + k] = qmfs->v[128 * n + k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 w[64 * n + 32 + k] = qmfs->v[128 * n + 96 + k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 /* window */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 for (n = 0; n < 320; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 w[n] *= qmf_c_2[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 /* calculate 32 output samples */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 for (k = 0; k < 32; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 real_t sample = 0.0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 for (n = 0; n < 10; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 sample += w[32 * n + k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 *outptr++ = sample;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 void sbr_qmf_synthesis_64(qmfs_info *qmfs, const qmf_t *X,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 real_t *output)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 uint8_t l;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 int16_t n, k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 real_t x[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 real_t x1[64], x2[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 real_t *outptr = output;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 /* qmf subsample l */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 for (l = 0; l < 32; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 /* shift buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 memmove(qmfs->v + 128, qmfs->v, (1280-128)*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 /* calculate 128 samples */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 for (k = 0; k < 64; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 x[k] = QMF_RE(X[(l<<6) + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 x[k] = QMF_RE(X[(l<<6) + k]) / 32.;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 DCT2_64_unscaled(x, x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 for (n = 0; n < 64; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 qmfs->v[n+32] = x[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 qmfs->v[0] = qmfs->v[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 for (n = 1; n < 32; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 qmfs->v[32 - n] = qmfs->v[n + 32];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 qmfs->v[n + 96] = -qmfs->v[96 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 for (k = 0; k < 64; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 x1[k] = QMF_RE(X[(l<<6) + k])/64.;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 x2[k] = QMF_IM(X[(l<<6) + k])/64.;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 DCT4_64(x1, x1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 DST4_64(x2, x2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 for (n = 0; n < 64; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 qmfs->v[n] = x2[n] - x1[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 qmfs->v[127-n] = x2[n] + x1[n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 /* calculate 64 output samples and window */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 for (k = 0; k < 64; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 *outptr++ = MUL_R_C(qmfs->v[k], qmf_c[k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 MUL_R_C(qmfs->v[192 + k], qmf_c[64 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 MUL_R_C(qmfs->v[256 + k], qmf_c[128 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 MUL_R_C(qmfs->v[256 + 192 + k], qmf_c[128 + 64 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 MUL_R_C(qmfs->v[512 + k], qmf_c[256 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 MUL_R_C(qmfs->v[512 + 192 + k], qmf_c[256 + 64 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 MUL_R_C(qmfs->v[768 + k], qmf_c[384 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 MUL_R_C(qmfs->v[768 + 192 + k], qmf_c[384 + 64 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 MUL_R_C(qmfs->v[1024 + k], qmf_c[512 + k]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 MUL_R_C(qmfs->v[1024 + 192 + k], qmf_c[512 + 64 + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 #endif