comparison wavpack.c @ 5482:bba203d5c5e7 libavcodec

Add the handling of the INT32INFO block to the WavPack decoder. Patch by David Bryant david at $codecname dot com Thread: [FFmpeg-devel] [PATCH] handle INT32INFO in WavPack decoder
author kostya
date Sun, 05 Aug 2007 05:56:34 +0000
parents 1bfdcac74275
children 37bf17e052fb
comparison
equal deleted inserted replaced
5481:defae3a747d9 5482:bba203d5c5e7
74 int samples; 74 int samples;
75 int median[6]; 75 int median[6];
76 int terms; 76 int terms;
77 Decorr decorr[MAX_TERMS]; 77 Decorr decorr[MAX_TERMS];
78 int zero, one, zeroes; 78 int zero, one, zeroes;
79 int and, or, shift;
79 } WavpackContext; 80 } WavpackContext;
80 81
81 // exponent table copied from WavPack source 82 // exponent table copied from WavPack source
82 static const uint8_t wp_exp2_table [256] = { 83 static const uint8_t wp_exp2_table [256] = {
83 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b, 84 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b,
233 234
234 static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst) 235 static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst)
235 { 236 {
236 int i, j, count = 0; 237 int i, j, count = 0;
237 int last, t; 238 int last, t;
238 int A, B, L, L2, R, R2; 239 int A, B, L, L2, R, R2, bit;
239 int pos = 0; 240 int pos = 0;
240 uint32_t crc = 0xFFFFFFFF; 241 uint32_t crc = 0xFFFFFFFF;
241 242
242 s->one = s->zero = s->zeroes = 0; 243 s->one = s->zero = s->zeroes = 0;
243 do{ 244 do{
297 } 298 }
298 pos = (pos + 1) & 7; 299 pos = (pos + 1) & 7;
299 if(s->joint) 300 if(s->joint)
300 L += (R -= (L >> 1)); 301 L += (R -= (L >> 1));
301 crc = (crc * 3 + L) * 3 + R; 302 crc = (crc * 3 + L) * 3 + R;
302 *dst++ = L; 303 bit = (L & s->and) | s->or;
303 *dst++ = R; 304 *dst++ = ((L + bit) << s->shift) - bit;
304 305 bit = (R & s->and) | s->or;
306 *dst++ = ((R + bit) << s->shift) - bit;
305 count++; 307 count++;
306 }while(!last && count < s->samples); 308 }while(!last && count < s->samples);
307 309
308 if(crc != s->CRC){ 310 if(crc != s->CRC){
309 av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); 311 av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
314 316
315 static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst) 317 static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst)
316 { 318 {
317 int i, j, count = 0; 319 int i, j, count = 0;
318 int last, t; 320 int last, t;
319 int A, S, T; 321 int A, S, T, bit;
320 int pos = 0; 322 int pos = 0;
321 uint32_t crc = 0xFFFFFFFF; 323 uint32_t crc = 0xFFFFFFFF;
322 324
323 s->one = s->zero = s->zeroes = 0; 325 s->one = s->zero = s->zeroes = 0;
324 do{ 326 do{
342 if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; 344 if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
343 s->decorr[i].samplesA[j] = T = S; 345 s->decorr[i].samplesA[j] = T = S;
344 } 346 }
345 pos = (pos + 1) & 7; 347 pos = (pos + 1) & 7;
346 crc = crc * 3 + S; 348 crc = crc * 3 + S;
347 *dst++ = S; 349 bit = (S & s->and) | s->or;
350 *dst++ = ((S + bit) << s->shift) - bit;
348 count++; 351 count++;
349 }while(!last && count < s->samples); 352 }while(!last && count < s->samples);
350 353
351 if(crc != s->CRC){ 354 if(crc != s->CRC){
352 av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); 355 av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
387 *data_size = 0; 390 *data_size = 0;
388 return 0; 391 return 0;
389 } 392 }
390 393
391 memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); 394 memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
395 s->and = s->or = s->shift = 0;
392 396
393 s->samples = AV_RL32(buf); buf += 4; 397 s->samples = AV_RL32(buf); buf += 4;
394 if(!s->samples){ 398 if(!s->samples){
395 *data_size = 0; 399 *data_size = 0;
396 return buf_size; 400 return buf_size;
507 s->median[i] = wp_exp2(AV_RL16(buf)); 511 s->median[i] = wp_exp2(AV_RL16(buf));
508 buf += 2; 512 buf += 2;
509 } 513 }
510 got_entropy = 1; 514 got_entropy = 1;
511 break; 515 break;
516 case WP_ID_INT32INFO:
517 if(size != 4 || *buf){
518 av_log(avctx, AV_LOG_ERROR, "Invalid INT32INFO, size = %i, sent_bits = %i\n", size, *buf);
519 buf += ssize;
520 continue;
521 }
522 if(buf[1])
523 s->shift = buf[1];
524 else if(buf[2]){
525 s->and = s->or = 1;
526 s->shift = buf[2];
527 }else if(buf[3]){
528 s->and = 1;
529 s->shift = buf[3];
530 }
531 buf += 4;
532 break;
512 case WP_ID_DATA: 533 case WP_ID_DATA:
513 init_get_bits(&s->gb, buf, size * 8); 534 init_get_bits(&s->gb, buf, size * 8);
514 s->data_size = size * 8; 535 s->data_size = size * 8;
515 buf += size; 536 buf += size;
516 got_bs = 1; 537 got_bs = 1;