/proc/self/cwd/libfaad/sbr_syntax.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | | ** Copyright (C) 2003-2005 M. Bakker, Nero 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 | | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | | ** |
25 | | ** Commercial non-GPL licensing of this software is possible. |
26 | | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | | ** |
28 | | ** $Id: sbr_syntax.c,v 1.39 2009/01/26 22:32:31 menno Exp $ |
29 | | **/ |
30 | | |
31 | | #include "common.h" |
32 | | #include "structs.h" |
33 | | |
34 | | #ifdef SBR_DEC |
35 | | |
36 | | #include "sbr_syntax.h" |
37 | | #include "syntax.h" |
38 | | #include "sbr_huff.h" |
39 | | #include "sbr_fbt.h" |
40 | | #include "sbr_tf_grid.h" |
41 | | #include "sbr_e_nf.h" |
42 | | #include "bits.h" |
43 | | #ifdef PS_DEC |
44 | | #include "ps_dec.h" |
45 | | #endif |
46 | | #ifdef DRM_PS |
47 | | #include "drm_dec.h" |
48 | | #endif |
49 | | #include "analysis.h" |
50 | | |
51 | | /* static function declarations */ |
52 | | /* static function declarations */ |
53 | | static void sbr_header(bitfile *ld, sbr_info *sbr); |
54 | | static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq, |
55 | | uint8_t samplerate_mode, uint8_t freq_scale, |
56 | | uint8_t alter_scale, uint8_t xover_band); |
57 | | static uint8_t sbr_data(bitfile *ld, sbr_info *sbr); |
58 | | static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr, |
59 | | uint8_t bs_extension_id, uint16_t num_bits_left); |
60 | | static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr); |
61 | | static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr); |
62 | | static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch); |
63 | | static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch); |
64 | | static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch); |
65 | | static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch); |
66 | | |
67 | | |
68 | | static void sbr_reset(sbr_info *sbr) |
69 | 0 | { |
70 | | #if 0 |
71 | | printf("%d\n", sbr->bs_start_freq_prev); |
72 | | printf("%d\n", sbr->bs_stop_freq_prev); |
73 | | printf("%d\n", sbr->bs_freq_scale_prev); |
74 | | printf("%d\n", sbr->bs_alter_scale_prev); |
75 | | printf("%d\n", sbr->bs_xover_band_prev); |
76 | | printf("%d\n\n", sbr->bs_noise_bands_prev); |
77 | | #endif |
78 | | |
79 | | /* if these are different from the previous frame: Reset = 1 */ |
80 | 0 | if ((sbr->bs_start_freq != sbr->bs_start_freq_prev) || |
81 | 0 | (sbr->bs_stop_freq != sbr->bs_stop_freq_prev) || |
82 | 0 | (sbr->bs_freq_scale != sbr->bs_freq_scale_prev) || |
83 | 0 | (sbr->bs_alter_scale != sbr->bs_alter_scale_prev) || |
84 | 0 | (sbr->bs_xover_band != sbr->bs_xover_band_prev) || |
85 | 0 | (sbr->bs_noise_bands != sbr->bs_noise_bands_prev)) |
86 | 0 | { |
87 | 0 | sbr->Reset = 1; |
88 | 0 | } else { |
89 | 0 | sbr->Reset = 0; |
90 | 0 | } |
91 | |
|
92 | 0 | sbr->bs_start_freq_prev = sbr->bs_start_freq; |
93 | 0 | sbr->bs_stop_freq_prev = sbr->bs_stop_freq; |
94 | 0 | sbr->bs_freq_scale_prev = sbr->bs_freq_scale; |
95 | 0 | sbr->bs_alter_scale_prev = sbr->bs_alter_scale; |
96 | 0 | sbr->bs_xover_band_prev = sbr->bs_xover_band; |
97 | 0 | sbr->bs_noise_bands_prev = sbr->bs_noise_bands; |
98 | 0 | } |
99 | | |
100 | | static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq, |
101 | | uint8_t samplerate_mode, uint8_t freq_scale, |
102 | | uint8_t alter_scale, uint8_t xover_band) |
103 | 0 | { |
104 | 0 | uint8_t result = 0; |
105 | 0 | uint8_t k2; |
106 | | |
107 | | /* calculate the Master Frequency Table */ |
108 | 0 | sbr->k0 = qmf_start_channel(start_freq, samplerate_mode, sbr->sample_rate); |
109 | 0 | k2 = qmf_stop_channel(stop_freq, sbr->sample_rate, sbr->k0); |
110 | | |
111 | | /* check k0 and k2 */ |
112 | 0 | if (sbr->sample_rate >= 48000) |
113 | 0 | { |
114 | 0 | if ((k2 - sbr->k0) > 32) |
115 | 0 | result += 1; |
116 | 0 | } else if (sbr->sample_rate <= 32000) { |
117 | 0 | if ((k2 - sbr->k0) > 48) |
118 | 0 | result += 1; |
119 | 0 | } else { /* (sbr->sample_rate == 44100) */ |
120 | 0 | if ((k2 - sbr->k0) > 45) |
121 | 0 | result += 1; |
122 | 0 | } |
123 | |
|
124 | 0 | if (freq_scale == 0) |
125 | 0 | { |
126 | 0 | result += master_frequency_table_fs0(sbr, sbr->k0, k2, alter_scale); |
127 | 0 | } else { |
128 | 0 | result += master_frequency_table(sbr, sbr->k0, k2, freq_scale, alter_scale); |
129 | 0 | } |
130 | 0 | result += derived_frequency_table(sbr, xover_band, k2); |
131 | |
|
132 | 0 | result = (result > 0) ? 1 : 0; |
133 | |
|
134 | 0 | return result; |
135 | 0 | } |
136 | | |
137 | | /* table 2 */ |
138 | | uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt, |
139 | | uint8_t psResetFlag) |
140 | 0 | { |
141 | 0 | uint8_t result = 0; |
142 | 0 | uint16_t num_align_bits = 0; |
143 | 0 | uint16_t num_sbr_bits1 = (uint16_t)faad_get_processed_bits(ld); |
144 | 0 | uint16_t num_sbr_bits2; |
145 | |
|
146 | 0 | uint8_t saved_start_freq, saved_samplerate_mode; |
147 | 0 | uint8_t saved_stop_freq, saved_freq_scale; |
148 | 0 | uint8_t saved_alter_scale, saved_xover_band; |
149 | |
|
150 | 0 | #if (defined(PS_DEC) || defined(DRM_PS)) |
151 | 0 | if (psResetFlag) |
152 | 0 | sbr->psResetFlag = psResetFlag; |
153 | 0 | #endif |
154 | |
|
155 | | #ifdef DRM |
156 | | if (!sbr->Is_DRM_SBR) |
157 | | #endif |
158 | 0 | { |
159 | 0 | uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4 |
160 | 0 | DEBUGVAR(1,198,"sbr_bitstream(): bs_extension_type")); |
161 | |
|
162 | 0 | if (bs_extension_type == EXT_SBR_DATA_CRC) |
163 | 0 | { |
164 | 0 | sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10 |
165 | 0 | DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits")); |
166 | 0 | } |
167 | 0 | } |
168 | | |
169 | | /* save old header values, in case the new ones are corrupted */ |
170 | 0 | saved_start_freq = sbr->bs_start_freq; |
171 | 0 | saved_samplerate_mode = sbr->bs_samplerate_mode; |
172 | 0 | saved_stop_freq = sbr->bs_stop_freq; |
173 | 0 | saved_freq_scale = sbr->bs_freq_scale; |
174 | 0 | saved_alter_scale = sbr->bs_alter_scale; |
175 | 0 | saved_xover_band = sbr->bs_xover_band; |
176 | |
|
177 | 0 | sbr->bs_header_flag = faad_get1bit(ld |
178 | 0 | DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag")); |
179 | |
|
180 | 0 | if (sbr->bs_header_flag) |
181 | 0 | sbr_header(ld, sbr); |
182 | | |
183 | | /* Reset? */ |
184 | 0 | sbr_reset(sbr); |
185 | | |
186 | | /* first frame should have a header */ |
187 | | //if (!(sbr->frame == 0 && sbr->bs_header_flag == 0)) |
188 | 0 | if (sbr->header_count != 0) |
189 | 0 | { |
190 | 0 | if (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked)) |
191 | 0 | { |
192 | 0 | uint8_t rt = calc_sbr_tables(sbr, sbr->bs_start_freq, sbr->bs_stop_freq, |
193 | 0 | sbr->bs_samplerate_mode, sbr->bs_freq_scale, |
194 | 0 | sbr->bs_alter_scale, sbr->bs_xover_band); |
195 | | |
196 | | /* if an error occured with the new header values revert to the old ones */ |
197 | 0 | if (rt > 0) |
198 | 0 | { |
199 | 0 | result += calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq, |
200 | 0 | saved_samplerate_mode, saved_freq_scale, |
201 | 0 | saved_alter_scale, saved_xover_band); |
202 | 0 | } |
203 | 0 | } |
204 | |
|
205 | 0 | if (result == 0) |
206 | 0 | { |
207 | 0 | result = sbr_data(ld, sbr); |
208 | | |
209 | | /* sbr_data() returning an error means that there was an error in |
210 | | envelope_time_border_vector(). |
211 | | In this case the old time border vector is saved and all the previous |
212 | | data normally read after sbr_grid() is saved. |
213 | | */ |
214 | | /* to be on the safe side, calculate old sbr tables in case of error */ |
215 | 0 | if ((result > 0) && |
216 | 0 | (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked))) |
217 | 0 | { |
218 | 0 | result += calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq, |
219 | 0 | saved_samplerate_mode, saved_freq_scale, |
220 | 0 | saved_alter_scale, saved_xover_band); |
221 | 0 | } |
222 | | |
223 | | /* we should be able to safely set result to 0 now, */ |
224 | | /* but practise indicates this doesn't work well */ |
225 | 0 | } |
226 | 0 | } else { |
227 | 0 | result = 1; |
228 | 0 | } |
229 | |
|
230 | 0 | num_sbr_bits2 = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits1; |
231 | | |
232 | | /* check if we read more bits then were available for sbr */ |
233 | 0 | if (8*cnt < num_sbr_bits2) |
234 | 0 | { |
235 | 0 | faad_resetbits(ld, num_sbr_bits1 + 8u * cnt); |
236 | 0 | num_sbr_bits2 = 8*cnt; |
237 | |
|
238 | 0 | #ifdef PS_DEC |
239 | | /* turn off PS for the unfortunate case that we randomly read some |
240 | | * PS data that looks correct */ |
241 | 0 | sbr->ps_used = 0; |
242 | 0 | #endif |
243 | | |
244 | | /* Make sure it doesn't decode SBR in this frame, or we'll get glitches */ |
245 | 0 | return 1; |
246 | 0 | } |
247 | | |
248 | | #ifdef DRM |
249 | | if (!sbr->Is_DRM_SBR) |
250 | | #endif |
251 | 0 | { |
252 | | /* -4 does not apply, bs_extension_type is re-read in this function */ |
253 | 0 | num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits2; |
254 | |
|
255 | 0 | while (num_align_bits > 7) |
256 | 0 | { |
257 | 0 | faad_getbits(ld, 8 |
258 | 0 | DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits")); |
259 | 0 | num_align_bits -= 8; |
260 | 0 | } |
261 | 0 | faad_getbits(ld, num_align_bits |
262 | 0 | DEBUGVAR(1,999,"sbr_bitstream(): num_align_bits")); |
263 | 0 | } |
264 | |
|
265 | 0 | return result; |
266 | 0 | } |
267 | | |
268 | | /* table 3 */ |
269 | | static void sbr_header(bitfile *ld, sbr_info *sbr) |
270 | 0 | { |
271 | 0 | uint8_t bs_header_extra_1, bs_header_extra_2; |
272 | |
|
273 | 0 | sbr->header_count++; |
274 | |
|
275 | 0 | sbr->bs_amp_res = faad_get1bit(ld |
276 | 0 | DEBUGVAR(1,203,"sbr_header(): bs_amp_res")); |
277 | | |
278 | | /* bs_start_freq and bs_stop_freq must define a fequency band that does |
279 | | not exceed 48 channels */ |
280 | 0 | sbr->bs_start_freq = (uint8_t)faad_getbits(ld, 4 |
281 | 0 | DEBUGVAR(1,204,"sbr_header(): bs_start_freq")); |
282 | 0 | sbr->bs_stop_freq = (uint8_t)faad_getbits(ld, 4 |
283 | 0 | DEBUGVAR(1,205,"sbr_header(): bs_stop_freq")); |
284 | 0 | sbr->bs_xover_band = (uint8_t)faad_getbits(ld, 3 |
285 | 0 | DEBUGVAR(1,206,"sbr_header(): bs_xover_band")); |
286 | 0 | faad_getbits(ld, 2 |
287 | 0 | DEBUGVAR(1,207,"sbr_header(): bs_reserved_bits_hdr")); |
288 | 0 | bs_header_extra_1 = (uint8_t)faad_get1bit(ld |
289 | 0 | DEBUGVAR(1,208,"sbr_header(): bs_header_extra_1")); |
290 | 0 | bs_header_extra_2 = (uint8_t)faad_get1bit(ld |
291 | 0 | DEBUGVAR(1,209,"sbr_header(): bs_header_extra_2")); |
292 | |
|
293 | 0 | if (bs_header_extra_1) |
294 | 0 | { |
295 | 0 | sbr->bs_freq_scale = (uint8_t)faad_getbits(ld, 2 |
296 | 0 | DEBUGVAR(1,211,"sbr_header(): bs_freq_scale")); |
297 | 0 | sbr->bs_alter_scale = (uint8_t)faad_get1bit(ld |
298 | 0 | DEBUGVAR(1,212,"sbr_header(): bs_alter_scale")); |
299 | 0 | sbr->bs_noise_bands = (uint8_t)faad_getbits(ld, 2 |
300 | 0 | DEBUGVAR(1,213,"sbr_header(): bs_noise_bands")); |
301 | 0 | } else { |
302 | | /* Default values */ |
303 | 0 | sbr->bs_freq_scale = 2; |
304 | 0 | sbr->bs_alter_scale = 1; |
305 | 0 | sbr->bs_noise_bands = 2; |
306 | 0 | } |
307 | |
|
308 | 0 | if (bs_header_extra_2) |
309 | 0 | { |
310 | 0 | sbr->bs_limiter_bands = (uint8_t)faad_getbits(ld, 2 |
311 | 0 | DEBUGVAR(1,214,"sbr_header(): bs_limiter_bands")); |
312 | 0 | sbr->bs_limiter_gains = (uint8_t)faad_getbits(ld, 2 |
313 | 0 | DEBUGVAR(1,215,"sbr_header(): bs_limiter_gains")); |
314 | 0 | sbr->bs_interpol_freq = (uint8_t)faad_get1bit(ld |
315 | 0 | DEBUGVAR(1,216,"sbr_header(): bs_interpol_freq")); |
316 | 0 | sbr->bs_smoothing_mode = (uint8_t)faad_get1bit(ld |
317 | 0 | DEBUGVAR(1,217,"sbr_header(): bs_smoothing_mode")); |
318 | 0 | } else { |
319 | | /* Default values */ |
320 | 0 | sbr->bs_limiter_bands = 2; |
321 | 0 | sbr->bs_limiter_gains = 2; |
322 | 0 | sbr->bs_interpol_freq = 1; |
323 | 0 | sbr->bs_smoothing_mode = 1; |
324 | 0 | } |
325 | |
|
326 | | #if 0 |
327 | | /* print the header to screen */ |
328 | | printf("bs_amp_res: %d\n", sbr->bs_amp_res); |
329 | | printf("bs_start_freq: %d\n", sbr->bs_start_freq); |
330 | | printf("bs_stop_freq: %d\n", sbr->bs_stop_freq); |
331 | | printf("bs_xover_band: %d\n", sbr->bs_xover_band); |
332 | | if (bs_header_extra_1) |
333 | | { |
334 | | printf("bs_freq_scale: %d\n", sbr->bs_freq_scale); |
335 | | printf("bs_alter_scale: %d\n", sbr->bs_alter_scale); |
336 | | printf("bs_noise_bands: %d\n", sbr->bs_noise_bands); |
337 | | } |
338 | | if (bs_header_extra_2) |
339 | | { |
340 | | printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands); |
341 | | printf("bs_limiter_gains: %d\n", sbr->bs_limiter_gains); |
342 | | printf("bs_interpol_freq: %d\n", sbr->bs_interpol_freq); |
343 | | printf("bs_smoothing_mode: %d\n", sbr->bs_smoothing_mode); |
344 | | } |
345 | | printf("\n"); |
346 | | #endif |
347 | 0 | } |
348 | | |
349 | | /* table 4 */ |
350 | | static uint8_t sbr_data(bitfile *ld, sbr_info *sbr) |
351 | 0 | { |
352 | 0 | uint8_t result; |
353 | | #if 0 |
354 | | sbr->bs_samplerate_mode = faad_get1bit(ld |
355 | | DEBUGVAR(1,219,"sbr_data(): bs_samplerate_mode")); |
356 | | #endif |
357 | |
|
358 | 0 | sbr->rate = (sbr->bs_samplerate_mode) ? 2 : 1; |
359 | |
|
360 | 0 | switch (sbr->id_aac) |
361 | 0 | { |
362 | 0 | case ID_SCE: |
363 | 0 | if ((result = sbr_single_channel_element(ld, sbr)) > 0) |
364 | 0 | return result; |
365 | 0 | break; |
366 | 0 | case ID_CPE: |
367 | 0 | if ((result = sbr_channel_pair_element(ld, sbr)) > 0) |
368 | 0 | return result; |
369 | 0 | break; |
370 | 0 | } |
371 | | |
372 | 0 | return 0; |
373 | 0 | } |
374 | | |
375 | | /* table 5 */ |
376 | | static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr) |
377 | 0 | { |
378 | 0 | uint8_t result; |
379 | |
|
380 | 0 | if (faad_get1bit(ld |
381 | 0 | DEBUGVAR(1,220,"sbr_single_channel_element(): bs_data_extra"))) |
382 | 0 | { |
383 | 0 | faad_getbits(ld, 4 |
384 | 0 | DEBUGVAR(1,221,"sbr_single_channel_element(): bs_reserved_bits_data")); |
385 | 0 | } |
386 | |
|
387 | | #ifdef DRM |
388 | | /* bs_coupling, from sbr_channel_pair_base_element(bs_amp_res) */ |
389 | | if (sbr->Is_DRM_SBR) |
390 | | { |
391 | | faad_get1bit(ld); |
392 | | } |
393 | | #endif |
394 | |
|
395 | 0 | if ((result = sbr_grid(ld, sbr, 0)) > 0) |
396 | 0 | return result; |
397 | | |
398 | 0 | sbr_dtdf(ld, sbr, 0); |
399 | 0 | invf_mode(ld, sbr, 0); |
400 | 0 | sbr_envelope(ld, sbr, 0); |
401 | 0 | sbr_noise(ld, sbr, 0); |
402 | |
|
403 | 0 | #ifndef FIXED_POINT |
404 | 0 | envelope_noise_dequantisation(sbr, 0); |
405 | 0 | #endif |
406 | |
|
407 | 0 | memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); |
408 | |
|
409 | 0 | sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld |
410 | 0 | DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]")); |
411 | 0 | if (sbr->bs_add_harmonic_flag[0]) |
412 | 0 | sinusoidal_coding(ld, sbr, 0); |
413 | |
|
414 | 0 | sbr->bs_extended_data = faad_get1bit(ld |
415 | 0 | DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]")); |
416 | |
|
417 | 0 | if (sbr->bs_extended_data) |
418 | 0 | { |
419 | 0 | uint16_t nr_bits_left; |
420 | 0 | #if (defined(PS_DEC) || defined(DRM_PS)) |
421 | 0 | uint8_t ps_ext_read = 0; |
422 | 0 | #endif |
423 | 0 | uint16_t cnt = (uint16_t)faad_getbits(ld, 4 |
424 | 0 | DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size")); |
425 | 0 | if (cnt == 15) |
426 | 0 | { |
427 | 0 | cnt += (uint16_t)faad_getbits(ld, 8 |
428 | 0 | DEBUGVAR(1,226,"sbr_single_channel_element(): bs_esc_count")); |
429 | 0 | } |
430 | |
|
431 | 0 | nr_bits_left = 8 * cnt; |
432 | 0 | while (nr_bits_left > 7) |
433 | 0 | { |
434 | 0 | uint16_t tmp_nr_bits = 0; |
435 | |
|
436 | 0 | sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
437 | 0 | DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id")); |
438 | 0 | tmp_nr_bits += 2; |
439 | | |
440 | | /* allow only 1 PS extension element per extension data */ |
441 | 0 | #if (defined(PS_DEC) || defined(DRM_PS)) |
442 | | #if (defined(PS_DEC) && defined(DRM_PS)) |
443 | | if (sbr->bs_extension_id == EXTENSION_ID_PS || sbr->bs_extension_id == DRM_PARAMETRIC_STEREO) |
444 | | #else |
445 | 0 | #ifdef PS_DEC |
446 | 0 | if (sbr->bs_extension_id == EXTENSION_ID_PS) |
447 | | #else |
448 | | #ifdef DRM_PS |
449 | | if (sbr->bs_extension_id == DRM_PARAMETRIC_STEREO) |
450 | | #endif |
451 | | #endif |
452 | 0 | #endif |
453 | 0 | { |
454 | 0 | if (ps_ext_read == 0) |
455 | 0 | { |
456 | 0 | ps_ext_read = 1; |
457 | 0 | } else { |
458 | | /* to be safe make it 3, will switch to "default" |
459 | | * in sbr_extension() */ |
460 | | #ifdef DRM |
461 | | return 1; |
462 | | #else |
463 | 0 | sbr->bs_extension_id = 3; |
464 | 0 | #endif |
465 | 0 | } |
466 | 0 | } |
467 | 0 | #endif |
468 | |
|
469 | 0 | tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); |
470 | | |
471 | | /* check if the data read is bigger than the number of available bits */ |
472 | 0 | if (tmp_nr_bits > nr_bits_left) |
473 | 0 | return 1; |
474 | | |
475 | 0 | nr_bits_left -= tmp_nr_bits; |
476 | 0 | } |
477 | | |
478 | | /* Corrigendum */ |
479 | 0 | if (nr_bits_left > 0) |
480 | 0 | { |
481 | 0 | faad_getbits(ld, nr_bits_left |
482 | 0 | DEBUGVAR(1,280,"sbr_single_channel_element(): nr_bits_left")); |
483 | 0 | } |
484 | 0 | } |
485 | | |
486 | 0 | return 0; |
487 | 0 | } |
488 | | |
489 | | /* table 6 */ |
490 | | static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr) |
491 | 0 | { |
492 | 0 | uint8_t n, result; |
493 | |
|
494 | 0 | if (faad_get1bit(ld |
495 | 0 | DEBUGVAR(1,228,"sbr_single_channel_element(): bs_data_extra"))) |
496 | 0 | { |
497 | 0 | faad_getbits(ld, 4 |
498 | 0 | DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_reserved_bits_data")); |
499 | 0 | faad_getbits(ld, 4 |
500 | 0 | DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_reserved_bits_data")); |
501 | 0 | } |
502 | |
|
503 | 0 | sbr->bs_coupling = faad_get1bit(ld |
504 | 0 | DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_coupling")); |
505 | |
|
506 | 0 | if (sbr->bs_coupling) |
507 | 0 | { |
508 | 0 | if ((result = sbr_grid(ld, sbr, 0)) > 0) |
509 | 0 | return result; |
510 | | |
511 | | /* need to copy some data from left to right */ |
512 | 0 | sbr->bs_frame_class[1] = sbr->bs_frame_class[0]; |
513 | 0 | sbr->L_E[1] = sbr->L_E[0]; |
514 | 0 | sbr->L_Q[1] = sbr->L_Q[0]; |
515 | 0 | sbr->bs_pointer[1] = sbr->bs_pointer[0]; |
516 | |
|
517 | 0 | for (n = 0; n <= sbr->L_E[0]; n++) |
518 | 0 | { |
519 | 0 | sbr->t_E[1][n] = sbr->t_E[0][n]; |
520 | 0 | sbr->f[1][n] = sbr->f[0][n]; |
521 | 0 | } |
522 | 0 | for (n = 0; n <= sbr->L_Q[0]; n++) |
523 | 0 | sbr->t_Q[1][n] = sbr->t_Q[0][n]; |
524 | |
|
525 | 0 | sbr_dtdf(ld, sbr, 0); |
526 | 0 | sbr_dtdf(ld, sbr, 1); |
527 | 0 | invf_mode(ld, sbr, 0); |
528 | | |
529 | | /* more copying */ |
530 | 0 | for (n = 0; n < sbr->N_Q; n++) |
531 | 0 | sbr->bs_invf_mode[1][n] = sbr->bs_invf_mode[0][n]; |
532 | |
|
533 | 0 | sbr_envelope(ld, sbr, 0); |
534 | 0 | sbr_noise(ld, sbr, 0); |
535 | 0 | sbr_envelope(ld, sbr, 1); |
536 | 0 | sbr_noise(ld, sbr, 1); |
537 | |
|
538 | 0 | memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); |
539 | 0 | memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t)); |
540 | |
|
541 | 0 | sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld |
542 | 0 | DEBUGVAR(1,231,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]")); |
543 | 0 | if (sbr->bs_add_harmonic_flag[0]) |
544 | 0 | sinusoidal_coding(ld, sbr, 0); |
545 | |
|
546 | 0 | sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld |
547 | 0 | DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
548 | 0 | if (sbr->bs_add_harmonic_flag[1]) |
549 | 0 | sinusoidal_coding(ld, sbr, 1); |
550 | 0 | } else { |
551 | 0 | uint8_t saved_t_E[6] = {0}, saved_t_Q[3] = {0}; |
552 | 0 | uint8_t saved_L_E = sbr->L_E[0]; |
553 | 0 | uint8_t saved_L_Q = sbr->L_Q[0]; |
554 | 0 | uint8_t saved_frame_class = sbr->bs_frame_class[0]; |
555 | |
|
556 | 0 | for (n = 0; n < saved_L_E; n++) |
557 | 0 | saved_t_E[n] = sbr->t_E[0][n]; |
558 | 0 | for (n = 0; n < saved_L_Q; n++) |
559 | 0 | saved_t_Q[n] = sbr->t_Q[0][n]; |
560 | |
|
561 | 0 | if ((result = sbr_grid(ld, sbr, 0)) > 0) |
562 | 0 | return result; |
563 | 0 | if ((result = sbr_grid(ld, sbr, 1)) > 0) |
564 | 0 | { |
565 | | /* restore first channel data as well */ |
566 | 0 | sbr->bs_frame_class[0] = saved_frame_class; |
567 | 0 | sbr->L_E[0] = saved_L_E; |
568 | 0 | sbr->L_Q[0] = saved_L_Q; |
569 | 0 | for (n = 0; n < 6; n++) |
570 | 0 | sbr->t_E[0][n] = saved_t_E[n]; |
571 | 0 | for (n = 0; n < 3; n++) |
572 | 0 | sbr->t_Q[0][n] = saved_t_Q[n]; |
573 | |
|
574 | 0 | return result; |
575 | 0 | } |
576 | 0 | sbr_dtdf(ld, sbr, 0); |
577 | 0 | sbr_dtdf(ld, sbr, 1); |
578 | 0 | invf_mode(ld, sbr, 0); |
579 | 0 | invf_mode(ld, sbr, 1); |
580 | 0 | sbr_envelope(ld, sbr, 0); |
581 | 0 | sbr_envelope(ld, sbr, 1); |
582 | 0 | sbr_noise(ld, sbr, 0); |
583 | 0 | sbr_noise(ld, sbr, 1); |
584 | |
|
585 | 0 | memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); |
586 | 0 | memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t)); |
587 | |
|
588 | 0 | sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld |
589 | 0 | DEBUGVAR(1,239,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]")); |
590 | 0 | if (sbr->bs_add_harmonic_flag[0]) |
591 | 0 | sinusoidal_coding(ld, sbr, 0); |
592 | |
|
593 | 0 | sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld |
594 | 0 | DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
595 | 0 | if (sbr->bs_add_harmonic_flag[1]) |
596 | 0 | sinusoidal_coding(ld, sbr, 1); |
597 | 0 | } |
598 | 0 | #ifndef FIXED_POINT |
599 | 0 | envelope_noise_dequantisation(sbr, 0); |
600 | 0 | envelope_noise_dequantisation(sbr, 1); |
601 | |
|
602 | 0 | if (sbr->bs_coupling) |
603 | 0 | unmap_envelope_noise(sbr); |
604 | 0 | #endif |
605 | |
|
606 | 0 | sbr->bs_extended_data = faad_get1bit(ld |
607 | 0 | DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]")); |
608 | 0 | if (sbr->bs_extended_data) |
609 | 0 | { |
610 | 0 | uint16_t nr_bits_left; |
611 | 0 | uint16_t cnt = (uint16_t)faad_getbits(ld, 4 |
612 | 0 | DEBUGVAR(1,234,"sbr_channel_pair_element(): bs_extension_size")); |
613 | 0 | if (cnt == 15) |
614 | 0 | { |
615 | 0 | cnt += (uint16_t)faad_getbits(ld, 8 |
616 | 0 | DEBUGVAR(1,235,"sbr_channel_pair_element(): bs_esc_count")); |
617 | 0 | } |
618 | |
|
619 | 0 | nr_bits_left = 8 * cnt; |
620 | 0 | while (nr_bits_left > 7) |
621 | 0 | { |
622 | 0 | uint16_t tmp_nr_bits = 0; |
623 | |
|
624 | 0 | sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
625 | 0 | DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id")); |
626 | 0 | tmp_nr_bits += 2; |
627 | 0 | tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); |
628 | | |
629 | | /* check if the data read is bigger than the number of available bits */ |
630 | 0 | if (tmp_nr_bits > nr_bits_left) |
631 | 0 | return 1; |
632 | | |
633 | 0 | nr_bits_left -= tmp_nr_bits; |
634 | 0 | } |
635 | | |
636 | | /* Corrigendum */ |
637 | 0 | if (nr_bits_left > 0) |
638 | 0 | { |
639 | 0 | faad_getbits(ld, nr_bits_left |
640 | 0 | DEBUGVAR(1,280,"sbr_channel_pair_element(): nr_bits_left")); |
641 | 0 | } |
642 | 0 | } |
643 | | |
644 | 0 | return 0; |
645 | 0 | } |
646 | | |
647 | | /* integer log[2](x): input range [0,10) */ |
648 | | static uint8_t sbr_log2(const uint8_t val) |
649 | 0 | { |
650 | 0 | uint8_t log2tab[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4 }; |
651 | 0 | if (val < 10 && val >= 0) |
652 | 0 | return log2tab[val]; |
653 | 0 | else |
654 | 0 | return 0; |
655 | 0 | } |
656 | | |
657 | | |
658 | | /* table 7 */ |
659 | | static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch) |
660 | 0 | { |
661 | 0 | uint8_t i, j, env, rel, result; |
662 | 0 | uint8_t bs_abs_bord, bs_abs_bord_1; |
663 | 0 | uint8_t bs_num_env = 0; |
664 | 0 | uint8_t saved_L_E = sbr->L_E[ch]; |
665 | 0 | uint8_t saved_L_Q = sbr->L_Q[ch]; |
666 | 0 | uint8_t saved_frame_class = sbr->bs_frame_class[ch]; |
667 | |
|
668 | 0 | sbr->bs_frame_class[ch] = (uint8_t)faad_getbits(ld, 2 |
669 | 0 | DEBUGVAR(1,248,"sbr_grid(): bs_frame_class")); |
670 | |
|
671 | 0 | switch (sbr->bs_frame_class[ch]) |
672 | 0 | { |
673 | 0 | case FIXFIX: |
674 | 0 | i = (uint8_t)faad_getbits(ld, 2 |
675 | 0 | DEBUGVAR(1,249,"sbr_grid(): bs_num_env_raw")); |
676 | |
|
677 | 0 | bs_num_env = min(1u << i, 5u); |
678 | |
|
679 | 0 | i = (uint8_t)faad_get1bit(ld |
680 | 0 | DEBUGVAR(1,250,"sbr_grid(): bs_freq_res_flag")); |
681 | 0 | for (env = 0; env < bs_num_env; env++) |
682 | 0 | sbr->f[ch][env] = i; |
683 | |
|
684 | 0 | sbr->abs_bord_lead[ch] = 0; |
685 | 0 | sbr->abs_bord_trail[ch] = sbr->numTimeSlots; |
686 | 0 | sbr->n_rel_lead[ch] = bs_num_env - 1; |
687 | 0 | sbr->n_rel_trail[ch] = 0; |
688 | 0 | break; |
689 | | |
690 | 0 | case FIXVAR: |
691 | 0 | bs_abs_bord = (uint8_t)faad_getbits(ld, 2 |
692 | 0 | DEBUGVAR(1,251,"sbr_grid(): bs_abs_bord")) + sbr->numTimeSlots; |
693 | 0 | bs_num_env = (uint8_t)faad_getbits(ld, 2 |
694 | 0 | DEBUGVAR(1,252,"sbr_grid(): bs_num_env")) + 1; |
695 | |
|
696 | 0 | for (rel = 0; rel < bs_num_env-1; rel++) |
697 | 0 | { |
698 | 0 | sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
699 | 0 | DEBUGVAR(1,253,"sbr_grid(): bs_rel_bord")) + 2; |
700 | 0 | } |
701 | 0 | j = bs_num_env; |
702 | 0 | i = sbr_log2(j + 1); |
703 | 0 | sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
704 | 0 | DEBUGVAR(1,254,"sbr_grid(): bs_pointer")); |
705 | 0 | sbr->bs_pointer[ch] = min(sbr->bs_pointer[ch], j); |
706 | |
|
707 | 0 | for (env = 0; env < bs_num_env; env++) |
708 | 0 | { |
709 | 0 | sbr->f[ch][bs_num_env - env - 1] = (uint8_t)faad_get1bit(ld |
710 | 0 | DEBUGVAR(1,255,"sbr_grid(): bs_freq_res")); |
711 | 0 | } |
712 | |
|
713 | 0 | sbr->abs_bord_lead[ch] = 0; |
714 | 0 | sbr->abs_bord_trail[ch] = bs_abs_bord; |
715 | 0 | sbr->n_rel_lead[ch] = 0; |
716 | 0 | sbr->n_rel_trail[ch] = bs_num_env - 1; |
717 | 0 | break; |
718 | | |
719 | 0 | case VARFIX: |
720 | 0 | bs_abs_bord = (uint8_t)faad_getbits(ld, 2 |
721 | 0 | DEBUGVAR(1,256,"sbr_grid(): bs_abs_bord")); |
722 | 0 | bs_num_env = (uint8_t)faad_getbits(ld, 2 |
723 | 0 | DEBUGVAR(1,257,"sbr_grid(): bs_num_env")) + 1; |
724 | |
|
725 | 0 | for (rel = 0; rel < bs_num_env-1; rel++) |
726 | 0 | { |
727 | 0 | sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
728 | 0 | DEBUGVAR(1,258,"sbr_grid(): bs_rel_bord")) + 2; |
729 | 0 | } |
730 | 0 | j = bs_num_env; |
731 | 0 | i = sbr_log2(j + 1); |
732 | 0 | sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
733 | 0 | DEBUGVAR(1,259,"sbr_grid(): bs_pointer")); |
734 | 0 | sbr->bs_pointer[ch] = min(sbr->bs_pointer[ch], j); |
735 | |
|
736 | 0 | for (env = 0; env < bs_num_env; env++) |
737 | 0 | { |
738 | 0 | sbr->f[ch][env] = (uint8_t)faad_get1bit(ld |
739 | 0 | DEBUGVAR(1,260,"sbr_grid(): bs_freq_res")); |
740 | 0 | } |
741 | |
|
742 | 0 | sbr->abs_bord_lead[ch] = bs_abs_bord; |
743 | 0 | sbr->abs_bord_trail[ch] = sbr->numTimeSlots; |
744 | 0 | sbr->n_rel_lead[ch] = bs_num_env - 1; |
745 | 0 | sbr->n_rel_trail[ch] = 0; |
746 | 0 | break; |
747 | | |
748 | 0 | case VARVAR: |
749 | 0 | bs_abs_bord = (uint8_t)faad_getbits(ld, 2 |
750 | 0 | DEBUGVAR(1,261,"sbr_grid(): bs_abs_bord_0")); |
751 | 0 | bs_abs_bord_1 = (uint8_t)faad_getbits(ld, 2 |
752 | 0 | DEBUGVAR(1,262,"sbr_grid(): bs_abs_bord_1")) + sbr->numTimeSlots; |
753 | 0 | sbr->bs_num_rel_0[ch] = (uint8_t)faad_getbits(ld, 2 |
754 | 0 | DEBUGVAR(1,263,"sbr_grid(): bs_num_rel_0")); |
755 | 0 | sbr->bs_num_rel_1[ch] = (uint8_t)faad_getbits(ld, 2 |
756 | 0 | DEBUGVAR(1,264,"sbr_grid(): bs_num_rel_1")); |
757 | |
|
758 | 0 | bs_num_env = min(5, sbr->bs_num_rel_0[ch] + sbr->bs_num_rel_1[ch] + 1); |
759 | |
|
760 | 0 | for (rel = 0; rel < sbr->bs_num_rel_0[ch]; rel++) |
761 | 0 | { |
762 | 0 | sbr->bs_rel_bord_0[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
763 | 0 | DEBUGVAR(1,265,"sbr_grid(): bs_rel_bord")) + 2; |
764 | 0 | } |
765 | 0 | for(rel = 0; rel < sbr->bs_num_rel_1[ch]; rel++) |
766 | 0 | { |
767 | 0 | sbr->bs_rel_bord_1[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
768 | 0 | DEBUGVAR(1,266,"sbr_grid(): bs_rel_bord")) + 2; |
769 | 0 | } |
770 | 0 | j = sbr->bs_num_rel_0[ch] + sbr->bs_num_rel_1[ch] + 1; |
771 | 0 | i = sbr_log2(j + 1); |
772 | 0 | sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
773 | 0 | DEBUGVAR(1,267,"sbr_grid(): bs_pointer")); |
774 | 0 | sbr->bs_pointer[ch] = min(sbr->bs_pointer[ch], j); |
775 | |
|
776 | 0 | for (env = 0; env < bs_num_env; env++) |
777 | 0 | { |
778 | 0 | sbr->f[ch][env] = (uint8_t)faad_get1bit(ld |
779 | 0 | DEBUGVAR(1,268,"sbr_grid(): bs_freq_res")); |
780 | 0 | } |
781 | |
|
782 | 0 | sbr->abs_bord_lead[ch] = bs_abs_bord; |
783 | 0 | sbr->abs_bord_trail[ch] = bs_abs_bord_1; |
784 | 0 | sbr->n_rel_lead[ch] = sbr->bs_num_rel_0[ch]; |
785 | 0 | sbr->n_rel_trail[ch] = sbr->bs_num_rel_1[ch]; |
786 | 0 | break; |
787 | 0 | } |
788 | | |
789 | 0 | if (sbr->bs_frame_class[ch] == VARVAR) |
790 | 0 | sbr->L_E[ch] = min(bs_num_env, 5); |
791 | 0 | else |
792 | 0 | sbr->L_E[ch] = min(bs_num_env, 4); |
793 | |
|
794 | 0 | if (sbr->L_E[ch] <= 0) |
795 | 0 | return 1; |
796 | | |
797 | 0 | if (sbr->L_E[ch] > 1) |
798 | 0 | sbr->L_Q[ch] = 2; |
799 | 0 | else |
800 | 0 | sbr->L_Q[ch] = 1; |
801 | | |
802 | | /* TODO: this code can probably be integrated into the code above! */ |
803 | 0 | if ((result = envelope_time_border_vector(sbr, ch)) > 0) |
804 | 0 | { |
805 | 0 | sbr->bs_frame_class[ch] = saved_frame_class; |
806 | 0 | sbr->L_E[ch] = saved_L_E; |
807 | 0 | sbr->L_Q[ch] = saved_L_Q; |
808 | 0 | return result; |
809 | 0 | } |
810 | 0 | noise_floor_time_border_vector(sbr, ch); |
811 | |
|
812 | | #if 0 |
813 | | for (env = 0; env < bs_num_env; env++) |
814 | | { |
815 | | printf("freq_res[ch:%d][env:%d]: %d\n", ch, env, sbr->f[ch][env]); |
816 | | } |
817 | | #endif |
818 | |
|
819 | 0 | return 0; |
820 | 0 | } |
821 | | |
822 | | /* table 8 */ |
823 | | static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch) |
824 | 0 | { |
825 | 0 | uint8_t i; |
826 | |
|
827 | 0 | for (i = 0; i < sbr->L_E[ch]; i++) |
828 | 0 | { |
829 | 0 | sbr->bs_df_env[ch][i] = faad_get1bit(ld |
830 | 0 | DEBUGVAR(1,269,"sbr_dtdf(): bs_df_env")); |
831 | 0 | } |
832 | |
|
833 | 0 | for (i = 0; i < sbr->L_Q[ch]; i++) |
834 | 0 | { |
835 | 0 | sbr->bs_df_noise[ch][i] = faad_get1bit(ld |
836 | 0 | DEBUGVAR(1,270,"sbr_dtdf(): bs_df_noise")); |
837 | 0 | } |
838 | 0 | } |
839 | | |
840 | | /* table 9 */ |
841 | | static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch) |
842 | 0 | { |
843 | 0 | uint8_t n; |
844 | |
|
845 | 0 | for (n = 0; n < sbr->N_Q; n++) |
846 | 0 | { |
847 | 0 | sbr->bs_invf_mode[ch][n] = (uint8_t)faad_getbits(ld, 2 |
848 | 0 | DEBUGVAR(1,271,"invf_mode(): bs_invf_mode")); |
849 | 0 | } |
850 | 0 | } |
851 | | |
852 | | static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr, |
853 | | uint8_t bs_extension_id, uint16_t num_bits_left) |
854 | 0 | { |
855 | 0 | #ifdef PS_DEC |
856 | 0 | uint8_t header; |
857 | 0 | uint16_t ret; |
858 | 0 | #endif |
859 | 0 | (void)num_bits_left; /* TODO: remove or actually use parameter. */ |
860 | |
|
861 | 0 | switch (bs_extension_id) |
862 | 0 | { |
863 | 0 | #ifdef PS_DEC |
864 | 0 | case EXTENSION_ID_PS: |
865 | 0 | if (!sbr->ps) |
866 | 0 | { |
867 | 0 | sbr->ps = ps_init(get_sr_index(sbr->sample_rate), sbr->numTimeSlotsRate); |
868 | 0 | } |
869 | 0 | if (sbr->psResetFlag) |
870 | 0 | { |
871 | 0 | sbr->ps->header_read = 0; |
872 | 0 | } |
873 | 0 | ret = ps_data(sbr->ps, ld, &header); |
874 | | |
875 | | /* enable PS if and only if: a header has been decoded */ |
876 | 0 | if (sbr->ps_used == 0 && header == 1) |
877 | 0 | { |
878 | 0 | sbr->ps_used = 1; |
879 | 0 | } |
880 | |
|
881 | 0 | if (header == 1) |
882 | 0 | { |
883 | 0 | sbr->psResetFlag = 0; |
884 | 0 | } |
885 | |
|
886 | 0 | return ret; |
887 | 0 | #endif |
888 | | #ifdef DRM_PS |
889 | | case DRM_PARAMETRIC_STEREO: |
890 | | /* If not expected then only decode but do not expose. */ |
891 | | if (sbr->Is_DRM_SBR) |
892 | | { |
893 | | sbr->ps_used = 1; |
894 | | } |
895 | | if (!sbr->drm_ps) |
896 | | { |
897 | | sbr->drm_ps = drm_ps_init(); |
898 | | } |
899 | | return drm_ps_data(sbr->drm_ps, ld); |
900 | | #endif |
901 | 0 | default: |
902 | 0 | sbr->bs_extension_data = (uint8_t)faad_getbits(ld, 6 |
903 | 0 | DEBUGVAR(1,279,"sbr_single_channel_element(): bs_extension_data")); |
904 | 0 | return 6; |
905 | 0 | } |
906 | 0 | } |
907 | | |
908 | | /* table 12 */ |
909 | | static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch) |
910 | 0 | { |
911 | 0 | uint8_t n; |
912 | |
|
913 | 0 | for (n = 0; n < sbr->N_high; n++) |
914 | 0 | { |
915 | 0 | sbr->bs_add_harmonic[ch][n] = faad_get1bit(ld |
916 | 0 | DEBUGVAR(1,278,"sinusoidal_coding(): bs_add_harmonic")); |
917 | 0 | } |
918 | 0 | } |
919 | | |
920 | | |
921 | | #endif /* SBR_DEC */ |