Mercurial > audlegacy
annotate Plugins/Input/aac/libfaad2/sbr_syntax.c @ 1010:29feaace84d0 trunk
[svn] - synchronize audacious-faad with FAAD2 CVS.
author | nenolod |
---|---|
date | Mon, 08 May 2006 06:56:47 -0700 |
parents | 0a2ad94e8607 |
children | 1e6c0a3f2d15 |
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 | |
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 ** | |
1010 | 25 ** $Id: sbr_syntax.c,v 1.25 2004/01/29 11:31:11 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); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
60 |
61 | 61 static void sbr_reset(sbr_info *sbr) |
62 { | |
63 #if 0 | |
64 printf("%d\n", sbr->bs_start_freq_prev); | |
65 printf("%d\n", sbr->bs_stop_freq_prev); | |
66 printf("%d\n", sbr->bs_freq_scale_prev); | |
67 printf("%d\n", sbr->bs_alter_scale_prev); | |
68 printf("%d\n", sbr->bs_xover_band_prev); | |
69 printf("%d\n\n", sbr->bs_noise_bands_prev); | |
70 #endif | |
71 | |
72 /* if these are different from the previous frame: Reset = 1 */ | |
73 if ((sbr->bs_start_freq != sbr->bs_start_freq_prev) || | |
74 (sbr->bs_stop_freq != sbr->bs_stop_freq_prev) || | |
75 (sbr->bs_freq_scale != sbr->bs_freq_scale_prev) || | |
1010 | 76 (sbr->bs_alter_scale != sbr->bs_alter_scale_prev)) |
77 { | |
78 sbr->Reset = 1; | |
79 } else { | |
80 sbr->Reset = 0; | |
81 } | |
82 | |
83 if ((sbr->bs_start_freq != sbr->bs_start_freq_prev) || | |
84 (sbr->bs_stop_freq != sbr->bs_stop_freq_prev) || | |
85 (sbr->bs_freq_scale != sbr->bs_freq_scale_prev) || | |
61 | 86 (sbr->bs_alter_scale != sbr->bs_alter_scale_prev) || |
87 (sbr->bs_xover_band != sbr->bs_xover_band_prev) || | |
88 (sbr->bs_noise_bands != sbr->bs_noise_bands_prev)) | |
89 { | |
90 sbr->Reset = 1; | |
91 } else { | |
92 sbr->Reset = 0; | |
93 } | |
94 | |
95 sbr->bs_start_freq_prev = sbr->bs_start_freq; | |
96 sbr->bs_stop_freq_prev = sbr->bs_stop_freq; | |
97 sbr->bs_freq_scale_prev = sbr->bs_freq_scale; | |
98 sbr->bs_alter_scale_prev = sbr->bs_alter_scale; | |
99 sbr->bs_xover_band_prev = sbr->bs_xover_band; | |
100 sbr->bs_noise_bands_prev = sbr->bs_noise_bands; | |
101 | |
1010 | 102 if (sbr->frame == 0) |
61 | 103 { |
1010 | 104 sbr->Reset = 1; |
61 | 105 } |
106 } | |
107 | |
108 /* table 2 */ | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
109 uint8_t sbr_extension_data(bitfile *ld, sbr_info *sbr, uint16_t cnt) |
61 | 110 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
111 uint8_t result = 0; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
112 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
|
113 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
|
114 |
61 | 115 #ifdef DRM |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
116 if (!sbr->Is_DRM_SBR) |
61 | 117 #endif |
118 { | |
119 uint8_t bs_extension_type = (uint8_t)faad_getbits(ld, 4 | |
120 DEBUGVAR(1,198,"sbr_bitstream(): bs_extension_type")); | |
121 | |
122 if (bs_extension_type == EXT_SBR_DATA_CRC) | |
123 { | |
124 sbr->bs_sbr_crc_bits = (uint16_t)faad_getbits(ld, 10 | |
125 DEBUGVAR(1,199,"sbr_bitstream(): bs_sbr_crc_bits")); | |
126 } | |
127 } | |
128 | |
129 sbr->bs_header_flag = faad_get1bit(ld | |
130 DEBUGVAR(1,200,"sbr_bitstream(): bs_header_flag")); | |
131 | |
132 if (sbr->bs_header_flag) | |
133 sbr_header(ld, sbr); | |
134 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
135 /* Reset? */ |
61 | 136 sbr_reset(sbr); |
137 | |
138 /* 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
|
139 //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
|
140 if (sbr->header_count != 0) |
61 | 141 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
142 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
|
143 { |
1010 | 144 uint8_t k2; |
145 | |
146 /* calculate the Master Frequency Table */ | |
147 sbr->k0 = qmf_start_channel(sbr->bs_start_freq, sbr->bs_samplerate_mode, | |
148 sbr->sample_rate); | |
149 k2 = qmf_stop_channel(sbr->bs_stop_freq, sbr->sample_rate, sbr->k0); | |
61 | 150 |
1010 | 151 /* check k0 and k2 */ |
152 if (sbr->sample_rate >= 48000) | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
153 { |
1010 | 154 if ((k2 - sbr->k0) > 32) |
155 result += 1; | |
156 } else if (sbr->sample_rate <= 32000) { | |
157 if ((k2 - sbr->k0) > 48) | |
158 result += 1; | |
159 } else { /* (sbr->sample_rate == 44100) */ | |
160 if ((k2 - sbr->k0) > 45) | |
161 result += 1; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
162 } |
1010 | 163 |
164 if (sbr->bs_freq_scale == 0) | |
165 { | |
166 result += master_frequency_table_fs0(sbr, sbr->k0, k2, | |
167 sbr->bs_alter_scale); | |
168 } else { | |
169 result += master_frequency_table(sbr, sbr->k0, k2, sbr->bs_freq_scale, | |
170 sbr->bs_alter_scale); | |
171 } | |
172 result += derived_frequency_table(sbr, sbr->bs_xover_band, k2); | |
173 | |
174 result = (result > 0) ? 1 : 0; | |
61 | 175 } |
176 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
177 if (result == 0) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
178 result = sbr_data(ld, sbr); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
179 } else { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
180 result = 1; |
61 | 181 } |
182 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
183 #ifdef DRM |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
184 if (!sbr->Is_DRM_SBR) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
185 #endif |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
186 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
187 num_sbr_bits = (uint16_t)faad_get_processed_bits(ld) - num_sbr_bits; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
188 /* -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
|
189 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
|
190 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
191 while (num_align_bits > 7) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
192 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
193 faad_getbits(ld, 8 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
194 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
|
195 num_align_bits -= 8; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
196 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
197 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
|
198 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
|
199 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
200 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
201 return result; |
61 | 202 } |
203 | |
204 /* table 3 */ | |
205 static void sbr_header(bitfile *ld, sbr_info *sbr) | |
206 { | |
207 uint8_t bs_header_extra_1, bs_header_extra_2; | |
208 | |
209 sbr->header_count++; | |
210 | |
211 sbr->bs_amp_res = faad_get1bit(ld | |
212 DEBUGVAR(1,203,"sbr_header(): bs_amp_res")); | |
213 | |
214 /* bs_start_freq and bs_stop_freq must define a fequency band that does | |
215 not exceed 48 channels */ | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
216 sbr->bs_start_freq = (uint8_t)faad_getbits(ld, 4 |
61 | 217 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
|
218 sbr->bs_stop_freq = (uint8_t)faad_getbits(ld, 4 |
61 | 219 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
|
220 sbr->bs_xover_band = (uint8_t)faad_getbits(ld, 3 |
61 | 221 DEBUGVAR(1,206,"sbr_header(): bs_xover_band")); |
222 faad_getbits(ld, 2 | |
223 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
|
224 bs_header_extra_1 = (uint8_t)faad_get1bit(ld |
61 | 225 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
|
226 bs_header_extra_2 = (uint8_t)faad_get1bit(ld |
61 | 227 DEBUGVAR(1,209,"sbr_header(): bs_header_extra_2")); |
228 | |
229 if (bs_header_extra_1) | |
230 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
231 sbr->bs_freq_scale = (uint8_t)faad_getbits(ld, 2 |
61 | 232 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
|
233 sbr->bs_alter_scale = (uint8_t)faad_get1bit(ld |
61 | 234 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
|
235 sbr->bs_noise_bands = (uint8_t)faad_getbits(ld, 2 |
61 | 236 DEBUGVAR(1,213,"sbr_header(): bs_noise_bands")); |
237 } else { | |
238 /* Default values */ | |
239 sbr->bs_freq_scale = 2; | |
240 sbr->bs_alter_scale = 1; | |
241 sbr->bs_noise_bands = 2; | |
242 } | |
243 | |
244 if (bs_header_extra_2) | |
245 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
246 sbr->bs_limiter_bands = (uint8_t)faad_getbits(ld, 2 |
61 | 247 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
|
248 sbr->bs_limiter_gains = (uint8_t)faad_getbits(ld, 2 |
61 | 249 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
|
250 sbr->bs_interpol_freq = (uint8_t)faad_get1bit(ld |
61 | 251 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
|
252 sbr->bs_smoothing_mode = (uint8_t)faad_get1bit(ld |
61 | 253 DEBUGVAR(1,217,"sbr_header(): bs_smoothing_mode")); |
254 } else { | |
255 /* Default values */ | |
256 sbr->bs_limiter_bands = 2; | |
257 sbr->bs_limiter_gains = 2; | |
258 sbr->bs_interpol_freq = 1; | |
259 sbr->bs_smoothing_mode = 1; | |
260 } | |
261 | |
262 #if 0 | |
263 /* print the header to screen */ | |
264 printf("bs_amp_res: %d\n", sbr->bs_amp_res); | |
265 printf("bs_start_freq: %d\n", sbr->bs_start_freq); | |
266 printf("bs_stop_freq: %d\n", sbr->bs_stop_freq); | |
267 printf("bs_xover_band: %d\n", sbr->bs_xover_band); | |
268 if (bs_header_extra_1) | |
269 { | |
270 printf("bs_freq_scale: %d\n", sbr->bs_freq_scale); | |
271 printf("bs_alter_scale: %d\n", sbr->bs_alter_scale); | |
272 printf("bs_noise_bands: %d\n", sbr->bs_noise_bands); | |
273 } | |
274 if (bs_header_extra_2) | |
275 { | |
276 printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands); | |
277 printf("bs_limiter_gains: %d\n", sbr->bs_limiter_gains); | |
278 printf("bs_interpol_freq: %d\n", sbr->bs_interpol_freq); | |
279 printf("bs_smoothing_mode: %d\n", sbr->bs_smoothing_mode); | |
280 } | |
281 printf("\n"); | |
282 #endif | |
283 } | |
284 | |
285 /* table 4 */ | |
286 static uint8_t sbr_data(bitfile *ld, sbr_info *sbr) | |
287 { | |
288 uint8_t result; | |
289 #if 0 | |
290 sbr->bs_samplerate_mode = faad_get1bit(ld | |
291 DEBUGVAR(1,219,"sbr_data(): bs_samplerate_mode")); | |
292 #endif | |
293 | |
294 sbr->rate = (sbr->bs_samplerate_mode) ? 2 : 1; | |
295 | |
296 switch (sbr->id_aac) | |
297 { | |
298 case ID_SCE: | |
299 if ((result = sbr_single_channel_element(ld, sbr)) > 0) | |
300 return result; | |
301 break; | |
302 case ID_CPE: | |
303 if ((result = sbr_channel_pair_element(ld, sbr)) > 0) | |
304 return result; | |
305 break; | |
306 } | |
307 | |
308 return 0; | |
309 } | |
310 | |
311 /* table 5 */ | |
312 static uint8_t sbr_single_channel_element(bitfile *ld, sbr_info *sbr) | |
313 { | |
314 uint8_t result; | |
315 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
316 if (faad_get1bit(ld |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
317 DEBUGVAR(1,220,"sbr_single_channel_element(): bs_data_extra"))) |
61 | 318 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
319 faad_getbits(ld, 4 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
320 DEBUGVAR(1,221,"sbr_single_channel_element(): bs_reserved_bits_data")); |
61 | 321 } |
322 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
323 #ifdef DRM |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
324 /* 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
|
325 if (sbr->Is_DRM_SBR) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
326 faad_get1bit(ld); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
327 #endif |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
328 |
61 | 329 if ((result = sbr_grid(ld, sbr, 0)) > 0) |
330 return result; | |
331 sbr_dtdf(ld, sbr, 0); | |
332 invf_mode(ld, sbr, 0); | |
333 sbr_envelope(ld, sbr, 0); | |
334 sbr_noise(ld, sbr, 0); | |
335 | |
336 envelope_noise_dequantisation(sbr, 0); | |
337 | |
338 memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); | |
339 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
340 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
|
341 DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]")); |
61 | 342 if (sbr->bs_add_harmonic_flag[0]) |
343 sinusoidal_coding(ld, sbr, 0); | |
344 | |
345 sbr->bs_extended_data = faad_get1bit(ld | |
346 DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]")); | |
347 if (sbr->bs_extended_data) | |
348 { | |
349 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
|
350 uint16_t cnt = (uint16_t)faad_getbits(ld, 4 |
61 | 351 DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size")); |
352 if (cnt == 15) | |
353 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
354 cnt += (uint16_t)faad_getbits(ld, 8 |
61 | 355 DEBUGVAR(1,226,"sbr_single_channel_element(): bs_esc_count")); |
356 } | |
357 | |
358 nr_bits_left = 8 * cnt; | |
359 while (nr_bits_left > 7) | |
360 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
361 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
61 | 362 DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id")); |
1010 | 363 nr_bits_left -= 2; |
364 nr_bits_left -= sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); | |
61 | 365 } |
366 | |
367 /* Corrigendum */ | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
368 if (nr_bits_left > 0) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
369 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
370 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
|
371 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
|
372 } |
61 | 373 } |
374 | |
375 return 0; | |
376 } | |
377 | |
378 /* table 6 */ | |
379 static uint8_t sbr_channel_pair_element(bitfile *ld, sbr_info *sbr) | |
380 { | |
381 uint8_t n, result; | |
382 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
383 if (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,228,"sbr_single_channel_element(): bs_data_extra"))) |
61 | 385 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
386 faad_getbits(ld, 4 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
387 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
|
388 faad_getbits(ld, 4 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
389 DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_reserved_bits_data")); |
61 | 390 } |
391 | |
392 sbr->bs_coupling = faad_get1bit(ld | |
393 DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_coupling")); | |
394 | |
395 if (sbr->bs_coupling) | |
396 { | |
397 if ((result = sbr_grid(ld, sbr, 0)) > 0) | |
398 return result; | |
399 | |
400 /* need to copy some data from left to right */ | |
401 sbr->bs_frame_class[1] = sbr->bs_frame_class[0]; | |
402 sbr->L_E[1] = sbr->L_E[0]; | |
403 sbr->L_Q[1] = sbr->L_Q[0]; | |
404 sbr->bs_pointer[1] = sbr->bs_pointer[0]; | |
405 | |
406 for (n = 0; n <= sbr->L_E[0]; n++) | |
407 { | |
408 sbr->t_E[1][n] = sbr->t_E[0][n]; | |
409 sbr->f[1][n] = sbr->f[0][n]; | |
410 } | |
411 for (n = 0; n <= sbr->L_Q[0]; n++) | |
412 sbr->t_Q[1][n] = sbr->t_Q[0][n]; | |
413 | |
414 sbr_dtdf(ld, sbr, 0); | |
415 sbr_dtdf(ld, sbr, 1); | |
416 invf_mode(ld, sbr, 0); | |
417 | |
418 /* more copying */ | |
419 for (n = 0; n < sbr->N_Q; n++) | |
420 sbr->bs_invf_mode[1][n] = sbr->bs_invf_mode[0][n]; | |
421 | |
422 sbr_envelope(ld, sbr, 0); | |
423 sbr_noise(ld, sbr, 0); | |
424 sbr_envelope(ld, sbr, 1); | |
425 sbr_noise(ld, sbr, 1); | |
426 | |
427 memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); | |
428 memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t)); | |
429 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
430 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
|
431 DEBUGVAR(1,231,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]")); |
61 | 432 if (sbr->bs_add_harmonic_flag[0]) |
433 sinusoidal_coding(ld, sbr, 0); | |
434 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
435 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
|
436 DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
61 | 437 if (sbr->bs_add_harmonic_flag[1]) |
438 sinusoidal_coding(ld, sbr, 1); | |
439 } else { | |
440 if ((result = sbr_grid(ld, sbr, 0)) > 0) | |
441 return result; | |
442 if ((result = sbr_grid(ld, sbr, 1)) > 0) | |
443 return result; | |
444 sbr_dtdf(ld, sbr, 0); | |
445 sbr_dtdf(ld, sbr, 1); | |
446 invf_mode(ld, sbr, 0); | |
447 invf_mode(ld, sbr, 1); | |
448 sbr_envelope(ld, sbr, 0); | |
449 sbr_envelope(ld, sbr, 1); | |
450 sbr_noise(ld, sbr, 0); | |
451 sbr_noise(ld, sbr, 1); | |
452 | |
453 memset(sbr->bs_add_harmonic[0], 0, 64*sizeof(uint8_t)); | |
454 memset(sbr->bs_add_harmonic[1], 0, 64*sizeof(uint8_t)); | |
455 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
456 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
|
457 DEBUGVAR(1,239,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]")); |
61 | 458 if (sbr->bs_add_harmonic_flag[0]) |
459 sinusoidal_coding(ld, sbr, 0); | |
460 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
461 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
|
462 DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]")); |
61 | 463 if (sbr->bs_add_harmonic_flag[1]) |
464 sinusoidal_coding(ld, sbr, 1); | |
465 } | |
466 envelope_noise_dequantisation(sbr, 0); | |
467 envelope_noise_dequantisation(sbr, 1); | |
468 | |
469 if (sbr->bs_coupling) | |
470 unmap_envelope_noise(sbr); | |
471 | |
472 sbr->bs_extended_data = faad_get1bit(ld | |
473 DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]")); | |
474 if (sbr->bs_extended_data) | |
475 { | |
476 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
|
477 uint16_t cnt = (uint16_t)faad_getbits(ld, 4 |
61 | 478 DEBUGVAR(1,234,"sbr_channel_pair_element(): bs_extension_size")); |
479 if (cnt == 15) | |
480 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
481 cnt += (uint16_t)faad_getbits(ld, 8 |
61 | 482 DEBUGVAR(1,235,"sbr_channel_pair_element(): bs_esc_count")); |
483 } | |
484 | |
485 nr_bits_left = 8 * cnt; | |
486 while (nr_bits_left > 7) | |
487 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
488 sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2 |
61 | 489 DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id")); |
1010 | 490 nr_bits_left -= 2; |
491 sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left); | |
61 | 492 } |
493 | |
494 /* Corrigendum */ | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
495 if (nr_bits_left > 0) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
496 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
497 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
|
498 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
|
499 } |
61 | 500 } |
501 | |
502 return 0; | |
503 } | |
504 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
505 /* 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
|
506 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
|
507 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
508 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
|
509 if (val < 10 && val >= 0) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
510 return log2tab[val]; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
511 else |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
512 return 0; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
513 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
514 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
515 |
61 | 516 /* table 7 */ |
517 static uint8_t sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch) | |
518 { | |
519 uint8_t i, env, rel, result; | |
520 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
|
521 uint8_t bs_num_env = 0; |
61 | 522 |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
523 sbr->bs_frame_class[ch] = (uint8_t)faad_getbits(ld, 2 |
61 | 524 DEBUGVAR(1,248,"sbr_grid(): bs_frame_class")); |
525 | |
526 switch (sbr->bs_frame_class[ch]) | |
527 { | |
528 case FIXFIX: | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
529 i = (uint8_t)faad_getbits(ld, 2 |
61 | 530 DEBUGVAR(1,249,"sbr_grid(): bs_num_env_raw")); |
531 | |
532 bs_num_env = min(1 << i, 5); | |
533 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
534 i = (uint8_t)faad_get1bit(ld |
61 | 535 DEBUGVAR(1,250,"sbr_grid(): bs_freq_res_flag")); |
536 for (env = 0; env < bs_num_env; env++) | |
537 sbr->f[ch][env] = i; | |
538 | |
539 sbr->abs_bord_lead[ch] = 0; | |
540 sbr->abs_bord_trail[ch] = sbr->numTimeSlots; | |
541 sbr->n_rel_lead[ch] = bs_num_env - 1; | |
542 sbr->n_rel_trail[ch] = 0; | |
543 break; | |
544 | |
545 case FIXVAR: | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
546 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
|
547 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
|
548 bs_num_env = (uint8_t)faad_getbits(ld, 2 |
61 | 549 DEBUGVAR(1,252,"sbr_grid(): bs_num_env")) + 1; |
550 | |
551 for (rel = 0; rel < bs_num_env-1; rel++) | |
552 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
553 sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
61 | 554 DEBUGVAR(1,253,"sbr_grid(): bs_rel_bord")) + 2; |
555 } | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
556 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
|
557 sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
61 | 558 DEBUGVAR(1,254,"sbr_grid(): bs_pointer")); |
559 | |
560 for (env = 0; env < bs_num_env; env++) | |
561 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
562 sbr->f[ch][bs_num_env - env - 1] = (uint8_t)faad_get1bit(ld |
61 | 563 DEBUGVAR(1,255,"sbr_grid(): bs_freq_res")); |
564 } | |
565 | |
566 sbr->abs_bord_lead[ch] = 0; | |
567 sbr->abs_bord_trail[ch] = bs_abs_bord; | |
568 sbr->n_rel_lead[ch] = 0; | |
569 sbr->n_rel_trail[ch] = bs_num_env - 1; | |
570 break; | |
571 | |
572 case VARFIX: | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
573 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
|
574 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
|
575 bs_num_env = (uint8_t)faad_getbits(ld, 2 |
61 | 576 DEBUGVAR(1,257,"sbr_grid(): bs_num_env")) + 1; |
577 | |
578 for (rel = 0; rel < bs_num_env-1; rel++) | |
579 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
580 sbr->bs_rel_bord[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
61 | 581 DEBUGVAR(1,258,"sbr_grid(): bs_rel_bord")) + 2; |
582 } | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
583 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
|
584 sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
61 | 585 DEBUGVAR(1,259,"sbr_grid(): bs_pointer")); |
586 | |
587 for (env = 0; env < bs_num_env; env++) | |
588 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
589 sbr->f[ch][env] = (uint8_t)faad_get1bit(ld |
61 | 590 DEBUGVAR(1,260,"sbr_grid(): bs_freq_res")); |
591 } | |
592 | |
593 sbr->abs_bord_lead[ch] = bs_abs_bord; | |
594 sbr->abs_bord_trail[ch] = sbr->numTimeSlots; | |
595 sbr->n_rel_lead[ch] = bs_num_env - 1; | |
596 sbr->n_rel_trail[ch] = 0; | |
597 break; | |
598 | |
599 case VARVAR: | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 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
|
604 sbr->bs_num_rel_0[ch] = (uint8_t)faad_getbits(ld, 2 |
61 | 605 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
|
606 sbr->bs_num_rel_1[ch] = (uint8_t)faad_getbits(ld, 2 |
61 | 607 DEBUGVAR(1,264,"sbr_grid(): bs_num_rel_1")); |
608 | |
609 bs_num_env = min(5, sbr->bs_num_rel_0[ch] + sbr->bs_num_rel_1[ch] + 1); | |
610 | |
611 for (rel = 0; rel < sbr->bs_num_rel_0[ch]; rel++) | |
612 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
613 sbr->bs_rel_bord_0[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
61 | 614 DEBUGVAR(1,265,"sbr_grid(): bs_rel_bord")) + 2; |
615 } | |
616 for(rel = 0; rel < sbr->bs_num_rel_1[ch]; rel++) | |
617 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
618 sbr->bs_rel_bord_1[ch][rel] = 2 * (uint8_t)faad_getbits(ld, 2 |
61 | 619 DEBUGVAR(1,266,"sbr_grid(): bs_rel_bord")) + 2; |
620 } | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
621 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
|
622 sbr->bs_pointer[ch] = (uint8_t)faad_getbits(ld, i |
61 | 623 DEBUGVAR(1,267,"sbr_grid(): bs_pointer")); |
624 | |
625 for (env = 0; env < bs_num_env; env++) | |
626 { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
627 sbr->f[ch][env] = (uint8_t)faad_get1bit(ld |
61 | 628 DEBUGVAR(1,268,"sbr_grid(): bs_freq_res")); |
629 } | |
630 | |
631 sbr->abs_bord_lead[ch] = bs_abs_bord; | |
632 sbr->abs_bord_trail[ch] = bs_abs_bord_1; | |
633 sbr->n_rel_lead[ch] = sbr->bs_num_rel_0[ch]; | |
634 sbr->n_rel_trail[ch] = sbr->bs_num_rel_1[ch]; | |
635 break; | |
636 } | |
637 | |
638 if (sbr->bs_frame_class[ch] == VARVAR) | |
639 sbr->L_E[ch] = min(bs_num_env, 5); | |
640 else | |
641 sbr->L_E[ch] = min(bs_num_env, 4); | |
642 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
643 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
|
644 return 1; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
645 |
61 | 646 if (sbr->L_E[ch] > 1) |
647 sbr->L_Q[ch] = 2; | |
648 else | |
649 sbr->L_Q[ch] = 1; | |
650 | |
651 /* TODO: this code can probably be integrated into the code above! */ | |
652 if ((result = envelope_time_border_vector(sbr, ch)) > 0) | |
653 return result; | |
654 noise_floor_time_border_vector(sbr, ch); | |
655 | |
656 return 0; | |
657 } | |
658 | |
659 /* table 8 */ | |
660 static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch) | |
661 { | |
662 uint8_t i; | |
663 | |
664 for (i = 0; i < sbr->L_E[ch]; i++) | |
665 { | |
666 sbr->bs_df_env[ch][i] = faad_get1bit(ld | |
667 DEBUGVAR(1,269,"sbr_dtdf(): bs_df_env")); | |
668 } | |
669 | |
670 for (i = 0; i < sbr->L_Q[ch]; i++) | |
671 { | |
672 sbr->bs_df_noise[ch][i] = faad_get1bit(ld | |
673 DEBUGVAR(1,270,"sbr_dtdf(): bs_df_noise")); | |
674 } | |
675 } | |
676 | |
677 /* table 9 */ | |
678 static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch) | |
679 { | |
680 uint8_t n; | |
681 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
682 for (n = 0; n < sbr->N_Q; n++) |
61 | 683 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
684 sbr->bs_invf_mode[ch][n] = (uint8_t)faad_getbits(ld, 2 |
61 | 685 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
|
686 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
687 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
688 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
689 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
|
690 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
|
691 { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
692 switch (bs_extension_id) |
61 | 693 { |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
694 #ifdef PS_DEC |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
695 case EXTENSION_ID_PS: |
1010 | 696 sbr->ps_used = 1; |
697 return ps_data(&(sbr->ps), ld); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
698 #endif |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
699 #ifdef DRM_PS |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
700 case DRM_PARAMETRIC_STEREO: |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
701 sbr->ps_used = 1; |
1010 | 702 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
|
703 #endif |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
704 default: |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
705 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
|
706 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
|
707 return 6; |
61 | 708 } |
709 } | |
710 | |
711 /* table 12 */ | |
712 static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch) | |
713 { | |
714 uint8_t n; | |
715 | |
716 for (n = 0; n < sbr->N_high; n++) | |
717 { | |
718 sbr->bs_add_harmonic[ch][n] = faad_get1bit(ld | |
719 DEBUGVAR(1,278,"sinusoidal_coding(): bs_add_harmonic")); | |
720 } | |
721 } | |
722 | |
723 | |
724 #endif /* SBR_DEC */ |