Mercurial > audlegacy-plugins
comparison src/aac/libfaad2/sbr_tf_grid.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/aac/libfaad2/sbr_tf_grid.c@13389e613d67 |
children | 1d8b08df98c3 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* | |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
3 ** Copyright (C) 2003-2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 ** | |
25 ** $Id: sbr_tf_grid.c,v 1.15 2004/09/04 14:56:28 menno Exp $ | |
26 **/ | |
27 | |
28 /* Time/Frequency grid */ | |
29 | |
30 #include "common.h" | |
31 #include "structs.h" | |
32 | |
33 #ifdef SBR_DEC | |
34 | |
35 #include <stdlib.h> | |
36 | |
37 #include "sbr_syntax.h" | |
38 #include "sbr_tf_grid.h" | |
39 | |
40 | |
41 /* static function declarations */ | |
42 #if 0 | |
43 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l); | |
44 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l); | |
45 #endif | |
46 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch); | |
47 | |
48 | |
49 /* function constructs new time border vector */ | |
50 /* first build into temp vector to be able to use previous vector on error */ | |
51 uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch) | |
52 { | |
53 uint8_t l, border, temp; | |
54 uint8_t t_E_temp[6] = {0}; | |
55 | |
56 t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch]; | |
57 t_E_temp[sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch]; | |
58 | |
59 switch (sbr->bs_frame_class[ch]) | |
60 { | |
61 case FIXFIX: | |
62 switch (sbr->L_E[ch]) | |
63 { | |
64 case 4: | |
65 temp = (int) (sbr->numTimeSlots / 4); | |
66 t_E_temp[3] = sbr->rate * 3 * temp; | |
67 t_E_temp[2] = sbr->rate * 2 * temp; | |
68 t_E_temp[1] = sbr->rate * temp; | |
69 break; | |
70 case 2: | |
71 t_E_temp[1] = sbr->rate * (int) (sbr->numTimeSlots / 2); | |
72 break; | |
73 default: | |
74 break; | |
75 } | |
76 break; | |
77 | |
78 case FIXVAR: | |
79 if (sbr->L_E[ch] > 1) | |
80 { | |
81 int8_t i = sbr->L_E[ch]; | |
82 border = sbr->abs_bord_trail[ch]; | |
83 | |
84 for (l = 0; l < (sbr->L_E[ch] - 1); l++) | |
85 { | |
86 if (border < sbr->bs_rel_bord[ch][l]) | |
87 return 1; | |
88 | |
89 border -= sbr->bs_rel_bord[ch][l]; | |
90 t_E_temp[--i] = sbr->rate * border; | |
91 } | |
92 } | |
93 break; | |
94 | |
95 case VARFIX: | |
96 if (sbr->L_E[ch] > 1) | |
97 { | |
98 int8_t i = 1; | |
99 border = sbr->abs_bord_lead[ch]; | |
100 | |
101 for (l = 0; l < (sbr->L_E[ch] - 1); l++) | |
102 { | |
103 border += sbr->bs_rel_bord[ch][l]; | |
104 | |
105 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen) | |
106 return 1; | |
107 | |
108 t_E_temp[i++] = sbr->rate * border; | |
109 } | |
110 } | |
111 break; | |
112 | |
113 case VARVAR: | |
114 if (sbr->bs_num_rel_0[ch]) | |
115 { | |
116 int8_t i = 1; | |
117 border = sbr->abs_bord_lead[ch]; | |
118 | |
119 for (l = 0; l < sbr->bs_num_rel_0[ch]; l++) | |
120 { | |
121 border += sbr->bs_rel_bord_0[ch][l]; | |
122 | |
123 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen) | |
124 return 1; | |
125 | |
126 t_E_temp[i++] = sbr->rate * border; | |
127 } | |
128 } | |
129 | |
130 if (sbr->bs_num_rel_1[ch]) | |
131 { | |
132 int8_t i = sbr->L_E[ch]; | |
133 border = sbr->abs_bord_trail[ch]; | |
134 | |
135 for (l = 0; l < sbr->bs_num_rel_1[ch]; l++) | |
136 { | |
137 if (border < sbr->bs_rel_bord_1[ch][l]) | |
138 return 1; | |
139 | |
140 border -= sbr->bs_rel_bord_1[ch][l]; | |
141 t_E_temp[--i] = sbr->rate * border; | |
142 } | |
143 } | |
144 break; | |
145 } | |
146 | |
147 /* no error occured, we can safely use this t_E vector */ | |
148 for (l = 0; l < 6; l++) | |
149 { | |
150 sbr->t_E[ch][l] = t_E_temp[l]; | |
151 } | |
152 | |
153 return 0; | |
154 } | |
155 | |
156 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch) | |
157 { | |
158 sbr->t_Q[ch][0] = sbr->t_E[ch][0]; | |
159 | |
160 if (sbr->L_E[ch] == 1) | |
161 { | |
162 sbr->t_Q[ch][1] = sbr->t_E[ch][1]; | |
163 sbr->t_Q[ch][2] = 0; | |
164 } else { | |
165 uint8_t index = middleBorder(sbr, ch); | |
166 sbr->t_Q[ch][1] = sbr->t_E[ch][index]; | |
167 sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]]; | |
168 } | |
169 } | |
170 | |
171 #if 0 | |
172 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l) | |
173 { | |
174 uint8_t i; | |
175 int16_t acc = 0; | |
176 | |
177 switch (sbr->bs_frame_class[ch]) | |
178 { | |
179 case FIXFIX: | |
180 return sbr->numTimeSlots/sbr->L_E[ch]; | |
181 case FIXVAR: | |
182 return 0; | |
183 case VARFIX: | |
184 for (i = 0; i < l; i++) | |
185 { | |
186 acc += sbr->bs_rel_bord[ch][i]; | |
187 } | |
188 return acc; | |
189 case VARVAR: | |
190 for (i = 0; i < l; i++) | |
191 { | |
192 acc += sbr->bs_rel_bord_0[ch][i]; | |
193 } | |
194 return acc; | |
195 } | |
196 | |
197 return 0; | |
198 } | |
199 | |
200 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l) | |
201 { | |
202 uint8_t i; | |
203 int16_t acc = 0; | |
204 | |
205 switch (sbr->bs_frame_class[ch]) | |
206 { | |
207 case FIXFIX: | |
208 case VARFIX: | |
209 return 0; | |
210 case FIXVAR: | |
211 for (i = 0; i < l; i++) | |
212 { | |
213 acc += sbr->bs_rel_bord[ch][i]; | |
214 } | |
215 return acc; | |
216 case VARVAR: | |
217 for (i = 0; i < l; i++) | |
218 { | |
219 acc += sbr->bs_rel_bord_1[ch][i]; | |
220 } | |
221 return acc; | |
222 } | |
223 | |
224 return 0; | |
225 } | |
226 #endif | |
227 | |
228 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch) | |
229 { | |
230 int8_t retval = 0; | |
231 | |
232 switch (sbr->bs_frame_class[ch]) | |
233 { | |
234 case FIXFIX: | |
235 retval = sbr->L_E[ch]/2; | |
236 break; | |
237 case VARFIX: | |
238 if (sbr->bs_pointer[ch] == 0) | |
239 retval = 1; | |
240 else if (sbr->bs_pointer[ch] == 1) | |
241 retval = sbr->L_E[ch] - 1; | |
242 else | |
243 retval = sbr->bs_pointer[ch] - 1; | |
244 break; | |
245 case FIXVAR: | |
246 case VARVAR: | |
247 if (sbr->bs_pointer[ch] > 1) | |
248 retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch]; | |
249 else | |
250 retval = sbr->L_E[ch] - 1; | |
251 break; | |
252 } | |
253 | |
254 return (retval > 0) ? retval : 0; | |
255 } | |
256 | |
257 | |
258 #endif |