Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libfaad2 / sbr_tf_grid.c
blob740ab3a6f78164f50d0d6905575534de93a2e115
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: sbr_tf_grid.c,v 1.15 2004/09/04 14:56:28 menno Exp $
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, border, temp;
54 uint8_t t_E_temp[6] = {0};
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];
59 switch (sbr->bs_frame_class[ch])
61 case FIXFIX:
62 switch (sbr->L_E[ch])
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;
76 break;
78 case FIXVAR:
79 if (sbr->L_E[ch] > 1)
81 int8_t i = sbr->L_E[ch];
82 border = sbr->abs_bord_trail[ch];
84 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
86 if (border < sbr->bs_rel_bord[ch][l])
87 return 1;
89 border -= sbr->bs_rel_bord[ch][l];
90 t_E_temp[--i] = sbr->rate * border;
93 break;
95 case VARFIX:
96 if (sbr->L_E[ch] > 1)
98 int8_t i = 1;
99 border = sbr->abs_bord_lead[ch];
101 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
103 border += sbr->bs_rel_bord[ch][l];
105 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
106 return 1;
108 t_E_temp[i++] = sbr->rate * border;
111 break;
113 case VARVAR:
114 if (sbr->bs_num_rel_0[ch])
116 int8_t i = 1;
117 border = sbr->abs_bord_lead[ch];
119 for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
121 border += sbr->bs_rel_bord_0[ch][l];
123 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
124 return 1;
126 t_E_temp[i++] = sbr->rate * border;
130 if (sbr->bs_num_rel_1[ch])
132 int8_t i = sbr->L_E[ch];
133 border = sbr->abs_bord_trail[ch];
135 for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
137 if (border < sbr->bs_rel_bord_1[ch][l])
138 return 1;
140 border -= sbr->bs_rel_bord_1[ch][l];
141 t_E_temp[--i] = sbr->rate * border;
144 break;
147 /* no error occured, we can safely use this t_E vector */
148 for (l = 0; l < 6; l++)
150 sbr->t_E[ch][l] = t_E_temp[l];
153 return 0;
156 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
158 sbr->t_Q[ch][0] = sbr->t_E[ch][0];
160 if (sbr->L_E[ch] == 1)
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]];
171 #if 0
172 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
174 uint8_t i;
175 int16_t acc = 0;
177 switch (sbr->bs_frame_class[ch])
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++)
186 acc += sbr->bs_rel_bord[ch][i];
188 return acc;
189 case VARVAR:
190 for (i = 0; i < l; i++)
192 acc += sbr->bs_rel_bord_0[ch][i];
194 return acc;
197 return 0;
200 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
202 uint8_t i;
203 int16_t acc = 0;
205 switch (sbr->bs_frame_class[ch])
207 case FIXFIX:
208 case VARFIX:
209 return 0;
210 case FIXVAR:
211 for (i = 0; i < l; i++)
213 acc += sbr->bs_rel_bord[ch][i];
215 return acc;
216 case VARVAR:
217 for (i = 0; i < l; i++)
219 acc += sbr->bs_rel_bord_1[ch][i];
221 return acc;
224 return 0;
226 #endif
228 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
230 int8_t retval = 0;
232 switch (sbr->bs_frame_class[ch])
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;
254 return (retval > 0) ? retval : 0;
258 #endif