annotate libfaad2/sbr_hfadj.c @ 11109:084c271c785e

10l found by Mark Berryman <mplayer@theberrymans.com>
author alex
date Tue, 14 Oct 2003 09:59:46 +0000
parents 3185f64f6350
children 4a370c80fe5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: sbr_hfadj.c,v 1.4 2003/09/09 18:37:32 menno Exp $
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 /* High Frequency 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 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 calc_gain_groups(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 aliasing_reduction(sbr, &adj, deg, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 hf_assembly(sbr, &adj, Xsbr, ch);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 uint8_t l, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 uint32_t m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 for (i = 0; i < sbr->N_Q; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 for (m = sbr->f_table_noise[i]; m < sbr->f_table_noise[i+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 adj->Q_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 for (k = 0; k < 2; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 if ((sbr->t_E[ch][l] >= sbr->t_Q[ch][k]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 (sbr->t_E[ch][l+1] <= sbr->t_Q[ch][k+1]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 adj->Q_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 sbr->Q_orig[ch][i][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 }
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 static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 uint8_t l, i, m, k, k1, k2, delta_S, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 if (sbr->bs_frame_class[ch] == FIXFIX)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 } else if (sbr->bs_frame_class[ch] == VARFIX) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 if (sbr->bs_pointer[ch] > 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 sbr->l_A[ch] = sbr->bs_pointer[ch] - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 if (sbr->bs_pointer[ch] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 sbr->l_A[ch] = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 for (l = 0; l < 5; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 for (i = 0; i < 64; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 adj->S_index_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 adj->S_mapped[i][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 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
127 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 uint8_t delta_step = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 if ((l >= sbr->l_A[ch]) || ((sbr->bs_add_harmonic_prev[ch][i]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 (sbr->bs_add_harmonic_flag_prev[ch])))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 delta_step = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 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
136 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 adj->S_index_mapped[m - sbr->kx][l] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 delta_step * sbr->bs_add_harmonic[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 adj->S_index_mapped[m - sbr->kx][l] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 for (i = 0; i < sbr->N_high; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 if (sbr->f[ch][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 k1 = i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 k2 = i + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 for (k1 = 0; k1 < sbr->N_low; k1++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 if ((sbr->f_table_res[HI_RES][i] >= sbr->f_table_res[LO_RES][k1]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 (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
159 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 for (k2 = 0; k2 < sbr->N_low; k2++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 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
166 (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
167 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 l_i = sbr->f_table_res[sbr->f[ch][l]][k1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 u_i = sbr->f_table_res[sbr->f[ch][l]][k2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 delta_S = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 for (k = l_i; k < u_i; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 if (adj->S_index_mapped[k - sbr->kx][l] == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 delta_S = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 for (m = l_i; m < u_i; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 adj->S_mapped[m - sbr->kx][l] = delta_S;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t *Xsbr,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 uint8_t m, l, j, k, k_l, k_h, p;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 real_t nrg, div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 if (sbr->bs_interpol_freq == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 div = (real_t)(u_i - l_i);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 nrg = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
212 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 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
215 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 + 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
217 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 ;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 sbr->E_curr[ch][m][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 sbr->E_curr[ch][m][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 for (p = 0; p < sbr->n[sbr->f[ch][l]]; p++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 k_l = sbr->f_table_res[sbr->f[ch][l]][p];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 k_h = sbr->f_table_res[sbr->f[ch][l]][p+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 for (k = k_l; k < k_h; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 uint8_t i, l_i, u_i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 nrg = 0.0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 l_i = sbr->t_E[ch][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 u_i = sbr->t_E[ch][l+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 div = (real_t)((u_i - l_i)*(k_h - k_l + 1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
245 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 for (j = k_l; j < k_h; j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 nrg += MUL(QMF_RE(Xsbr[(i<<6) + j]), QMF_RE(Xsbr[(i<<6) + j]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 + MUL(QMF_IM(Xsbr[(i<<6) + j]), QMF_IM(Xsbr[(i<<6) + j]))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 ;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 sbr->E_curr[ch][k - sbr->kx][l] *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
267 #define EPS (1e-12)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 #define ONE (1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 uint8_t m, l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 real_t Q_M_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 real_t G_lim[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 real_t G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 real_t S_M[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 uint8_t table_map_res_to_m[64];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 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
291 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 table_map_res_to_m[m - sbr->kx] = i;
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 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 real_t G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 real_t den = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 real_t acc1 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 real_t acc2 = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 acc2 += sbr->E_curr[ch][m][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 G_max = ((EPS + acc1)/(EPS + acc2)) * limGain[sbr->bs_limiter_gains];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 G_max = min(G_max, 1e10);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 real_t d, Q_M, G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 real_t div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 div2 = adj->Q_mapped[m][l] / (1 + adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 Q_M = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 if (adj->S_mapped[m][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 S_M[m] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 /* fixed point: delta* can stay since it's either 1 or 0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 d = (1 + sbr->E_curr[ch][m][l]) * (1 + delta*adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 G = sbr->E_orig[ch][table_map_res_to_m[m]][l] / d;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 real_t div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 div = adj->S_mapped[m][l] / (1. + adj->Q_mapped[m][l]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 S_M[m] = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 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
335 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 /* limit the additional noise energy level */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 /* and apply the limiter */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 if (G_max > G)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 Q_M_lim[m] = Q_M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 G_lim[m] = G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 Q_M_lim[m] = Q_M * G_max / G;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345 G_lim[m] = G_max;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 den += sbr->E_curr[ch][m][l] * G_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 den += S_M[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 else if (l != sbr->l_A[ch])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 den += Q_M_lim[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 G_boost = (acc1 + EPS) / (den + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 /* apply compensation to gain, noise floor sf's and sinusoid levels */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 adj->G_lim_boost[l][m] = sqrt(G_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 /* sqrt() will be done after the aliasing reduction to save a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 * few multiplies
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 adj->G_lim_boost[l][m] = G_lim[m] * G_boost;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 adj->Q_M_lim_boost[l][m] = sqrt(Q_M_lim[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 adj->S_M_boost[l][m] = sqrt(S_M[m] * G_boost);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 adj->S_M_boost[l][m] = 0;
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 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 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
383 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 uint8_t l, k, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 uint8_t grouping;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 i = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 if (deg[k + 1] && adj->S_mapped[k-sbr->kx][l] == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 if (grouping == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 grouping = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 if (adj->S_mapped[k-sbr->kx][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 sbr->f_group[l][i] = k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 sbr->f_group[l][i] = k + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 grouping = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 if (grouping)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 sbr->f_group[l][i] = sbr->kx + sbr->M;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 i++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 sbr->N_G[l] = (uint8_t)(i >> 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 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
426 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 uint8_t l, k, m;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 real_t E_total, E_total_est, G_target, acc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 for (k = 0; k < sbr->N_G[l]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 E_total_est = E_total = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 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
437 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 /* E_curr: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 /* G_lim_boost: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 /* E_total_est: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 /* E_total: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 E_total_est += sbr->E_curr[ch][m-sbr->kx][l];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 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
444 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 /* G_target: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 if ((E_total_est + EPS) == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 G_target = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 G_target = E_total / (E_total_est + EPS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 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
454 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 real_t alpha;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 /* alpha: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 if (m < sbr->kx + sbr->M - 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 alpha = max(deg[m], deg[m + 1]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 alpha = deg[m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 adj->G_lim_boost[l][m-sbr->kx] = MUL(alpha, G_target) +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 MUL((REAL_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 /* acc: integer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 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
470 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 /* acc: fixed point */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 if (acc + EPS == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 acc = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 acc = E_total / (acc + EPS);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
477
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 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
479 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 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
481 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 qmf_t *Xsbr, uint8_t ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 static real_t h_smooth[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 COEF_CONST(0.03183050093751), COEF_CONST(0.11516383427084),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 COEF_CONST(0.21816949906249), COEF_CONST(0.30150283239582),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 COEF_CONST(0.33333333333333)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 static int8_t phi_re[] = { 1, 0, -1, 0 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 static int8_t phi_im[] = { 0, 1, 0, -1 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 uint8_t m, l, i, n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 uint16_t fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 uint8_t fIndexSine = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 uint8_t assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 real_t *temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516 real_t G_filt, Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 uint8_t h_SL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 if (sbr->Reset == 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 assembly_reset = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 fIndexNoise = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 fIndexNoise = sbr->index_noise_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 fIndexSine = sbr->psi_is_prev[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 for (l = 0; l < sbr->L_E[ch]; l++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533 uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 h_SL = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538 h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 h_SL = (no_noise ? 0 : h_SL);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 if (assembly_reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 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
547 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
548 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 assembly_reset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l+1]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555 #ifdef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 uint8_t i_min1, i_plus1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 uint8_t sinusoids = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 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
561 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
562
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
563 for (m = 0; m < sbr->M; m++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 uint8_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 qmf_t psi;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569 G_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 Q_filt = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
573 if (h_SL != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
574 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 for (n = 0; n <= 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 G_filt += MUL_R_C(sbr->G_temp_prev[ch][n][m], h_smooth[j]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578 Q_filt += MUL_R_C(sbr->Q_temp_prev[ch][n][m], h_smooth[j]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579 j++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
582 G_filt = sbr->G_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
583 Q_filt = sbr->Q_temp_prev[ch][4][m];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
584 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
585
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586 Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588 /* add noise to the output */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589 fIndexNoise = (fIndexNoise + 1) & 511;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 /* the smoothed gain values are applied to Xsbr */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592 /* V is defined, not calculated */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
593 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594 + MUL_R_C(Q_filt, RE(V[fIndexNoise]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
595 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
596 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = 16428320;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 #ifndef SBR_LOW_POWER
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
598 QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 + MUL_R_C(Q_filt, IM(V[fIndexNoise]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603 if (adj->S_index_mapped[m][l])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 int8_t rev = ((m + sbr->kx) & 1) ? -1 : 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 QMF_RE(psi) = MUL(adj->S_M_boost[l][m], phi_re[fIndexSine]);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
607 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_RE(psi);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
608
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609 #ifndef SBR_LOW_POWER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
610 QMF_IM(psi) = rev * MUL(adj->S_M_boost[l][m], phi_im[fIndexSine]);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
611 QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_IM(psi);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
612 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
613 i_min1 = (fIndexSine - 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 i_plus1 = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
615
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
616 if (m == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
618 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx - 1]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 (rev * MUL_R_C(MUL(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815)));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
620 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621 (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
622 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
623 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
625 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
626 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
627 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628 (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
629 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 if ((m == sbr->M - 1) && (sinusoids < 16) && (m + sbr->kx + 1 < 63))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
632 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
634 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx + 1]) -=
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
635 (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
636 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
637
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
638 sinusoids++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
639 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
640 }
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 fIndexSine = (fIndexSine + 1) & 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
644
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
645
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
646 temp = sbr->G_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
647 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
648 sbr->G_temp_prev[ch][n] = sbr->G_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
649 sbr->G_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
650
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
651 temp = sbr->Q_temp_prev[ch][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
652 for (n = 0; n < 4; n++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
653 sbr->Q_temp_prev[ch][n] = sbr->Q_temp_prev[ch][n+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
654 sbr->Q_temp_prev[ch][4] = temp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
655 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
656 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
657
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
658 sbr->index_noise_prev[ch] = fIndexNoise;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
659 sbr->psi_is_prev[ch] = fIndexSine;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
660 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662 #endif