annotate libfaad2/sbr_hfadj.c @ 10764:06ebe990fa92

Ignore .depend.
author diego
date Sun, 31 Aug 2003 23:07:28 +0000
parents e989150f8216
children 3185f64f6350
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: sbr_hfadj.c,v 1.1 2003/07/29 08:20:13 menno Exp $
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 /* High Frequency adjustment */
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_hfadj.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "sbr_noise.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 void hf_adjustment(sbr_info *sbr, qmf_t *Xsbr
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 ,real_t *deg /* aliasing degree */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 ,uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 sbr_hfadj_info adj;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 memset(&adj, 0, sizeof(sbr_hfadj_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 map_noise_data(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 map_sinusoids(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 estimate_current_envelope(sbr, &adj, Xsbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 calculate_gain(sbr, &adj, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 #if 1
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 calc_gain_groups(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 aliasing_reduction(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 hf_assembly(sbr, &adj, Xsbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 uint8_t l, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 uint32_t m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 for (i = 0; i < sbr->N_Q; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 for (m = sbr->f_table_noise[i]; m < sbr->f_table_noise[i+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 adj->Q_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 for (k = 0; k < 2; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 if ((sbr->t_E[ch][l] >= sbr->t_Q[ch][k]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 (sbr->t_E[ch][l+1] <= sbr->t_Q[ch][k+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 adj->Q_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 sbr->Q_orig[ch][i][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 uint8_t l, i, m, k, k1, k2, delta_S, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 if (sbr->bs_frame_class[ch] == FIXFIX)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 } else if (sbr->bs_frame_class[ch] == VARFIX) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 if (sbr->bs_pointer[ch] > 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 sbr->l_A[ch] = sbr->bs_pointer[ch] - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 if (sbr->bs_pointer[ch] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 for (l = 0; l < 5; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 for (i = 0; i < 64; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 adj->S_index_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 adj->S_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 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
131 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 uint8_t delta_step = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 if ((l >= sbr->l_A[ch]) || ((sbr->bs_add_harmonic_prev[ch][i]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 (sbr->bs_add_harmonic_flag_prev[ch])))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 delta_step = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 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
140 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 adj->S_index_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 delta_step * sbr->bs_add_harmonic[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 adj->S_index_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 if (sbr->frame == 95)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 printf("%d %d %d %d %d\n", adj->S_index_mapped[m - sbr->kx][l],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 sbr->bs_add_harmonic[ch][i], sbr->bs_add_harmonic_prev[ch][i],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 l, sbr->l_A[ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 if (sbr->f[ch][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 k1 = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 k2 = i + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 for (k1 = 0; k1 < sbr->N_low; k1++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 if ((sbr->f_table_res[HI_RES][i] >= sbr->f_table_res[LO_RES][k1]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 (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
172 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 break;
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 for (k2 = 0; k2 < sbr->N_low; k2++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 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
179 (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
180 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 }
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 l_i = sbr->f_table_res[sbr->f[ch][l]][k1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 u_i = sbr->f_table_res[sbr->f[ch][l]][k2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 delta_S = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 for (k = l_i; k < u_i; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 if (adj->S_index_mapped[k - sbr->kx][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 delta_S = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 for (m = l_i; m < u_i; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 adj->S_mapped[m - sbr->kx][l] = delta_S;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 }
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 static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t *Xsbr,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 uint8_t m, l, j, k, k_l, k_h, p;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 real_t nrg, div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 if (sbr->bs_interpol_freq == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 div = (real_t)(u_i - l_i);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 nrg = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 for (i = l_i + tHFAdj; i < u_i + tHFAdj; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 nrg += ((QMF_RE(Xsbr[(i<<6) + m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[(i<<6) + m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 nrg += MUL(QMF_RE(Xsbr[(i<<6) + m + sbr->kx]), QMF_RE(Xsbr[(i<<6) + m + sbr->kx]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 + MUL(QMF_IM(Xsbr[(i<<6) + m + sbr->kx]), QMF_IM(Xsbr[(i<<6) + m + sbr->kx]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 ;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 sbr->E_curr[ch][m][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 sbr->E_curr[ch][m][l] <<= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 sbr->E_curr[ch][m][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 for (p = 0; p < sbr->n[sbr->f[ch][l]]; p++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 k_l = sbr->f_table_res[sbr->f[ch][l]][p];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 k_h = sbr->f_table_res[sbr->f[ch][l]][p+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 for (k = k_l; k < k_h; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 nrg = 0.0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 div = (real_t)((u_i - l_i)*(k_h - k_l + 1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 for (i = l_i + tHFAdj; i < u_i + tHFAdj; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 for (j = k_l; j < k_h; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 nrg += ((QMF_RE(Xsbr[(i<<6) + j])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[(i<<6) + j])+(1<<(REAL_BITS-1)))>>REAL_BITS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 nrg += MUL(QMF_RE(Xsbr[(i<<6) + j]), QMF_RE(Xsbr[(i<<6) + j]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 + MUL(QMF_IM(Xsbr[(i<<6) + j]), QMF_IM(Xsbr[(i<<6) + j]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 ;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 sbr->E_curr[ch][k - sbr->kx][l] <<= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 sbr->E_curr[ch][k - sbr->kx][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 }
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 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 #define step(shift) \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 if ((0x40000000l >> shift) + root <= value) \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 { \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 value -= (0x40000000l >> shift) + root; \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 root = (root >> 1) | (0x40000000l >> shift); \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 } else { \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 root = root >> 1; \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 /* fixed point square root approximation */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 real_t sbr_sqrt(real_t value)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 real_t root = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 step( 0); step( 2); step( 4); step( 6);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 step( 8); step(10); step(12); step(14);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 step(16); step(18); step(20); step(22);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 step(24); step(26); step(28); step(30);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 if (root < value)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 ++root;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 root <<= (REAL_BITS/2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 return root;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 real_t sbr_sqrt_int(real_t value)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 real_t root = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 step( 0); step( 2); step( 4); step( 6);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 step( 8); step(10); step(12); step(14);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 step(16); step(18); step(20); step(22);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 step(24); step(26); step(28); step(30);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 if (root < value)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 ++root;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335 return root;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 #define SBR_SQRT_FIX(A) sbr_sqrt(A)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 #define SBR_SQRT_INT(A) sbr_sqrt_int(A)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 #define EPS (1) /* smallest number available in fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 #define EPS (1e-12)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 #define ONE (REAL_CONST(1)>>10)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 #define ONE (1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 uint8_t m, l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 real_t Q_M_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 real_t G_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 real_t G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 real_t S_M[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 uint8_t table_map_res_to_m[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 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
373 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 table_map_res_to_m[m - sbr->kx] = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 real_t G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 real_t den = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 real_t acc1 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 real_t acc2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 /* E_orig: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 /* E_curr: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 acc2 += sbr->E_curr[ch][m][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 /* G_max: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 if (acc2 == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 G_max = 0xFFF;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 G_max = (((int64_t)acc1)<<REAL_BITS) / acc2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 switch (sbr->bs_limiter_gains)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 case 0: G_max >>= 1; break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 case 2: G_max <<= 1; break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 default: break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 //printf("%f %d %d\n", G_max /(float)(1<<REAL_BITS), acc1, acc2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 real_t d, Q_M, G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 real_t div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 /* Q_mapped: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 /* div2: fixed point COEF */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 real_t tmp2 = adj->Q_mapped[m][l] << (COEF_BITS-REAL_BITS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 real_t tmp = COEF_CONST(1) + tmp2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 if (tmp == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 div2 = COEF_CONST(1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 div2 = (((int64_t)tmp2 << COEF_BITS)/tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 //printf("%f\n", div2 / (float)(1<<COEF_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 /* Q_M: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 Q_M = MUL_R_C(sbr->E_orig[ch][table_map_res_to_m[m]][l], div2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 //printf("%d\n", Q_M /* / (float)(1<<REAL_BITS)*/);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 if (adj->S_mapped[m][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 real_t tmp, tmp2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 S_M[m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 /* d: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 tmp2 = adj->Q_mapped[m][l] /* << (COEF_BITS-REAL_BITS)*/;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 tmp = REAL_CONST(1) + delta*tmp2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 d = (((int64_t)REAL_CONST(1))<<REAL_BITS) / (tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 /* G: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 G = (((int64_t)sbr->E_orig[ch][table_map_res_to_m[m]][l])<<REAL_BITS) / (1 + sbr->E_curr[ch][m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 G = MUL(G, d);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 //printf("%f\n", G/(float)(1<<REAL_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 real_t div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 /* div: fixed point COEF */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454 real_t tmp = COEF_CONST(1.0) + (adj->Q_mapped[m][l] << (COEF_BITS-REAL_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 real_t tmp2 = COEF_CONST(adj->S_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 if (tmp == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 div = COEF_CONST(1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 div = (((int64_t)tmp2 << COEF_BITS)/tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 //printf("%f\n", div/(float)(1<<COEF_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 /* S_M: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 S_M[m] = MUL_R_C(sbr->E_orig[ch][table_map_res_to_m[m]][l], div);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 //printf("%d\n", S_M[m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 /* G: fixed_point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 if ((ONE + sbr->E_curr[ch][m][l]) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 G = 0xFFF; // uhm???
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 real_t tmp = ONE + sbr->E_curr[ch][m][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 /* tmp2: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 real_t tmp2 = (((int64_t)(sbr->E_orig[ch][table_map_res_to_m[m]][l]))<<REAL_BITS)/(tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 G = MUL_R_C(tmp2, div2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 //printf("%f\n", G/(float)(1<<REAL_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 /* limit the additional noise energy level */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 /* and apply the limiter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 /* G_lim: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 /* Q_M_lim: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 if (G_max > G)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 Q_M_lim[m] = Q_M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 G_lim[m] = G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 real_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 if (G == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 tmp = 0xFFF;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 tmp = SBR_DIV(G_max, G);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 Q_M_lim[m] = MUL(Q_M, tmp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 G_lim[m] = G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 /* E_curr: integer, using MUL() is NOT OK */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 den += MUL(sbr->E_curr[ch][m][l], G_lim[m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 den += S_M[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 else if (l != sbr->l_A[ch])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 den += Q_M_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 //printf("%d\n", den);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 /* G_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 if ((den + EPS) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 G_boost = REAL_CONST(2.51188643);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 G_boost = (((int64_t)(acc1 + EPS))<<REAL_BITS)/(den + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 G_boost = min(G_boost, REAL_CONST(2.51188643) /* 1.584893192 ^ 2 */);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 /* apply compensation to gain, noise floor sf's and sinusoid levels */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 /* G_lim_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 adj->G_lim_boost[l][m] = SBR_SQRT_FIX(MUL(G_lim[m], G_boost));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 /* sqrt() will be done after the aliasing reduction to save a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 * few multiplies
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 /* G_lim_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529 adj->G_lim_boost[l][m] = MUL(G_lim[m], G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 /* Q_M_lim_boost: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 adj->Q_M_lim_boost[l][m] = SBR_SQRT_INT(MUL(Q_M_lim[m], G_boost));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 /* S_M_boost: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 adj->S_M_boost[l][m] = SBR_SQRT_INT(MUL(S_M[m], G_boost));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538 adj->S_M_boost[l][m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
547 uint8_t m, l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 real_t Q_M_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550 real_t G_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551 real_t G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552 real_t S_M[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 uint8_t table_map_res_to_m[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
562 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
563 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 table_map_res_to_m[m - sbr->kx] = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 real_t G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 real_t den = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572 real_t acc1 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
573 real_t acc2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
574
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578 acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579 acc2 += sbr->E_curr[ch][m][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
582 G_max = ((EPS + acc1)/(EPS + acc2)) * limGain[sbr->bs_limiter_gains];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
583 G_max = min(G_max, 1e10);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
584
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
585 //printf("%f %d %d\n", G_max, (int)floor((acc1+EPS)/1024.), (int)floor((acc2+EPS)/1024.));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 real_t d, Q_M, G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 real_t div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
593 div2 = adj->Q_mapped[m][l] / (1 + adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
595 //printf("%f\n", div2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
596
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 Q_M = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
598
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 //printf("%f\n", Q_M/1024.);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601 if (adj->S_mapped[m][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603 S_M[m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 /* fixed point: delta* can stay since it's either 1 or 0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 d = (1 + sbr->E_curr[ch][m][l]) * (1 + delta*adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
608 //printf("%f\n", d/1024.);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
610 G = sbr->E_orig[ch][table_map_res_to_m[m]][l] / d;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
611
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
612 //printf("%f\n", G);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
613
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
615 real_t div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
616
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 div = adj->S_mapped[m][l] / (1. + adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
618
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 //printf("%f\n", div);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
620
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621 S_M[m] = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
622
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
623 //printf("%f\n", S_M[m]/1024.);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625 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
626
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
627 //printf("%f\n", G);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
629
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 /* limit the additional noise energy level */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631 /* and apply the limiter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
632 if (G_max > G)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
634 Q_M_lim[m] = Q_M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
635 G_lim[m] = G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
636 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
637 Q_M_lim[m] = Q_M * G_max / G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
638 G_lim[m] = G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
639
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
640 //printf("%f\n", Q_M_lim[m] / 1024.);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
641 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
642
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
643 den += sbr->E_curr[ch][m][l] * G_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
644 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
645 den += S_M[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
646 else if (l != sbr->l_A[ch])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
647 den += Q_M_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
648 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
649
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
650 //printf("%f\n", den/1024.);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
651
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
652 G_boost = (acc1 + EPS) / (den + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
653 G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
654
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
655 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
656 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
657 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
658 /* apply compensation to gain, noise floor sf's and sinusoid levels */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
659 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
660 adj->G_lim_boost[l][m] = sqrt(G_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662 /* sqrt() will be done after the aliasing reduction to save a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
663 * few multiplies
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
664 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
665 adj->G_lim_boost[l][m] = G_lim[m] * G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
666 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
667 adj->Q_M_lim_boost[l][m] = sqrt(Q_M_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
668
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
669 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
670 adj->S_M_boost[l][m] = sqrt(S_M[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
671 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
672 adj->S_M_boost[l][m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
673 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
674 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
675 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
676 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
677 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
678
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
679 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
680 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
681 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
682 uint8_t l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
683 uint8_t grouping;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
684
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
685 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
686 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
687 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
688 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
689
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
690 for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
691 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
692 if (deg[k + 1] && adj->S_mapped[k-sbr->kx][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
693 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
694 if (grouping == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
695 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
696 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
697 grouping = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
698 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
699 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
700 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
701 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
702 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
703 if (adj->S_mapped[k-sbr->kx][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
704 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
705 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
706 sbr->f_group[l][i] = k + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
707 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
708 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
709 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
710 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
711 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
712
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
713 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
714 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
715 sbr->f_group[l][i] = sbr->kx + sbr->M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
716 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
717 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
718
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
719 sbr->N_G[l] = (uint8_t)(i >> 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
720 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
721 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
722
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
723 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
724 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
725 uint8_t l, k, m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
726 real_t E_total, E_total_est, G_target, acc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
727
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
728 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
729 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
730 for (k = 0; k < sbr->N_G[l]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
731 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
732 E_total_est = E_total = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
733
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
734 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
735 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
736 /* E_curr: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
737 /* G_lim_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
738 /* E_total_est: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
739 /* E_total: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
740 E_total_est += sbr->E_curr[ch][m-sbr->kx][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
741 E_total += MUL(sbr->E_curr[ch][m-sbr->kx][l], adj->G_lim_boost[l][m-sbr->kx]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
742 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
743
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
744 /* G_target: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
745 if ((E_total_est + EPS) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
746 G_target = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
747 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
748 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
749 G_target = (((int64_t)(E_total))<<REAL_BITS)/(E_total_est + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
750 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
751 G_target = E_total / (E_total_est + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
752 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
753 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
754
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
755 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
756 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
757 real_t alpha;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
758
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
759 /* alpha: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
760 if (m < sbr->kx + sbr->M - 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
761 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
762 alpha = max(deg[m], deg[m + 1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
763 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
764 alpha = deg[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
765 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
766
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
767 adj->G_lim_boost[l][m-sbr->kx] = MUL(alpha, G_target) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
768 MUL((REAL_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
769
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
770 /* acc: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
771 acc += MUL(adj->G_lim_boost[l][m-sbr->kx], sbr->E_curr[ch][m-sbr->kx][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
772 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
773
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
774 /* acc: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
775 if (acc + EPS == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
776 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
777 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
778 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
779 acc = (((int64_t)(E_total))<<REAL_BITS)/(acc + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
780 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
781 acc = E_total / (acc + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
782 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
783 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
784 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
785 adj->G_lim_boost[l][m-sbr->kx] = MUL(acc, adj->G_lim_boost[l][m-sbr->kx]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
786 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
787 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
788 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
789
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
790 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
791 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
792 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
793 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
794 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
795 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
796 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
797 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
798 adj->G_lim_boost[l][m] = SBR_SQRT_FIX(adj->G_lim_boost[l][m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
799 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
800 adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
801 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
802 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
803 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
804 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
805 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
806 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
807
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
808 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
809 qmf_t *Xsbr, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
810 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
811 static real_t h_smooth[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
812 COEF_CONST(0.03183050093751), COEF_CONST(0.11516383427084),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
813 COEF_CONST(0.21816949906249), COEF_CONST(0.30150283239582),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
814 COEF_CONST(0.33333333333333)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
815 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
816 static int8_t phi_re[] = { 1, 0, -1, 0 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
817 static int8_t phi_im[] = { 0, 1, 0, -1 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
818
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
819 uint8_t m, l, i, n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
820 uint16_t fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
821 uint8_t fIndexSine = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
822 uint8_t assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
823 real_t *temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
824
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
825 real_t G_filt, Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
826
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
827 uint8_t h_SL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
828
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
829
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
830 if (sbr->Reset == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
831 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
832 assembly_reset = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
833 fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
834 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
835 fIndexNoise = sbr->index_noise_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
836 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
837 fIndexSine = sbr->psi_is_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
838
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
839
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
840 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
841 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
842 uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
843
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
844 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
845 h_SL = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
846 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
847 h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
848 h_SL = (no_noise ? 0 : h_SL);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
849 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
850
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
851 if (assembly_reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
852 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
853 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
854 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
855 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
856 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
857 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
858 assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
859 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
860
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
861
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
862 for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l+1]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
863 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
864 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
865 uint8_t i_min1, i_plus1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
866 uint8_t sinusoids = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
867 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
868
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
869 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
870 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
871
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
872 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
873 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
874 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
875 qmf_t psi;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
876
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
877
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
878 G_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
879 Q_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
880 j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
881
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
882 if (h_SL != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
883 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
884 for (n = 0; n <= 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
885 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
886 G_filt += MUL_R_C(sbr->G_temp_prev[ch][n][m], h_smooth[j]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
887 Q_filt += MUL_R_C(sbr->Q_temp_prev[ch][n][m], h_smooth[j]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
888 j++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
889 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
890 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
891 G_filt = sbr->G_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
892 Q_filt = sbr->Q_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
893 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
894
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
895 Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
896
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
897 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
898 if (sbr->frame == 155)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
899 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
900 printf("%f\n", G_filt);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
901 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
902 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
903
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
904 /* add noise to the output */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
905 fIndexNoise = (fIndexNoise + 1) & 511;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
906
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
907 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
908 printf("%d %f\n", Q_filt, RE(V[fIndexNoise])/(float)(1<<COEF_BITS));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
909 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
910
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
911 /* the smoothed gain values are applied to Xsbr */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
912 /* V is defined, not calculated */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
913 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
914 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
915 + MUL_R_C((Q_filt<<REAL_BITS), RE(V[fIndexNoise]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
916 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
917 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
918 + MUL_R_C(Q_filt, RE(V[fIndexNoise]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
919 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
920 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
921 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = 16428320;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
922 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
923 QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
924 + MUL_R_C(Q_filt, IM(V[fIndexNoise]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
925 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
926
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
927
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
928 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
929 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
930 int8_t rev = ((m + sbr->kx) & 1) ? -1 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
931 QMF_RE(psi) = MUL(adj->S_M_boost[l][m], phi_re[fIndexSine]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
932 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) += QMF_RE(psi);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
933
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
934 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
935 QMF_IM(psi) = rev * MUL(adj->S_M_boost[l][m], phi_im[fIndexSine]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
936 QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) += QMF_IM(psi);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
937 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
938 i_min1 = (fIndexSine - 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
939 i_plus1 = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
940
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
941 if (m == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
942 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
943 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx - 1]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
944 (rev * MUL_R_C(MUL(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
945 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
946 (rev * MUL_R_C(MUL(adj->S_M_boost[l][1], phi_re[i_plus1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
947 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
948 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
949 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
950 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
951 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
952 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
953 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_plus1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
954 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
955 if ((m == sbr->M - 1) && (sinusoids < 16) && (m + sbr->kx + 1 < 63))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
956 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
957 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
958 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
959 QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx + 1]) -=
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
960 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_min1]), COEF_CONST(0.00815)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
961 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
962
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
963 sinusoids++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
964 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
965 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
966 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
967
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
968 fIndexSine = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
969
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
970
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
971 temp = sbr->G_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
972 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
973 sbr->G_temp_prev[ch][n] = sbr->G_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
974 sbr->G_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
975
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
976 temp = sbr->Q_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
977 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
978 sbr->Q_temp_prev[ch][n] = sbr->Q_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
979 sbr->Q_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
980 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
981 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
982
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
983 sbr->index_noise_prev[ch] = fIndexNoise;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
984 sbr->psi_is_prev[ch] = fIndexSine;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
985 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
986
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
987 #endif