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