10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
10989
|
25 ** $Id: sbr_e_nf.c,v 1.4 2003/09/09 18:37:32 menno Exp $
|
10725
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #ifdef SBR_DEC
|
|
32
|
|
33 #include <stdlib.h>
|
|
34
|
|
35 #include "sbr_syntax.h"
|
|
36 #include "sbr_e_nf.h"
|
|
37
|
|
38 void extract_envelope_data(sbr_info *sbr, uint8_t ch)
|
|
39 {
|
|
40 uint8_t l, k;
|
|
41
|
|
42 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
43 {
|
|
44 if (sbr->bs_df_env[ch][l] == 0)
|
|
45 {
|
|
46 for (k = 1; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
47 {
|
|
48 sbr->E[ch][k][l] = sbr->E[ch][k - 1][l] + sbr->E[ch][k][l];
|
|
49 }
|
|
50
|
|
51 } else { /* bs_df_env == 1 */
|
|
52
|
|
53 uint8_t g = (l == 0) ? sbr->f_prev[ch] : sbr->f[ch][l-1];
|
|
54 int16_t E_prev;
|
|
55
|
|
56 if (sbr->f[ch][l] == g)
|
|
57 {
|
|
58 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
59 {
|
|
60 if (l == 0)
|
|
61 E_prev = sbr->E_prev[ch][k];
|
|
62 else
|
|
63 E_prev = sbr->E[ch][k][l - 1];
|
|
64
|
|
65 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
66 }
|
|
67
|
|
68 } else if ((g == 1) && (sbr->f[ch][l] == 0)) {
|
|
69 uint8_t i;
|
|
70
|
|
71 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
72 {
|
|
73 for (i = 0; i < sbr->N_high; i++)
|
|
74 {
|
|
75 if (sbr->f_table_res[HI_RES][i] == sbr->f_table_res[LO_RES][k])
|
|
76 {
|
|
77 if (l == 0)
|
|
78 E_prev = sbr->E_prev[ch][i];
|
|
79 else
|
|
80 E_prev = sbr->E[ch][i][l - 1];
|
|
81
|
|
82 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
83 }
|
|
84 }
|
|
85 }
|
|
86
|
|
87 } else if ((g == 0) && (sbr->f[ch][l] == 1)) {
|
|
88 uint8_t i;
|
|
89
|
|
90 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
91 {
|
|
92 for (i = 0; i < sbr->N_low; i++)
|
|
93 {
|
|
94 if ((sbr->f_table_res[LO_RES][i] <= sbr->f_table_res[HI_RES][k]) &&
|
|
95 (sbr->f_table_res[HI_RES][k] < sbr->f_table_res[LO_RES][i + 1]))
|
|
96 {
|
|
97 if (l == 0)
|
|
98 E_prev = sbr->E_prev[ch][i];
|
|
99 else
|
|
100 E_prev = sbr->E[ch][i][l - 1];
|
|
101
|
|
102 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
103 }
|
|
104 }
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108 }
|
|
109 }
|
|
110
|
|
111 void extract_noise_floor_data(sbr_info *sbr, uint8_t ch)
|
|
112 {
|
|
113 uint8_t l, k;
|
|
114
|
|
115 for (l = 0; l < sbr->L_Q[ch]; l++)
|
|
116 {
|
|
117 if (sbr->bs_df_noise[ch][l] == 0)
|
|
118 {
|
|
119 for (k = 1; k < sbr->N_Q; k++)
|
|
120 {
|
|
121 sbr->Q[ch][k][l] = sbr->Q[ch][k][l] + sbr->Q[ch][k-1][l];
|
|
122 }
|
|
123 } else {
|
|
124 if (l == 0)
|
|
125 {
|
|
126 for (k = 0; k < sbr->N_Q; k++)
|
|
127 {
|
|
128 sbr->Q[ch][k][l] = sbr->Q_prev[ch][k] + sbr->Q[ch][k][0];
|
|
129 }
|
|
130 } else {
|
|
131 for (k = 0; k < sbr->N_Q; k++)
|
|
132 {
|
|
133 sbr->Q[ch][k][l] = sbr->Q[ch][k][l - 1] + sbr->Q[ch][k][l];
|
|
134 }
|
|
135 }
|
|
136 }
|
|
137 }
|
|
138 }
|
|
139
|
|
140 /* FIXME: pow() not needed */
|
|
141 void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch)
|
|
142 {
|
|
143 if (sbr->bs_coupling == 0)
|
|
144 {
|
|
145 uint8_t l, k;
|
10989
|
146 real_t amp = (sbr->amp_res[ch]) ? 1.0f : 0.5f;
|
10725
|
147
|
|
148 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
149 {
|
|
150 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
151 {
|
|
152 /* +6 for the *64 */
|
10989
|
153 sbr->E_orig[ch][k][l] = (real_t)pow(2, sbr->E[ch][k][l]*amp + 6);
|
10725
|
154 }
|
|
155 }
|
|
156
|
|
157 for (l = 0; l < sbr->L_Q[ch]; l++)
|
|
158 {
|
|
159 for (k = 0; k < sbr->N_Q; k++)
|
|
160 {
|
|
161 if (sbr->Q[ch][k][l] < 0 || sbr->Q[ch][k][l] > 30)
|
|
162 sbr->Q_orig[ch][k][l] = 0;
|
|
163 else {
|
10989
|
164 sbr->Q_orig[ch][k][l] = (real_t)pow(2, NOISE_FLOOR_OFFSET - sbr->Q[ch][k][l]);
|
10725
|
165 }
|
|
166 }
|
|
167 }
|
|
168 }
|
|
169 }
|
|
170
|
|
171 void unmap_envelope_noise(sbr_info *sbr)
|
|
172 {
|
|
173 uint8_t l, k;
|
10989
|
174 real_t amp0 = (sbr->amp_res[0]) ? (real_t)1.0 : (real_t)0.5;
|
|
175 real_t amp1 = (sbr->amp_res[1]) ? (real_t)1.0 : (real_t)0.5;
|
10725
|
176
|
|
177 for (l = 0; l < sbr->L_E[0]; l++)
|
|
178 {
|
|
179 for (k = 0; k < sbr->n[sbr->f[0][l]]; k++)
|
|
180 {
|
|
181 real_t l_temp, r_temp;
|
|
182
|
10989
|
183 /* +6: * 64 ; +1: * 2 */
|
|
184 l_temp = (real_t)pow(2, sbr->E[0][k][l]*amp0 + 7);
|
10725
|
185 /* UN_MAP removed: (x / 4096) same as (x >> 12) */
|
10989
|
186 r_temp = (real_t)pow(2, sbr->E[1][k][l]*amp1 - 12);
|
10725
|
187
|
10989
|
188 sbr->E_orig[1][k][l] = l_temp / ((real_t)1.0 + r_temp);
|
10725
|
189 sbr->E_orig[0][k][l] = MUL(r_temp, sbr->E_orig[1][k][l]);
|
|
190 }
|
|
191 }
|
|
192 for (l = 0; l < sbr->L_Q[0]; l++)
|
|
193 {
|
|
194 for (k = 0; k < sbr->N_Q; k++)
|
|
195 {
|
|
196 if ((sbr->Q[0][k][l] < 0 || sbr->Q[0][k][l] > 30) ||
|
|
197 (sbr->Q[1][k][l] < 0 || sbr->Q[1][k][l] > 30))
|
|
198 {
|
|
199 sbr->Q_orig[0][k][l] = 0;
|
|
200 sbr->Q_orig[1][k][l] = 0;
|
|
201 } else {
|
|
202 real_t l_temp, r_temp;
|
|
203
|
10989
|
204 l_temp = (real_t)pow(2.0, NOISE_FLOOR_OFFSET - sbr->Q[0][k][l] + 1);
|
|
205 r_temp = (real_t)pow(2.0, sbr->Q[1][k][l] - 12);
|
10725
|
206
|
10989
|
207 sbr->Q_orig[1][k][l] = l_temp / ((real_t)1.0 + r_temp);
|
10725
|
208 sbr->Q_orig[0][k][l] = MUL(r_temp, sbr->Q_orig[1][k][l]);
|
|
209 }
|
|
210 }
|
|
211 }
|
|
212 }
|
|
213
|
|
214 #endif
|