annotate libfaad2/sbr_hfadj.c @ 13153:4fd062533921

fixed the removal of French maintainer of the Doc Nicolas Le Gaillart
author gpoirier
date Thu, 26 Aug 2004 13:32:36 +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_hfadj.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 adjustment */
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_hfadj.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #include "sbr_noise.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
42
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
43 /* static function delcarations */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
44 static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
45 static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
46 static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
47 qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
48 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
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_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
51 static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
52 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
53 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
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_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 ,real_t *deg /* aliasing degree */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 ,uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
62 ALIGN sbr_hfadj_info adj = {{{0}}};
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 map_noise_data(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 map_sinusoids(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 estimate_current_envelope(sbr, &adj, Xsbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 calculate_gain(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 calc_gain_groups(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 aliasing_reduction(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 hf_assembly(sbr, &adj, Xsbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 uint8_t l, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 uint32_t m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 for (i = 0; i < sbr->N_Q; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 for (m = sbr->f_table_noise[i]; m < sbr->f_table_noise[i+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 adj->Q_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 for (k = 0; k < 2; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 if ((sbr->t_E[ch][l] >= sbr->t_Q[ch][k]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 (sbr->t_E[ch][l+1] <= sbr->t_Q[ch][k+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 adj->Q_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 sbr->Q_orig[ch][i][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 uint8_t l, i, m, k, k1, k2, delta_S, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 if (sbr->bs_frame_class[ch] == FIXFIX)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 } else if (sbr->bs_frame_class[ch] == VARFIX) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 if (sbr->bs_pointer[ch] > 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 sbr->l_A[ch] = sbr->bs_pointer[ch] - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 if (sbr->bs_pointer[ch] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 for (l = 0; l < 5; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 for (i = 0; i < 64; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 adj->S_index_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 adj->S_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 for (m = sbr->f_table_res[HI_RES][i]; m < sbr->f_table_res[HI_RES][i+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 uint8_t delta_step = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 if ((l >= sbr->l_A[ch]) || ((sbr->bs_add_harmonic_prev[ch][i]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 (sbr->bs_add_harmonic_flag_prev[ch])))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 delta_step = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 if (m == (int32_t)((real_t)(sbr->f_table_res[HI_RES][i+1]+sbr->f_table_res[HI_RES][i])/2.))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 adj->S_index_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 delta_step * sbr->bs_add_harmonic[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 adj->S_index_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 if (sbr->f[ch][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 k1 = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 k2 = i + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 for (k1 = 0; k1 < sbr->N_low; k1++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 if ((sbr->f_table_res[HI_RES][i] >= sbr->f_table_res[LO_RES][k1]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 (sbr->f_table_res[HI_RES][i+1] <= sbr->f_table_res[LO_RES][k1+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 break;
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 for (k2 = 0; k2 < sbr->N_low; k2++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 if ((sbr->f_table_res[HI_RES][i+1] >= sbr->f_table_res[LO_RES][k2]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 (sbr->f_table_res[HI_RES][i+2] <= sbr->f_table_res[LO_RES][k2+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 l_i = sbr->f_table_res[sbr->f[ch][l]][k1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 u_i = sbr->f_table_res[sbr->f[ch][l]][k2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 delta_S = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 for (k = l_i; k < u_i; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 if (adj->S_index_mapped[k - sbr->kx][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 delta_S = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 for (m = l_i; m < u_i; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 adj->S_mapped[m - sbr->kx][l] = delta_S;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
205 static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
206 qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 uint8_t m, l, j, k, k_l, k_h, p;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 real_t nrg, div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 if (sbr->bs_interpol_freq == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 div = (real_t)(u_i - l_i);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 nrg = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
226 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
228 nrg += MUL_R(QMF_RE(Xsbr[i][m + sbr->kx]), QMF_RE(Xsbr[i][m + sbr->kx]))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 #ifndef SBR_LOW_POWER
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
230 + MUL_R(QMF_IM(Xsbr[i][m + sbr->kx]), QMF_IM(Xsbr[i][m + sbr->kx]))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 ;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 sbr->E_curr[ch][m][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 sbr->E_curr[ch][m][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 for (p = 0; p < sbr->n[sbr->f[ch][l]]; p++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 k_l = sbr->f_table_res[sbr->f[ch][l]][p];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 k_h = sbr->f_table_res[sbr->f[ch][l]][p+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 for (k = k_l; k < k_h; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 nrg = 0.0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
257 div = (real_t)((u_i - l_i)*(k_h - k_l));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
259 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 for (j = k_l; j < k_h; j++)
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 nrg += MUL_R(QMF_RE(Xsbr[i][j]), QMF_RE(Xsbr[i][j]))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 #ifndef SBR_LOW_POWER
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
265 + MUL_R(QMF_IM(Xsbr[i][j]), QMF_IM(Xsbr[i][j]))
10725
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 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 sbr->E_curr[ch][k - sbr->kx][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
281
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
282 #define EPS (1e-12)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 #define ONE (1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 uint8_t m, l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
292 ALIGN real_t Q_M_lim[64];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
293 ALIGN real_t G_lim[64];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
294 ALIGN real_t G_boost;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
295 ALIGN real_t S_M[64];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
296 ALIGN uint8_t table_map_res_to_m[64];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 for (m = sbr->f_table_res[sbr->f[ch][l]][i]; m < sbr->f_table_res[sbr->f[ch][l]][i+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 table_map_res_to_m[m - sbr->kx] = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 real_t G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 real_t den = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 real_t acc1 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 real_t acc2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 acc2 += sbr->E_curr[ch][m][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 G_max = ((EPS + acc1)/(EPS + acc2)) * limGain[sbr->bs_limiter_gains];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 G_max = min(G_max, 1e10);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 real_t d, Q_M, G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 real_t div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 div2 = adj->Q_mapped[m][l] / (1 + adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335 Q_M = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
337 /* 12-Nov: Changed S_mapped to S_index_mapped */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
338 if (adj->S_index_mapped[m][l] == 0)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 S_M[m] = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
341 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
342 real_t div;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
344 div = adj->S_index_mapped[m][l] / (1. + adj->Q_mapped[m][l]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
345 S_M[m] = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
346 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
347
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
348 if (adj->S_mapped[m][l] == 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
349 {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 d = (1 + sbr->E_curr[ch][m][l]) * (1 + delta*adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 G = sbr->E_orig[ch][table_map_res_to_m[m]][l] / d;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 G = (sbr->E_orig[ch][table_map_res_to_m[m]][l] / (1. + sbr->E_curr[ch][m][l])) * div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 /* limit the additional noise energy level */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 /* and apply the limiter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 if (G_max > G)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 Q_M_lim[m] = Q_M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 G_lim[m] = G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 Q_M_lim[m] = Q_M * G_max / G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 G_lim[m] = G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 den += sbr->E_curr[ch][m][l] * G_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 den += S_M[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 else if (l != sbr->l_A[ch])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 den += Q_M_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 G_boost = (acc1 + EPS) / (den + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 /* apply compensation to gain, noise floor sf's and sinusoid levels */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 adj->G_lim_boost[l][m] = sqrt(G_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 /* sqrt() will be done after the aliasing reduction to save a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 * few multiplies
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 adj->G_lim_boost[l][m] = G_lim[m] * G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 adj->Q_M_lim_boost[l][m] = sqrt(Q_M_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 adj->S_M_boost[l][m] = sqrt(S_M[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 adj->S_M_boost[l][m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 uint8_t l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 uint8_t grouping;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 if (deg[k + 1] && adj->S_mapped[k-sbr->kx][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 if (grouping == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 grouping = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 if (adj->S_mapped[k-sbr->kx][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 sbr->f_group[l][i] = k + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 sbr->f_group[l][i] = sbr->kx + sbr->M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 sbr->N_G[l] = (uint8_t)(i >> 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 uint8_t l, k, m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 real_t E_total, E_total_est, G_target, acc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 for (k = 0; k < sbr->N_G[l]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 E_total_est = E_total = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 for (m = sbr->f_group[l][k<<1]; m < sbr->f_group[l][(k<<1) + 1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 /* E_curr: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 /* G_lim_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 /* E_total_est: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 /* E_total: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 E_total_est += sbr->E_curr[ch][m-sbr->kx][l];
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
462 E_total += MUL_R(sbr->E_curr[ch][m-sbr->kx][l], adj->G_lim_boost[l][m-sbr->kx]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 /* G_target: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 if ((E_total_est + EPS) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467 G_target = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 G_target = E_total / (E_total_est + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 for (m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 real_t alpha;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 /* alpha: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 if (m < sbr->kx + sbr->M - 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 alpha = max(deg[m], deg[m + 1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 alpha = deg[m];
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 adj->G_lim_boost[l][m-sbr->kx] = MUL_R(alpha, G_target) +
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
485 MUL_R((REAL_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 /* acc: integer */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
488 acc += MUL_R(adj->G_lim_boost[l][m-sbr->kx], sbr->E_curr[ch][m-sbr->kx][l]);
10725
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 /* acc: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 if (acc + EPS == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 acc = E_total / (acc + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 for(m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
498 adj->G_lim_boost[l][m-sbr->kx] = MUL_R(acc, adj->G_lim_boost[l][m-sbr->kx]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
518 qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 static real_t h_smooth[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 COEF_CONST(0.03183050093751), COEF_CONST(0.11516383427084),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 COEF_CONST(0.21816949906249), COEF_CONST(0.30150283239582),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 COEF_CONST(0.33333333333333)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 static int8_t phi_re[] = { 1, 0, -1, 0 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 static int8_t phi_im[] = { 0, 1, 0, -1 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 uint8_t m, l, i, n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529 uint16_t fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530 uint8_t fIndexSine = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 uint8_t assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 real_t *temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 real_t G_filt, Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 uint8_t h_SL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 if (sbr->Reset == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 assembly_reset = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 fIndexNoise = sbr->index_noise_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 fIndexSine = sbr->psi_is_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
547
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551 uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554 h_SL = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 h_SL = (no_noise ? 0 : h_SL);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 if (assembly_reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
562 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
563 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 memcpy(sbr->G_temp_prev[ch][n], adj->G_lim_boost[l], sbr->M*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 memcpy(sbr->Q_temp_prev[ch][n], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567 assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l+1]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
573 uint8_t i_min1, i_plus1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
574 uint8_t sinusoids = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 memcpy(sbr->G_temp_prev[ch][4], adj->G_lim_boost[l], sbr->M*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578 memcpy(sbr->Q_temp_prev[ch][4], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
582 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
583 qmf_t psi;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
584
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
585
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586 G_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587 Q_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588 j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 if (h_SL != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592 for (n = 0; n <= 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
593 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
594 G_filt += MUL_C(sbr->G_temp_prev[ch][n][m], h_smooth[j]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
595 Q_filt += MUL_C(sbr->Q_temp_prev[ch][n][m], h_smooth[j]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
596 j++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
598 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 G_filt = sbr->G_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600 Q_filt = sbr->Q_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603 Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 /* add noise to the output */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 fIndexNoise = (fIndexNoise + 1) & 511;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
608 /* the smoothed gain values are applied to Xsbr */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609 /* V is defined, not calculated */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
610 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
611 + MUL_F(Q_filt, RE(V[fIndexNoise]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
612 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42)
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
613 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = 16428320;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 #ifndef SBR_LOW_POWER
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
615 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) = MUL_R(G_filt, QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]))
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
616 + MUL_F(Q_filt, IM(V[fIndexNoise]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
618
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
619 //if (adj->S_index_mapped[m][l])
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
620 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
621 int8_t rev = (((m + sbr->kx) & 1) ? -1 : 1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
622 QMF_RE(psi) = MUL_R(adj->S_M_boost[l][m], phi_re[fIndexSine]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
623 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += QMF_RE(psi);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625 #ifndef SBR_LOW_POWER
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
626 QMF_IM(psi) = rev * MUL_R(adj->S_M_boost[l][m], phi_im[fIndexSine]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
627 QMF_IM(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) += QMF_IM(psi);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
629 i_min1 = (fIndexSine - 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 i_plus1 = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
632 if (m == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
634 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx - 1]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
635 (-1*rev * MUL_C(MUL_R(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
636 if(m < sbr->M - 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
637 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
638 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
639 (rev * MUL_C(MUL_R(adj->S_M_boost[l][1], phi_re[i_plus1]), COEF_CONST(0.00815)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
640 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
641 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
642 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
643 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
644 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
645 (rev * MUL_C(MUL_R(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
646 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
647 (rev * MUL_C(MUL_R(adj->S_M_boost[l][m + 1], phi_re[i_plus1]), COEF_CONST(0.00815)));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
648 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
649 if ((m == sbr->M - 1) && (sinusoids < 16))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
650 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
651 if (m > 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
652 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
653 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
654 (rev * MUL_C(MUL_R(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
655 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
656 if (m + sbr->kx < 64)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
657 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
658 QMF_RE(Xsbr[i + sbr->tHFAdj][m+sbr->kx + 1]) -=
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
659 (-1*rev * MUL_C(MUL_R(adj->S_M_boost[l][m], phi_re[i_min1]), COEF_CONST(0.00815)));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
660 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
663 if (adj->S_M_boost[l][m] != 0)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
664 sinusoids++;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
665 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
666 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
667 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
668
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
669 fIndexSine = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
670
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
671
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
672 temp = sbr->G_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
673 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
674 sbr->G_temp_prev[ch][n] = sbr->G_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
675 sbr->G_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
676
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
677 temp = sbr->Q_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
678 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
679 sbr->Q_temp_prev[ch][n] = sbr->Q_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
680 sbr->Q_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
681 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
682 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
683
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
684 sbr->index_noise_prev[ch] = fIndexNoise;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
685 sbr->psi_is_prev[ch] = fIndexSine;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
686 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
687
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
688 #endif