History

add decode_coeffs()

Originally committed as revision 19719 to svn://svn.ffmpeg.org/ffmpeg/trunk

Sascha Sommer committed 17 years ago

Commit 85fecaf1 parent f53e96e1 file · +88 −0Browse files

Unified · Split

libavcodec/wmaprodec.c+88−0
@@ -152,6 +152,94 @@ static void decode_decorrelation_matrix(WMA3DecodeContext *s, · 151 unmodified lines
152152 }
153153 }
154154
155+/**
156+ *@brief Extract the coefficients from the bitstream.
157+ *@param s codec context
158+ *@param c current channel number
159+ *@return 0 on success, < 0 in case of bitstream errors
160+ */
161+static int decode_coeffs(WMA3DecodeContext *s, int c)
162+{
163+ int vlctable;
164+ VLC* vlc;
165+ WMA3ChannelCtx* ci = &s->channel[c];
166+ int rl_mode = 0;
167+ int cur_coeff = 0;
168+ int num_zeros = 0;
169+ const uint16_t* run;
170+ const uint16_t* level;
171+
172+ dprintf(s->avctx, "decode coefficients for channel %i\n", c);
173+
174+ vlctable = get_bits1(&s->gb);
175+ vlc = &coef_vlc[vlctable];
176+
177+ if (vlctable) {
178+ run = coef1_run;
179+ level = coef1_level;
180+ } else {
181+ run = coef0_run;
182+ level = coef0_level;
183+ }
184+
185+ /** decode vector coefficients (consumes up to 167 bits per iteration for
186+ 4 vector coded large values) */
187+ while (!rl_mode && cur_coeff + 3 < s->subframe_len) {
188+ int vals[4];
189+ int i;
190+ unsigned int idx;
191+
192+ idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
193+
194+ if ( idx == HUFF_VEC4_SIZE - 1 ) {
195+ for (i = 0; i < 4; i += 2) {
196+ idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
197+ if ( idx == HUFF_VEC2_SIZE - 1 ) {
198+ vals[i] = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
199+ if (vals[i] == HUFF_VEC1_SIZE - 1)
200+ vals[i] += ff_wma_get_large_val(&s->gb);
201+ vals[i+1] = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
202+ if (vals[i+1] == HUFF_VEC1_SIZE - 1)
203+ vals[i+1] += ff_wma_get_large_val(&s->gb);
204+ } else {
205+ vals[i] = symbol_to_vec2[idx] >> 4;
206+ vals[i+1] = symbol_to_vec2[idx] & 0xF;
207+ }
208+ }
209+ } else {
210+ vals[0] = symbol_to_vec4[idx] >> 12;
211+ vals[1] = (symbol_to_vec4[idx] >> 8) & 0xF;
212+ vals[2] = (symbol_to_vec4[idx] >> 4) & 0xF;
213+ vals[3] = symbol_to_vec4[idx] & 0xF;
214+ }
215+
216+ /** decode sign */
217+ for (i = 0; i < 4; i++) {
218+ if (vals[i]) {
219+ int sign = get_bits1(&s->gb) - 1;
220+ ci->coeffs[cur_coeff] = (vals[i]^sign) - sign;
221+ num_zeros = 0;
222+ } else {
223+ /** switch to run level mode when subframe_len / 128 zeros
224+ were found in a row */
225+ rl_mode |= (++num_zeros > s->subframe_len>>8);
226+ }
227+ ++cur_coeff;
228+ }
229+ }
230+
231+ /** decode run level coded coefficients */
232+ if (rl_mode) {
233+ if(ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
234+ level, run, 1, ci->coeffs,
235+ cur_coeff, s->subframe_len, s->subframe_len,
236+ s->esc_len, 0))
237+ return AVERROR_INVALIDDATA;
238+ }
239+
240+ return 0;
241+}
242+
155243 /**
156244 *@brief Reconstruct the individual channel data.
157245 *@param s codec context

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t