Mercurial > mplayer.hg
comparison libfaad2/sbr_syntax.c @ 13453:6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
patch by adland <adland123 at yahoo dot com>
author | diego |
---|---|
date | Fri, 24 Sep 2004 17:31:36 +0000 |
parents | d81145997036 |
children | 2ae5ab4331ca |
comparison
equal
deleted
inserted
replaced
13452:c364b7c13dd8 | 13453:6d50ef45a058 |
---|---|
21 ** | 21 ** |
22 ** Commercial non-GPL licensing of this software is possible. | 22 ** Commercial non-GPL licensing of this software is possible. |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. |
24 ** | 24 ** |
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 | 25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
26 ** $Id: sbr_syntax.c,v 1.3 2004/06/02 22:59:03 diego Exp $ | 26 ** $Id: sbr_syntax.c,v 1.4 2004/06/23 13:50:52 diego Exp $ |
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ | 27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
28 **/ | 28 **/ |
29 | 29 |
30 #include "common.h" | 30 #include "common.h" |
31 #include "structs.h" | 31 #include "structs.h" |
47 #endif | 47 #endif |
48 #include "analysis.h" | 48 #include "analysis.h" |
49 | 49 |
50 /* static function declarations */ | 50 /* static function declarations */ |
51 static void sbr_header(bitfile *ld, sbr_info *sbr); | 51 static void sbr_header(bitfile *ld, sbr_info *sbr); |
52 static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq, | |
53 uint8_t samplerate_mode, uint8_t freq_scale, | |
54 uint8_t alter_scale, uint8_t xover_band); | |
52 static uint8_t sbr_data(bitfile *ld, sbr_info *sbr); | 55 static uint8_t sbr_data(bitfile *ld, sbr_info *sbr); |
53 static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr, | 56 static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr, |
54 uint8_t bs_extension_id, uint16_t num_bits_left); | 57 uint8_t bs_extension_id, uint16_t num_bits_left); |
55 static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr); | 58 static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr); |
56 static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr); | 59 static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr); |
98 sbr->bs_stop_freq_prev = sbr->bs_stop_freq; | 101 sbr->bs_stop_freq_prev = sbr->bs_stop_freq; |
99 sbr->bs_freq_scale_prev = sbr->bs_freq_scale; | 102 sbr->bs_freq_scale_prev = sbr->bs_freq_scale; |
100 sbr->bs_alter_scale_prev = sbr->bs_alter_scale; | 103 sbr->bs_alter_scale_prev = sbr->bs_alter_scale; |
101 sbr->bs_xover_band_prev = sbr->bs_xover_band; | 104 sbr->bs_xover_band_prev = sbr->bs_xover_band; |
102 sbr->bs_noise_bands_prev = sbr->bs_noise_bands; | 105 sbr->bs_noise_bands_prev = sbr->bs_noise_bands; |
103 | 106 } |
104 if (sbr->frame == 0) | 107 |
105 { | 108 static uint8_t calc_sbr_tables(sbr_info *sbr, uint8_t start_freq, uint8_t stop_freq, |
106 sbr->Reset = 1; | 109 uint8_t samplerate_mode, uint8_t freq_scale, |
107 } | 110 uint8_t alter_scale, uint8_t xover_band) |
111 { | |
112 uint8_t result = 0; | |
113 uint8_t k2; | |
114 | |
115 /* calculate the Master Frequency Table */ | |
116 sbr->k0 = qmf_start_channel(start_freq, samplerate_mode, sbr->sample_rate); | |
117 k2 = qmf_stop_channel(stop_freq, sbr->sample_rate, sbr->k0); | |
118 | |
119 /* check k0 and k2 */ | |
120 if (sbr->sample_rate >= 48000) | |
121 { | |
122 if ((k2 - sbr->k0) > 32) | |
123 result += 1; | |
124 } else if (sbr->sample_rate <= 32000) { | |
125 if ((k2 - sbr->k0) > 48) | |
126 result += 1; | |
127 } else { /* (sbr->sample_rate == 44100) */ | |
128 if ((k2 - sbr->k0) > 45) | |
129 result += 1; | |
130 } | |
131 | |
132 if (freq_scale == 0) | |
133 { | |
134 result += master_frequency_table_fs0(sbr, sbr->k0, k2, alter_scale); | |
135 } else { | |
136 result += master_frequency_table(sbr, sbr->k0, k2, freq_scale, alter_scale); | |
137 } | |
138 result += derived_frequency_table(sbr, xover_band, k2); | |
139 | |
140 result = (result > 0) ? 1 : 0; | |
141 | |
142 return result; | |
108 } | 143 } |
109 | 144 |
110 /* table 2 */ | 145 /* table 2 */ |
111 uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt) | 146 uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt) |
112 { | 147 { |
113 uint8_t result = 0; | 148 uint8_t result = 0; |
114 uint16_t num_align_bits = 0; | 149 uint16_t num_align_bits = 0; |
115 uint16_t num_sbr_bits = (uint16_t)faad_get_processed_bits(ld); | 150 uint16_t num_sbr_bits = (uint16_t)faad_get_processed_bits(ld); |
116 | 151 |
152 uint8_t saved_start_freq, saved_samplerate_mode; | |
153 uint8_t saved_stop_freq, saved_freq_scale; | |
154 uint8_t saved_alter_scale, saved_xover_band; | |
155 | |
117 #ifdef DRM | 156 #ifdef DRM |
118 if (!sbr->Is_DRM_SBR) | 157 if (!sbr->Is_DRM_SBR) |
119 #endif | 158 #endif |
120 { | 159 { |
121 uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4 | 160 uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4 |
125 { | 164 { |
126 sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10 | 165 sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10 |
127 DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits")); | 166 DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits")); |
128 } | 167 } |
129 } | 168 } |
169 | |
170 /* save old header values, in case the new ones are corrupted */ | |
171 saved_start_freq = sbr->bs_start_freq; | |
172 saved_samplerate_mode = sbr->bs_samplerate_mode; | |
173 saved_stop_freq = sbr->bs_stop_freq; | |
174 saved_freq_scale = sbr->bs_freq_scale; | |
175 saved_alter_scale = sbr->bs_alter_scale; | |
176 saved_xover_band = sbr->bs_xover_band; | |
130 | 177 |
131 sbr->bs_header_flag = faad_get1bit(ld | 178 sbr->bs_header_flag = faad_get1bit(ld |
132 DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag")); | 179 DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag")); |
133 | 180 |
134 if (sbr->bs_header_flag) | 181 if (sbr->bs_header_flag) |
141 //if (!(sbr->frame == 0 && sbr->bs_header_flag == 0)) | 188 //if (!(sbr->frame == 0 && sbr->bs_header_flag == 0)) |
142 if (sbr->header_count != 0) | 189 if (sbr->header_count != 0) |
143 { | 190 { |
144 if (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked)) | 191 if (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked)) |
145 { | 192 { |
146 uint8_t k2; | 193 uint8_t rt = calc_sbr_tables(sbr, sbr->bs_start_freq, sbr->bs_stop_freq, |
147 | 194 sbr->bs_samplerate_mode, sbr->bs_freq_scale, |
148 /* calculate the Master Frequency Table */ | 195 sbr->bs_alter_scale, sbr->bs_xover_band); |
149 sbr->k0 = qmf_start_channel(sbr->bs_start_freq, sbr->bs_samplerate_mode, | 196 |
150 sbr->sample_rate); | 197 /* if an error occured with the new header values revert to the old ones */ |
151 k2 = qmf_stop_channel(sbr->bs_stop_freq, sbr->sample_rate, sbr->k0); | 198 if (rt > 0) |
152 | |
153 /* check k0 and k2 */ | |
154 if (sbr->sample_rate >= 48000) | |
155 { | 199 { |
156 if ((k2 - sbr->k0) > 32) | 200 calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq, |
157 result += 1; | 201 saved_samplerate_mode, saved_freq_scale, |
158 } else if (sbr->sample_rate <= 32000) { | 202 saved_alter_scale, saved_xover_band); |
159 if ((k2 - sbr->k0) > 48) | |
160 result += 1; | |
161 } else { /* (sbr->sample_rate == 44100) */ | |
162 if ((k2 - sbr->k0) > 45) | |
163 result += 1; | |
164 } | 203 } |
165 | 204 } |
166 if (sbr->bs_freq_scale == 0) | 205 |
206 if (result == 0) | |
207 { | |
208 result = sbr_data(ld, sbr); | |
209 | |
210 /* sbr_data() returning an error means that there was an error in | |
211 envelope_time_border_vector(). | |
212 In this case the old time border vector is saved and all the previous | |
213 data normally read after sbr_grid() is saved. | |
214 */ | |
215 /* to be on the safe side, calculate old sbr tables in case of error */ | |
216 if ((result > 0) && | |
217 (sbr->Reset || (sbr->bs_header_flag && sbr->just_seeked))) | |
167 { | 218 { |
168 result += master_frequency_table_fs0(sbr, sbr->k0, k2, | 219 calc_sbr_tables(sbr, saved_start_freq, saved_stop_freq, |
169 sbr->bs_alter_scale); | 220 saved_samplerate_mode, saved_freq_scale, |
170 } else { | 221 saved_alter_scale, saved_xover_band); |
171 result += master_frequency_table(sbr, sbr->k0, k2, sbr->bs_freq_scale, | |
172 sbr->bs_alter_scale); | |
173 } | 222 } |
174 result += derived_frequency_table(sbr, sbr->bs_xover_band, k2); | 223 |
175 | 224 /* we should be able to safely set result to 0 now */ |
176 result = (result > 0) ? 1 : 0; | 225 result = 0; |
177 } | 226 } |
178 | |
179 if (result == 0) | |
180 result = sbr_data(ld, sbr); | |
181 } else { | 227 } else { |
182 result = 1; | 228 result = 1; |
183 } | 229 } |
184 | 230 |
185 #ifdef DRM | 231 #ifdef DRM |
186 if (!sbr->Is_DRM_SBR) | 232 if (!sbr->Is_DRM_SBR) |
187 #endif | 233 #endif |
188 { | 234 { |
189 num_sbr_bits = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits; | 235 num_sbr_bits = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits; |
236 | |
237 /* check if we read more bits then were available for sbr */ | |
238 if (8*cnt < num_sbr_bits) | |
239 return 1; | |
240 | |
190 /* -4 does not apply, bs_extension_type is re-read in this function */ | 241 /* -4 does not apply, bs_extension_type is re-read in this function */ |
191 num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits; | 242 num_align_bits = 8*cnt /*- 4*/ - num_sbr_bits; |
192 | 243 |
193 while (num_align_bits > 7) | 244 while (num_align_bits > 7) |
194 { | 245 { |
333 sbr_dtdf(ld, sbr, 0); | 384 sbr_dtdf(ld, sbr, 0); |
334 invf_mode(ld, sbr, 0); | 385 invf_mode(ld, sbr, 0); |
335 sbr_envelope(ld, sbr, 0); | 386 sbr_envelope(ld, sbr, 0); |
336 sbr_noise(ld, sbr, 0); | 387 sbr_noise(ld, sbr, 0); |
337 | 388 |
389 #ifndef FIXED_POINT | |
338 envelope_noise_dequantisation(sbr, 0); | 390 envelope_noise_dequantisation(sbr, 0); |
391 #endif | |
339 | 392 |
340 memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); | 393 memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); |
341 | 394 |
342 sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld | 395 sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld |
343 DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]")); | 396 DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]")); |
344 if (sbr->bs_add_harmonic_flag[0]) | 397 if (sbr->bs_add_harmonic_flag[0]) |
345 sinusoidal_coding(ld, sbr, 0); | 398 sinusoidal_coding(ld, sbr, 0); |
346 | 399 |
347 sbr->bs_extended_data = faad_get1bit(ld | 400 sbr->bs_extended_data = faad_get1bit(ld |
348 DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]")); | 401 DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]")); |
402 | |
349 if (sbr->bs_extended_data) | 403 if (sbr->bs_extended_data) |
350 { | 404 { |
351 uint16_t nr_bits_left; | 405 uint16_t nr_bits_left; |
352 uint16_t cnt = (uint16_t)faad_getbits(ld, 4 | 406 uint16_t cnt = (uint16_t)faad_getbits(ld, 4 |
353 DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size")); | 407 DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size")); |
358 } | 412 } |
359 | 413 |
360 nr_bits_left = 8 * cnt; | 414 nr_bits_left = 8 * cnt; |
361 while (nr_bits_left > 7) | 415 while (nr_bits_left > 7) |
362 { | 416 { |
417 uint16_t tmp_nr_bits = 0; | |
418 | |
363 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 | 419 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
364 DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id")); | 420 DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id")); |
365 nr_bits_left -= 2; | 421 tmp_nr_bits += 2; |
366 nr_bits_left -= sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); | 422 tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); |
423 | |
424 /* check if the data read is bigger than the number of available bits */ | |
425 if (tmp_nr_bits > nr_bits_left) | |
426 return 1; | |
427 | |
428 nr_bits_left -= tmp_nr_bits; | |
367 } | 429 } |
368 | 430 |
369 /* Corrigendum */ | 431 /* Corrigendum */ |
370 if (nr_bits_left > 0) | 432 if (nr_bits_left > 0) |
371 { | 433 { |
437 sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld | 499 sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld |
438 DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); | 500 DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
439 if (sbr->bs_add_harmonic_flag[1]) | 501 if (sbr->bs_add_harmonic_flag[1]) |
440 sinusoidal_coding(ld, sbr, 1); | 502 sinusoidal_coding(ld, sbr, 1); |
441 } else { | 503 } else { |
504 uint8_t saved_t_E[6] = {0}, saved_t_Q[3] = {0}; | |
505 uint8_t saved_L_E = sbr->L_E[0]; | |
506 uint8_t saved_L_Q = sbr->L_Q[0]; | |
507 uint8_t saved_frame_class = sbr->bs_frame_class[0]; | |
508 | |
509 for (n = 0; n < saved_L_E; n++) | |
510 saved_t_E[n] = sbr->t_E[0][n]; | |
511 for (n = 0; n < saved_L_Q; n++) | |
512 saved_t_Q[n] = sbr->t_Q[0][n]; | |
513 | |
442 if ((result = sbr_grid(ld, sbr, 0)) > 0) | 514 if ((result = sbr_grid(ld, sbr, 0)) > 0) |
443 return result; | 515 return result; |
444 if ((result = sbr_grid(ld, sbr, 1)) > 0) | 516 if ((result = sbr_grid(ld, sbr, 1)) > 0) |
517 { | |
518 /* restore first channel data as well */ | |
519 sbr->bs_frame_class[0] = saved_frame_class; | |
520 sbr->L_E[0] = saved_L_E; | |
521 sbr->L_Q[0] = saved_L_Q; | |
522 for (n = 0; n < 6; n++) | |
523 sbr->t_E[0][n] = saved_t_E[n]; | |
524 for (n = 0; n < 3; n++) | |
525 sbr->t_Q[0][n] = saved_t_Q[n]; | |
526 | |
445 return result; | 527 return result; |
528 } | |
446 sbr_dtdf(ld, sbr, 0); | 529 sbr_dtdf(ld, sbr, 0); |
447 sbr_dtdf(ld, sbr, 1); | 530 sbr_dtdf(ld, sbr, 1); |
448 invf_mode(ld, sbr, 0); | 531 invf_mode(ld, sbr, 0); |
449 invf_mode(ld, sbr, 1); | 532 invf_mode(ld, sbr, 1); |
450 sbr_envelope(ld, sbr, 0); | 533 sbr_envelope(ld, sbr, 0); |
463 sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld | 546 sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld |
464 DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); | 547 DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
465 if (sbr->bs_add_harmonic_flag[1]) | 548 if (sbr->bs_add_harmonic_flag[1]) |
466 sinusoidal_coding(ld, sbr, 1); | 549 sinusoidal_coding(ld, sbr, 1); |
467 } | 550 } |
551 #ifndef FIXED_POINT | |
468 envelope_noise_dequantisation(sbr, 0); | 552 envelope_noise_dequantisation(sbr, 0); |
469 envelope_noise_dequantisation(sbr, 1); | 553 envelope_noise_dequantisation(sbr, 1); |
470 | 554 |
471 if (sbr->bs_coupling) | 555 if (sbr->bs_coupling) |
472 unmap_envelope_noise(sbr); | 556 unmap_envelope_noise(sbr); |
557 #endif | |
473 | 558 |
474 sbr->bs_extended_data = faad_get1bit(ld | 559 sbr->bs_extended_data = faad_get1bit(ld |
475 DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]")); | 560 DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]")); |
476 if (sbr->bs_extended_data) | 561 if (sbr->bs_extended_data) |
477 { | 562 { |
485 } | 570 } |
486 | 571 |
487 nr_bits_left = 8 * cnt; | 572 nr_bits_left = 8 * cnt; |
488 while (nr_bits_left > 7) | 573 while (nr_bits_left > 7) |
489 { | 574 { |
575 uint16_t tmp_nr_bits = 0; | |
576 | |
490 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 | 577 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
491 DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id")); | 578 DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id")); |
492 nr_bits_left -= 2; | 579 tmp_nr_bits += 2; |
493 sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); | 580 tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); |
581 | |
582 /* check if the data read is bigger than the number of available bits */ | |
583 if (tmp_nr_bits > nr_bits_left) | |
584 return 1; | |
585 | |
586 nr_bits_left -= tmp_nr_bits; | |
494 } | 587 } |
495 | 588 |
496 /* Corrigendum */ | 589 /* Corrigendum */ |
497 if (nr_bits_left > 0) | 590 if (nr_bits_left > 0) |
498 { | 591 { |
519 static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch) | 612 static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch) |
520 { | 613 { |
521 uint8_t i, env, rel, result; | 614 uint8_t i, env, rel, result; |
522 uint8_t bs_abs_bord, bs_abs_bord_1; | 615 uint8_t bs_abs_bord, bs_abs_bord_1; |
523 uint8_t bs_num_env = 0; | 616 uint8_t bs_num_env = 0; |
617 uint8_t saved_L_E = sbr->L_E[ch]; | |
618 uint8_t saved_L_Q = sbr->L_Q[ch]; | |
619 uint8_t saved_frame_class = sbr->bs_frame_class[ch]; | |
524 | 620 |
525 sbr->bs_frame_class[ch] = (uint8_t)faad_getbits(ld, 2 | 621 sbr->bs_frame_class[ch] = (uint8_t)faad_getbits(ld, 2 |
526 DEBUGVAR(1,248,"sbr_grid(): bs_frame_class")); | 622 DEBUGVAR(1,248,"sbr_grid(): bs_frame_class")); |
527 | 623 |
528 switch (sbr->bs_frame_class[ch]) | 624 switch (sbr->bs_frame_class[ch]) |
650 else | 746 else |
651 sbr->L_Q[ch] = 1; | 747 sbr->L_Q[ch] = 1; |
652 | 748 |
653 /* TODO: this code can probably be integrated into the code above! */ | 749 /* TODO: this code can probably be integrated into the code above! */ |
654 if ((result = envelope_time_border_vector(sbr, ch)) > 0) | 750 if ((result = envelope_time_border_vector(sbr, ch)) > 0) |
751 { | |
752 sbr->bs_frame_class[ch] = saved_frame_class; | |
753 sbr->L_E[ch] = saved_L_E; | |
754 sbr->L_Q[ch] = saved_L_Q; | |
655 return result; | 755 return result; |
756 } | |
656 noise_floor_time_border_vector(sbr, ch); | 757 noise_floor_time_border_vector(sbr, ch); |
758 | |
759 #if 0 | |
760 for (env = 0; env < bs_num_env; env++) | |
761 { | |
762 printf("freq_res[ch:%d][env:%d]: %d\n", ch, env, sbr->f[ch][env]); | |
763 } | |
764 #endif | |
657 | 765 |
658 return 0; | 766 return 0; |
659 } | 767 } |
660 | 768 |
661 /* table 8 */ | 769 /* table 8 */ |
694 switch (bs_extension_id) | 802 switch (bs_extension_id) |
695 { | 803 { |
696 #ifdef PS_DEC | 804 #ifdef PS_DEC |
697 case EXTENSION_ID_PS: | 805 case EXTENSION_ID_PS: |
698 sbr->ps_used = 1; | 806 sbr->ps_used = 1; |
699 return ps_data(&(sbr->ps), ld); | 807 if (!sbr->ps) |
808 { | |
809 sbr->ps = ps_init(get_sr_index(sbr->sample_rate)); | |
810 } | |
811 return ps_data(sbr->ps, ld); | |
700 #endif | 812 #endif |
701 #ifdef DRM_PS | 813 #ifdef DRM_PS |
702 case DRM_PARAMETRIC_STEREO: | 814 case DRM_PARAMETRIC_STEREO: |
703 sbr->ps_used = 1; | 815 sbr->ps_used = 1; |
704 return drm_ps_data(&(sbr->drm_ps), ld); | 816 if (!sbr->drm_ps) |
817 { | |
818 sbr->drm_ps = drm_ps_init(); | |
819 } | |
820 return drm_ps_data(sbr->drm_ps, ld); | |
705 #endif | 821 #endif |
706 default: | 822 default: |
707 sbr->bs_extension_data = (uint8_t)faad_getbits(ld, 6 | 823 sbr->bs_extension_data = (uint8_t)faad_getbits(ld, 6 |
708 DEBUGVAR(1,279,"sbr_single_channel_element(): bs_extension_data")); | 824 DEBUGVAR(1,279,"sbr_single_channel_element(): bs_extension_data")); |
709 return 6; | 825 return 6; |