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