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