annotate libfaad2/sbr_hfgen.c @ 12574:39de828ec1cb

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