comparison libfaad2/sbr_tf_grid.c @ 10725:e989150f8216

libfaad2 v2.0rc1 imported
author arpi
date Sat, 30 Aug 2003 22:30:28 +0000
parents
children 3185f64f6350
comparison
equal deleted inserted replaced
10724:adf5697b9d83 10725:e989150f8216
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 **
25 ** $Id: sbr_tf_grid.c,v 1.1 2003/07/29 08:20:13 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 void envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
41 {
42 uint8_t l, border;
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:
58 sbr->t_E[ch][3] = sbr->rate * 12;
59 sbr->t_E[ch][2] = sbr->rate * 8;
60 sbr->t_E[ch][1] = sbr->rate * 4;
61 break;
62 case 2:
63 sbr->t_E[ch][1] = sbr->rate * 8;
64 break;
65 default:
66 break;
67 }
68 break;
69
70 case FIXVAR:
71 if (sbr->L_E[ch] > 1)
72 {
73 int8_t i = sbr->L_E[ch];
74 border = sbr->abs_bord_trail[ch];
75
76 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
77 {
78 border -= sbr->bs_rel_bord[ch][l];
79 sbr->t_E[ch][--i] = sbr->rate * border;
80 }
81 }
82 break;
83
84 case VARFIX:
85 if (sbr->L_E[ch] > 1)
86 {
87 int8_t i = 1;
88 border = sbr->abs_bord_lead[ch];
89
90 for (l = 0; l < (sbr->L_E[ch] - 1); l++)
91 {
92 border += sbr->bs_rel_bord[ch][l];
93 sbr->t_E[ch][i++] = sbr->rate * border;
94 }
95 }
96 break;
97
98 case VARVAR:
99 if (sbr->bs_num_rel_0[ch])
100 {
101 int8_t i = 1;
102 border = sbr->abs_bord_lead[ch];
103
104 for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
105 {
106 border += sbr->bs_rel_bord_0[ch][l];
107 sbr->t_E[ch][i++] = sbr->rate * border;
108 }
109 }
110
111 if (sbr->bs_num_rel_1[ch])
112 {
113 int8_t i = sbr->L_E[ch];
114 border = sbr->abs_bord_trail[ch];
115
116 for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
117 {
118 border -= sbr->bs_rel_bord_1[ch][l];
119 sbr->t_E[ch][--i] = sbr->rate * border;
120 }
121 }
122 break;
123 }
124 }
125
126 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
127 {
128 sbr->t_Q[ch][0] = sbr->t_E[ch][0];
129
130 if (sbr->L_E[ch] == 1)
131 {
132 sbr->t_Q[ch][1] = sbr->t_E[ch][1];
133 sbr->t_Q[ch][2] = 0;
134 } else {
135 uint8_t index = middleBorder(sbr, ch);
136 sbr->t_Q[ch][1] = sbr->t_E[ch][index];
137 sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
138 }
139 }
140
141 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
142 {
143 uint8_t i;
144 int16_t acc = 0;
145
146 switch (sbr->bs_frame_class[ch])
147 {
148 case FIXFIX:
149 return NO_TIME_SLOTS/sbr->L_E[ch];
150 case FIXVAR:
151 return 0;
152 case VARFIX:
153 for (i = 0; i < l; i++)
154 {
155 acc += sbr->bs_rel_bord[ch][i];
156 }
157 return acc;
158 case VARVAR:
159 for (i = 0; i < l; i++)
160 {
161 acc += sbr->bs_rel_bord_0[ch][i];
162 }
163 return acc;
164 }
165
166 return 0;
167 }
168
169 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
170 {
171 uint8_t i;
172 int16_t acc = 0;
173
174 switch (sbr->bs_frame_class[ch])
175 {
176 case FIXFIX:
177 case VARFIX:
178 return 0;
179 case FIXVAR:
180 for (i = 0; i < l; i++)
181 {
182 acc += sbr->bs_rel_bord[ch][i];
183 }
184 return acc;
185 case VARVAR:
186 for (i = 0; i < l; i++)
187 {
188 acc += sbr->bs_rel_bord_1[ch][i];
189 }
190 return acc;
191 }
192
193 return 0;
194 }
195
196 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
197 {
198 int8_t retval;
199
200 switch (sbr->bs_frame_class[ch])
201 {
202 case FIXFIX:
203 retval = sbr->L_E[ch]/2;
204 break;
205 case VARFIX:
206 if (sbr->bs_pointer[ch] == 0)
207 retval = 1;
208 else if (sbr->bs_pointer[ch] == 1)
209 retval = sbr->L_E[ch] - 1;
210 else
211 retval = sbr->bs_pointer[ch] - 1;
212 break;
213 case FIXVAR:
214 case VARVAR:
215 if (sbr->bs_pointer[ch] > 1)
216 retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
217 else
218 retval = sbr->L_E[ch] - 1;
219 break;
220 }
221
222 return (retval > 0) ? retval : 0;
223 }
224
225
226 #endif