annotate libfaad2/sbr_hfgen.c @ 13232:4b7b0cb1d6f3

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