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_tf_grid.c,v 1.4 2003/09/30 16:32:02 menno Exp $
|
10725
|
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
|
10989
|
40 uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
|
10725
|
41 {
|
10989
|
42 uint8_t l, border, temp;
|
10725
|
43
|
|
44 for (l = 0; l <= sbr->L_E[ch]; l++)
|
|
45 {
|
|
46 sbr->t_E[ch][l] = 0;
|
|
47 }
|
|
48
|
|
49 sbr->t_E[ch][0] = sbr->rate * sbr->abs_bord_lead[ch];
|
|
50 sbr->t_E[ch][sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch];
|
|
51
|
|
52 switch (sbr->bs_frame_class[ch])
|
|
53 {
|
|
54 case FIXFIX:
|
|
55 switch (sbr->L_E[ch])
|
|
56 {
|
|
57 case 4:
|
10989
|
58 temp = (int) (sbr->numTimeSlots / 4);
|
|
59 sbr->t_E[ch][3] = sbr->rate * 3 * temp;
|
|
60 sbr->t_E[ch][2] = sbr->rate * 2 * temp;
|
|
61 sbr->t_E[ch][1] = sbr->rate * temp;
|
10725
|
62 break;
|
|
63 case 2:
|
10989
|
64 sbr->t_E[ch][1] = sbr->rate * (int) (sbr->numTimeSlots / 2);
|
10725
|
65 break;
|
|
66 default:
|
|
67 break;
|
|
68 }
|
|
69 break;
|
|
70
|
|
71 case FIXVAR:
|
|
72 if (sbr->L_E[ch] > 1)
|
|
73 {
|
|
74 int8_t i = sbr->L_E[ch];
|
|
75 border = sbr->abs_bord_trail[ch];
|
|
76
|
|
77 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
|
|
78 {
|
10989
|
79 if (border < sbr->bs_rel_bord[ch][l])
|
|
80 return 1;
|
|
81
|
10725
|
82 border -= sbr->bs_rel_bord[ch][l];
|
|
83 sbr->t_E[ch][--i] = sbr->rate * border;
|
|
84 }
|
|
85 }
|
|
86 break;
|
|
87
|
|
88 case VARFIX:
|
|
89 if (sbr->L_E[ch] > 1)
|
|
90 {
|
|
91 int8_t i = 1;
|
|
92 border = sbr->abs_bord_lead[ch];
|
|
93
|
|
94 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
|
|
95 {
|
|
96 border += sbr->bs_rel_bord[ch][l];
|
10989
|
97
|
|
98 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
|
|
99 return 1;
|
|
100
|
10725
|
101 sbr->t_E[ch][i++] = sbr->rate * border;
|
|
102 }
|
|
103 }
|
|
104 break;
|
|
105
|
|
106 case VARVAR:
|
|
107 if (sbr->bs_num_rel_0[ch])
|
|
108 {
|
|
109 int8_t i = 1;
|
|
110 border = sbr->abs_bord_lead[ch];
|
|
111
|
|
112 for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
|
|
113 {
|
|
114 border += sbr->bs_rel_bord_0[ch][l];
|
10989
|
115
|
|
116 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
|
|
117 return 1;
|
|
118
|
10725
|
119 sbr->t_E[ch][i++] = sbr->rate * border;
|
|
120 }
|
|
121 }
|
|
122
|
|
123 if (sbr->bs_num_rel_1[ch])
|
|
124 {
|
|
125 int8_t i = sbr->L_E[ch];
|
|
126 border = sbr->abs_bord_trail[ch];
|
|
127
|
|
128 for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
|
|
129 {
|
10989
|
130 if (border < sbr->bs_rel_bord_1[ch][l])
|
|
131 return 1;
|
|
132
|
10725
|
133 border -= sbr->bs_rel_bord_1[ch][l];
|
|
134 sbr->t_E[ch][--i] = sbr->rate * border;
|
|
135 }
|
|
136 }
|
|
137 break;
|
|
138 }
|
10989
|
139
|
|
140 return 0;
|
10725
|
141 }
|
|
142
|
|
143 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
|
|
144 {
|
|
145 sbr->t_Q[ch][0] = sbr->t_E[ch][0];
|
|
146
|
|
147 if (sbr->L_E[ch] == 1)
|
|
148 {
|
|
149 sbr->t_Q[ch][1] = sbr->t_E[ch][1];
|
|
150 sbr->t_Q[ch][2] = 0;
|
|
151 } else {
|
|
152 uint8_t index = middleBorder(sbr, ch);
|
|
153 sbr->t_Q[ch][1] = sbr->t_E[ch][index];
|
|
154 sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
|
|
155 }
|
|
156 }
|
|
157
|
|
158 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
|
|
159 {
|
|
160 uint8_t i;
|
|
161 int16_t acc = 0;
|
|
162
|
|
163 switch (sbr->bs_frame_class[ch])
|
|
164 {
|
|
165 case FIXFIX:
|
10989
|
166 return sbr->numTimeSlots/sbr->L_E[ch];
|
10725
|
167 case FIXVAR:
|
|
168 return 0;
|
|
169 case VARFIX:
|
|
170 for (i = 0; i < l; i++)
|
|
171 {
|
|
172 acc += sbr->bs_rel_bord[ch][i];
|
|
173 }
|
|
174 return acc;
|
|
175 case VARVAR:
|
|
176 for (i = 0; i < l; i++)
|
|
177 {
|
|
178 acc += sbr->bs_rel_bord_0[ch][i];
|
|
179 }
|
|
180 return acc;
|
|
181 }
|
|
182
|
|
183 return 0;
|
|
184 }
|
|
185
|
|
186 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
|
|
187 {
|
|
188 uint8_t i;
|
|
189 int16_t acc = 0;
|
|
190
|
|
191 switch (sbr->bs_frame_class[ch])
|
|
192 {
|
|
193 case FIXFIX:
|
|
194 case VARFIX:
|
|
195 return 0;
|
|
196 case FIXVAR:
|
|
197 for (i = 0; i < l; i++)
|
|
198 {
|
|
199 acc += sbr->bs_rel_bord[ch][i];
|
|
200 }
|
|
201 return acc;
|
|
202 case VARVAR:
|
|
203 for (i = 0; i < l; i++)
|
|
204 {
|
|
205 acc += sbr->bs_rel_bord_1[ch][i];
|
|
206 }
|
|
207 return acc;
|
|
208 }
|
|
209
|
|
210 return 0;
|
|
211 }
|
|
212
|
|
213 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
|
|
214 {
|
|
215 int8_t retval;
|
|
216
|
|
217 switch (sbr->bs_frame_class[ch])
|
|
218 {
|
|
219 case FIXFIX:
|
|
220 retval = sbr->L_E[ch]/2;
|
|
221 break;
|
|
222 case VARFIX:
|
|
223 if (sbr->bs_pointer[ch] == 0)
|
|
224 retval = 1;
|
|
225 else if (sbr->bs_pointer[ch] == 1)
|
|
226 retval = sbr->L_E[ch] - 1;
|
|
227 else
|
|
228 retval = sbr->bs_pointer[ch] - 1;
|
|
229 break;
|
|
230 case FIXVAR:
|
|
231 case VARVAR:
|
|
232 if (sbr->bs_pointer[ch] > 1)
|
|
233 retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
|
|
234 else
|
|
235 retval = sbr->L_E[ch] - 1;
|
|
236 break;
|
|
237 }
|
|
238
|
|
239 return (retval > 0) ? retval : 0;
|
|
240 }
|
|
241
|
|
242
|
|
243 #endif
|