22 pixel high Nimbus-like font, containing only digits and the period; intended for...
[kugel-rb.git] / apps / codecs / libfaad / sbr_tf_grid.c
blob2c21173490c0f944f7b273f017a4e3c14b875a2a
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden.
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id$
26 **/
28 /* Time/Frequency grid */
30 #include "common.h"
31 #include "structs.h"
33 #ifdef SBR_DEC
35 #include <stdlib.h>
37 #include "sbr_syntax.h"
38 #include "sbr_tf_grid.h"
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);
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)
53 uint8_t l, temp;
54 int8_t border;
55 uint8_t t_E_temp[6] = {0};
57 t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch];
58 t_E_temp[sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch];
60 switch (sbr->bs_frame_class[ch])
62 case FIXFIX:
63 switch (sbr->L_E[ch])
65 case 4:
66 temp = (int) (sbr->numTimeSlots / 4);
67 t_E_temp[3] = sbr->rate * 3 * temp;
68 t_E_temp[2] = sbr->rate * 2 * temp;
69 t_E_temp[1] = sbr->rate * temp;
70 break;
71 case 2:
72 t_E_temp[1] = sbr->rate * (int) (sbr->numTimeSlots / 2);
73 break;
74 default:
75 break;
77 break;
79 case FIXVAR:
80 if (sbr->L_E[ch] > 1)
82 int8_t i = sbr->L_E[ch];
83 border = sbr->abs_bord_trail[ch];
85 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
87 if (border < sbr->bs_rel_bord[ch][l])
88 return 1;
90 border -= sbr->bs_rel_bord[ch][l];
91 t_E_temp[--i] = sbr->rate * border;
94 break;
96 case VARFIX:
97 if (sbr->L_E[ch] > 1)
99 int8_t i = 1;
100 border = sbr->abs_bord_lead[ch];
102 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
104 border += sbr->bs_rel_bord[ch][l];
106 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
107 return 1;
109 t_E_temp[i++] = sbr->rate * border;
112 break;
114 case VARVAR:
115 if (sbr->bs_num_rel_0[ch])
117 int8_t i = 1;
118 border = sbr->abs_bord_lead[ch];
120 for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
122 border += sbr->bs_rel_bord_0[ch][l];
124 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
125 return 1;
127 t_E_temp[i++] = sbr->rate * border;
131 if (sbr->bs_num_rel_1[ch])
133 int8_t i = sbr->L_E[ch];
134 border = sbr->abs_bord_trail[ch];
136 for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
138 if (border < sbr->bs_rel_bord_1[ch][l])
139 return 1;
141 border -= sbr->bs_rel_bord_1[ch][l];
142 t_E_temp[--i] = sbr->rate * border;
145 break;
148 /* no error occured, we can safely use this t_E vector */
149 for (l = 0; l < 6; l++)
151 sbr->t_E[ch][l] = t_E_temp[l];
154 return 0;
157 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
159 sbr->t_Q[ch][0] = sbr->t_E[ch][0];
161 if (sbr->L_E[ch] == 1)
163 sbr->t_Q[ch][1] = sbr->t_E[ch][1];
164 sbr->t_Q[ch][2] = 0;
165 } else {
166 uint8_t index = middleBorder(sbr, ch);
167 sbr->t_Q[ch][1] = sbr->t_E[ch][index];
168 sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
172 #if 0
173 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
175 uint8_t i;
176 int16_t acc = 0;
178 switch (sbr->bs_frame_class[ch])
180 case FIXFIX:
181 return sbr->numTimeSlots/sbr->L_E[ch];
182 case FIXVAR:
183 return 0;
184 case VARFIX:
185 for (i = 0; i < l; i++)
187 acc += sbr->bs_rel_bord[ch][i];
189 return acc;
190 case VARVAR:
191 for (i = 0; i < l; i++)
193 acc += sbr->bs_rel_bord_0[ch][i];
195 return acc;
198 return 0;
201 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
203 uint8_t i;
204 int16_t acc = 0;
206 switch (sbr->bs_frame_class[ch])
208 case FIXFIX:
209 case VARFIX:
210 return 0;
211 case FIXVAR:
212 for (i = 0; i < l; i++)
214 acc += sbr->bs_rel_bord[ch][i];
216 return acc;
217 case VARVAR:
218 for (i = 0; i < l; i++)
220 acc += sbr->bs_rel_bord_1[ch][i];
222 return acc;
225 return 0;
227 #endif
229 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
231 int8_t retval = 0;
233 switch (sbr->bs_frame_class[ch])
235 case FIXFIX:
236 retval = sbr->L_E[ch]/2;
237 break;
238 case VARFIX:
239 if (sbr->bs_pointer[ch] == 0)
240 retval = 1;
241 else if (sbr->bs_pointer[ch] == 1)
242 retval = sbr->L_E[ch] - 1;
243 else
244 retval = sbr->bs_pointer[ch] - 1;
245 break;
246 case FIXVAR:
247 case VARVAR:
248 if (sbr->bs_pointer[ch] > 1)
249 retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
250 else
251 retval = sbr->L_E[ch] - 1;
252 break;
255 return (retval > 0) ? retval : 0;
259 #endif