annotate libfaad2/sbr_hfgen.c @ 11676:bc22491f91bf

Remove 8BPS, MsRLE, MsVideo1, RPZA, SMC These codecs are now in libavcodec
author rtognimp
date Tue, 23 Dec 2003 21:24:14 +0000
parents 3185f64f6350
children 4a370c80fe5c
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 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: sbr_hfgen.c,v 1.6 2003/09/25 12:04:31 menno Exp $
10725
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 /* High Frequency generation */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "sbr_syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "sbr_hfgen.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "sbr_fbt.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
39 void hf_generation(sbr_info *sbr, const qmf_t *Xlow,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 qmf_t *Xhigh
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 ,real_t *deg
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 ,uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 uint8_t l, i, x;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
47 uint8_t offset, first, last;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 complex_t alpha_0[64], alpha_1[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 real_t rxx[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
53 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
54 if (sbr->Is_DRM_SBR)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
55 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
56 offset = sbr->tHFGen;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
57 first = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
58 last = sbr->numTimeSlotsRate;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
59 } else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
60 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
61 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
62 offset = sbr->tHFAdj;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
63 first = sbr->t_E[ch][0];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
64 last = sbr->t_E[ch][sbr->L_E[ch]];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
65 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 calc_chirp_factors(sbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 if ((ch == 0) && (sbr->Reset))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 patch_construction(sbr);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 /* calculate the prediction coefficients */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 calc_prediction_coef(sbr, Xlow, alpha_0, alpha_1
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 , rxx
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 calc_aliasing_degree(sbr, rxx, deg);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 /* actual HF generation */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 for (i = 0; i < sbr->noPatches; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 for (x = 0; x < sbr->patchNoSubbands[i]; x++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 complex_t a0, a1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 real_t bw, bw2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 uint8_t q, p, k, g;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 /* find the low and high band for patching */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 k = sbr->kx + x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 for (q = 0; q < i; q++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 k += sbr->patchNoSubbands[q];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 p = sbr->patchStartSubband[i] + x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 if (x != 0 /*x < sbr->patchNoSubbands[i]-1*/)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 deg[k] = deg[p];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 deg[k] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 g = sbr->table_map_k_to_g[k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 bw = sbr->bwArray[ch][g];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 bw2 = MUL_C_C(bw, bw);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
112
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 /* do the patching */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 /* with or without filtering */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 if (bw2 > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 RE(a0) = MUL_R_C(RE(alpha_0[p]), bw);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 RE(a1) = MUL_R_C(RE(alpha_1[p]), bw2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 IM(a0) = MUL_R_C(IM(alpha_0[p]), bw);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 IM(a1) = MUL_R_C(IM(alpha_1[p]), bw2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
124 for (l = first; l < last; l++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
126 QMF_RE(Xhigh[((l + offset)<<6) + k]) = QMF_RE(Xlow[((l + offset)<<5) + p]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 #ifndef SBR_LOW_POWER
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
128 QMF_IM(Xhigh[((l + offset)<<6) + k]) = QMF_IM(Xlow[((l + offset)<<5) + p]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 #ifdef SBR_LOW_POWER
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
132 QMF_RE(Xhigh[((l + offset)<<6) + k]) += (
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
133 MUL(RE(a0), QMF_RE(Xlow[((l - 1 + offset)<<5) + p])) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
134 MUL(RE(a1), QMF_RE(Xlow[((l - 2 + offset)<<5) + p])));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 #else
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
136 QMF_RE(Xhigh[((l + offset)<<6) + k]) += (
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
137 RE(a0) * QMF_RE(Xlow[((l - 1 + offset)<<5) + p]) -
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
138 IM(a0) * QMF_IM(Xlow[((l - 1 + offset)<<5) + p]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
139 RE(a1) * QMF_RE(Xlow[((l - 2 + offset)<<5) + p]) -
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
140 IM(a1) * QMF_IM(Xlow[((l - 2 + offset)<<5) + p]));
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
141 QMF_IM(Xhigh[((l + offset)<<6) + k]) += (
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
142 IM(a0) * QMF_RE(Xlow[((l - 1 + offset)<<5) + p]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
143 RE(a0) * QMF_IM(Xlow[((l - 1 + offset)<<5) + p]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
144 IM(a1) * QMF_RE(Xlow[((l - 2 + offset)<<5) + p]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
145 RE(a1) * QMF_IM(Xlow[((l - 2 + offset)<<5) + p]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
149 for (l = first; l < last; l++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
151 QMF_RE(Xhigh[((l + offset)<<6) + k]) = QMF_RE(Xlow[((l + offset)<<5) + p]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 #ifndef SBR_LOW_POWER
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
153 QMF_IM(Xhigh[((l + offset)<<6) + k]) = QMF_IM(Xlow[((l + offset)<<5) + p]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 if (sbr->Reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 limiter_frequency_table(sbr);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 typedef struct
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 complex_t r01;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 complex_t r02;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 complex_t r11;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 complex_t r12;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 complex_t r22;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 real_t det;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 } acorr_coef;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 #define SBR_ABS(A) ((A) < 0) ? -(A) : (A)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
178 #ifdef SBR_LOW_POWER
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
179 static void auto_correlation(sbr_info *sbr, acorr_coef *ac, const qmf_t *buffer,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 uint8_t bd, uint8_t len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 int8_t j, jminus1, jminus2;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
183 uint8_t offset;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
184 real_t r01, i01, r11;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
185 const real_t rel = 1 / (1 + 1e-6f);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
187 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
188 if (sbr->Is_DRM_SBR)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
189 offset = sbr->tHFGen;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
190 else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
191 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
193 offset = sbr->tHFAdj;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 memset(ac, 0, sizeof(acorr_coef));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
198 r01 = QMF_RE(buffer[(offset-1)*32 + bd]) * QMF_RE(buffer[(offset-2)*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
199 r11 = QMF_RE(buffer[(offset-2)*32 + bd]) * QMF_RE(buffer[(offset-2)*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
200
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
201 for (j = offset; j < len + offset; j++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 jminus1 = j - 1;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
204 jminus2 = j - 2;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
206 RE(ac->r12) += r01;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
207 r01 = QMF_RE(buffer[j*32 + bd]) * QMF_RE(buffer[jminus1*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
208 RE(ac->r01) += r01;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
209 RE(ac->r02) += QMF_RE(buffer[j*32 + bd]) * QMF_RE(buffer[jminus2*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
210 RE(ac->r22) += r11;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
211 r11 = QMF_RE(buffer[jminus1*32 + bd]) * QMF_RE(buffer[jminus1*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
212 RE(ac->r11) += r11;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
213 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
214
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
215 ac->det = MUL(RE(ac->r11), RE(ac->r22)) - MUL_R_C(MUL(RE(ac->r12), RE(ac->r12)), rel);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
216 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 #else
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
218 static void auto_correlation(sbr_info *sbr, acorr_coef *ac, const qmf_t *buffer,
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
219 uint8_t bd, uint8_t len)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
220 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
221 int8_t j, jminus1, jminus2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
222 uint8_t offset;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
223 real_t r01, i01, r11;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
224 const real_t rel = 1 / (1 + 1e-6f);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
225
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
226 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
227 if (sbr->Is_DRM_SBR)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
228 offset = sbr->tHFGen;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
229 else
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
231 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
232 offset = sbr->tHFAdj;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
233 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
234
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
235 memset(ac, 0, sizeof(acorr_coef));
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
236
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
237 r01 = QMF_RE(buffer[(offset-1)*32 + bd]) * QMF_RE(buffer[(offset-2)*32 + bd]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
238 QMF_IM(buffer[(offset-1)*32 + bd]) * QMF_IM(buffer[(offset-2)*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
239 i01 = QMF_IM(buffer[(offset-1)*32 + bd]) * QMF_RE(buffer[(offset-2)*32 + bd]) -
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
240 QMF_RE(buffer[(offset-1)*32 + bd]) * QMF_IM(buffer[(offset-2)*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
241 r11 = QMF_RE(buffer[(offset-2)*32 + bd]) * QMF_RE(buffer[(offset-2)*32 + bd]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
242 QMF_IM(buffer[(offset-2)*32 + bd]) * QMF_IM(buffer[(offset-2)*32 + bd]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
244 for (j = offset; j < len + offset; j++)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
245 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
246 jminus1 = j - 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
247 jminus2 = j - 2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
248
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
249 RE(ac->r12) += r01;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
250 IM(ac->r12) += i01;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
251 r01 = QMF_RE(buffer[j*32 + bd]) * QMF_RE(buffer[jminus1*32 + bd]) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
252 QMF_IM(buffer[j*32 + bd]) * QMF_IM(buffer[jminus1*32 + bd]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
253 RE(ac->r01) += r01;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
254 i01 = QMF_IM(buffer[j*32 + bd]) * QMF_RE(buffer[jminus1*32 + bd]) -
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 QMF_RE(buffer[j*32 + bd]) * QMF_IM(buffer[jminus1*32 + bd]);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
256 IM(ac->r01) += i01;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 RE(ac->r02) += QMF_RE(buffer[j*32 + bd]) * QMF_RE(buffer[jminus2*32 + bd]) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 QMF_IM(buffer[j*32 + bd]) * QMF_IM(buffer[jminus2*32 + bd]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 IM(ac->r02) += QMF_IM(buffer[j*32 + bd]) * QMF_RE(buffer[jminus2*32 + bd]) -
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 QMF_RE(buffer[j*32 + bd]) * QMF_IM(buffer[jminus2*32 + bd]);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
261 RE(ac->r22) += r11;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
262 r11 = QMF_RE(buffer[jminus1*32 + bd]) * QMF_RE(buffer[jminus1*32 + bd]) +
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 QMF_IM(buffer[jminus1*32 + bd]) * QMF_IM(buffer[jminus1*32 + bd]);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
264 RE(ac->r11) += r11;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 ac->det = RE(ac->r11) * RE(ac->r22) - rel * (RE(ac->r12) * RE(ac->r12) + IM(ac->r12) * IM(ac->r12));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
268 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
271 static void calc_prediction_coef(sbr_info *sbr, const qmf_t *Xlow,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 complex_t *alpha_0, complex_t *alpha_1
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 , real_t *rxx
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 real_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 acorr_coef ac;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
282 for (k = 1; k < sbr->f_master[0]; k++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
284 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
285 if (sbr->Is_DRM_SBR)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
286 auto_correlation(sbr, &ac, Xlow, k, 30);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
287 else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
288 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
289 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
290 auto_correlation(sbr, &ac, Xlow, k, 38);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
291 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 if (ac.det == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 RE(alpha_1[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 tmp = MUL(RE(ac.r01), RE(ac.r12)) - MUL(RE(ac.r02), RE(ac.r11));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 RE(alpha_1[k]) = SBR_DIV(tmp, ac.det);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 if (RE(ac.r11) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 RE(alpha_0[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 tmp = RE(ac.r01) + MUL(RE(alpha_1[k]), RE(ac.r12));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 RE(alpha_0[k]) = -SBR_DIV(tmp, RE(ac.r11));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 if ((RE(alpha_0[k]) >= REAL_CONST(4)) || (RE(alpha_1[k]) >= REAL_CONST(4)))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 RE(alpha_0[k]) = REAL_CONST(0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 RE(alpha_1[k]) = REAL_CONST(0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 /* reflection coefficient */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 if (RE(ac.r11) == REAL_CONST(0.0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 rxx[k] = REAL_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 rxx[k] = -SBR_DIV(RE(ac.r01), RE(ac.r11));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 if (rxx[k] > REAL_CONST(1.0)) rxx[k] = REAL_CONST(1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 if (rxx[k] < REAL_CONST(-1.0)) rxx[k] = REAL_CONST(-1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 if (ac.det == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 RE(alpha_1[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 IM(alpha_1[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
331 tmp = REAL_CONST(1.0) / ac.det;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 RE(alpha_1[k]) = (RE(ac.r01) * RE(ac.r12) - IM(ac.r01) * IM(ac.r12) - RE(ac.r02) * RE(ac.r11)) * tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 IM(alpha_1[k]) = (IM(ac.r01) * RE(ac.r12) + RE(ac.r01) * IM(ac.r12) - IM(ac.r02) * RE(ac.r11)) * tmp;
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 if (RE(ac.r11) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 RE(alpha_0[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 IM(alpha_0[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 tmp = 1.0f / RE(ac.r11);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 RE(alpha_0[k]) = -(RE(ac.r01) + RE(alpha_1[k]) * RE(ac.r12) + IM(alpha_1[k]) * IM(ac.r12)) * tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 IM(alpha_0[k]) = -(IM(ac.r01) + IM(alpha_1[k]) * RE(ac.r12) - RE(alpha_1[k]) * IM(ac.r12)) * tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 if ((RE(alpha_0[k])*RE(alpha_0[k]) + IM(alpha_0[k])*IM(alpha_0[k]) >= 16) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 (RE(alpha_1[k])*RE(alpha_1[k]) + IM(alpha_1[k])*IM(alpha_1[k]) >= 16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 RE(alpha_0[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 IM(alpha_0[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 RE(alpha_1[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 IM(alpha_1[k]) = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 static void calc_aliasing_degree(sbr_info *sbr, real_t *rxx, real_t *deg)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 rxx[0] = REAL_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 deg[1] = REAL_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 for (k = 2; k < sbr->k0; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 deg[k] = 0.0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 if ((k % 2 == 0) && (rxx[k] < REAL_CONST(0.0)))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 if (rxx[k-1] < 0.0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 deg[k] = REAL_CONST(1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376 if (rxx[k-2] > REAL_CONST(0.0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 deg[k-1] = REAL_CONST(1.0) - MUL(rxx[k-1], rxx[k-1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 } else if (rxx[k-2] > REAL_CONST(0.0)) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 deg[k] = REAL_CONST(1.0) - MUL(rxx[k-1], rxx[k-1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 if ((k % 2 == 1) && (rxx[k] > REAL_CONST(0.0)))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 if (rxx[k-1] > REAL_CONST(0.0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 deg[k] = REAL_CONST(1.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 if (rxx[k-2] < REAL_CONST(0.0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 deg[k-1] = REAL_CONST(1.0) - MUL(rxx[k-1], rxx[k-1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 } else if (rxx[k-2] < REAL_CONST(0.0)) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 deg[k] = REAL_CONST(1.0) - MUL(rxx[k-1], rxx[k-1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 static real_t mapNewBw(uint8_t invf_mode, uint8_t invf_mode_prev)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 switch (invf_mode)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 case 1: /* LOW */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 if (invf_mode_prev == 0) /* NONE */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 return COEF_CONST(0.6);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 return COEF_CONST(0.75);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 case 2: /* MID */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 return COEF_CONST(0.9);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 case 3: /* HIGH */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 return COEF_CONST(0.98);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 default: /* NONE */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 if (invf_mode_prev == 1) /* LOW */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 return COEF_CONST(0.6);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 return COEF_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 static void calc_chirp_factors(sbr_info *sbr, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 for (i = 0; i < sbr->N_Q; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 sbr->bwArray[ch][i] = mapNewBw(sbr->bs_invf_mode[ch][i], sbr->bs_invf_mode_prev[ch][i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 if (sbr->bwArray[ch][i] < sbr->bwArray_prev[ch][i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 sbr->bwArray[ch][i] = MUL_C_C(COEF_CONST(0.75), sbr->bwArray[ch][i]) + MUL_C_C(COEF_CONST(0.25), sbr->bwArray_prev[ch][i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 sbr->bwArray[ch][i] = MUL_C_C(COEF_CONST(0.90625), sbr->bwArray[ch][i]) + MUL_C_C(COEF_CONST(0.09375), sbr->bwArray_prev[ch][i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 if (sbr->bwArray[ch][i] < COEF_CONST(0.015625))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 sbr->bwArray[ch][i] = COEF_CONST(0.0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 if (sbr->bwArray[ch][i] >= COEF_CONST(0.99609375))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 sbr->bwArray[ch][i] = COEF_CONST(0.99609375);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 sbr->bwArray_prev[ch][i] = sbr->bwArray[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 sbr->bs_invf_mode_prev[ch][i] = sbr->bs_invf_mode[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 static void patch_construction(sbr_info *sbr)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 uint8_t i, k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454 uint8_t odd, sb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 uint8_t msb = sbr->k0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 uint8_t usb = sbr->kx;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
457 uint8_t goalSb = (uint8_t)(2.048e6/sbr->sample_rate + 0.5);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 sbr->noPatches = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 if (goalSb < (sbr->kx + sbr->M))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 for (i = 0, k = 0; sbr->f_master[i] < goalSb; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 k = i+1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 k = sbr->N_master;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 do
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 uint8_t j = k + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 do
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 j--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 sb = sbr->f_master[j];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 odd = (sb - 2 + sbr->k0) % 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 } while (sb > (sbr->k0 - 1 + msb - odd));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 sbr->patchNoSubbands[sbr->noPatches] = max(sb - usb, 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 sbr->patchStartSubband[sbr->noPatches] = sbr->k0 - odd -
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 sbr->patchNoSubbands[sbr->noPatches];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 if (sbr->patchNoSubbands[sbr->noPatches] > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 usb = sb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 msb = sb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 sbr->noPatches++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 msb = sbr->kx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 if (sb == sbr->f_master[k])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 k = sbr->N_master;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 } while (sb != (sbr->kx + sbr->M));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
498 if ((sbr->patchNoSubbands[sbr->noPatches-1] < 3) && (sbr->noPatches > 1))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 sbr->noPatches--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 sbr->noPatches = min(sbr->noPatches, 5);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 #endif