Mercurial > libavcodec.hg
comparison flacdec.c @ 8701:bb7f9053df83 libavcodec
flacdec: add support for SAMPLE_FMT_32
author | jbr |
---|---|
date | Sat, 31 Jan 2009 01:20:40 +0000 |
parents | 94f7aca055d5 |
children | f284b60e2bc5 |
comparison
equal
deleted
inserted
replaced
8700:ebb66d91b011 | 8701:bb7f9053df83 |
---|---|
61 AVCodecContext *avctx; | 61 AVCodecContext *avctx; |
62 GetBitContext gb; | 62 GetBitContext gb; |
63 | 63 |
64 int blocksize/*, last_blocksize*/; | 64 int blocksize/*, last_blocksize*/; |
65 int curr_bps; | 65 int curr_bps; |
66 int sample_shift; /* shift required to make output samples 16-bit or 32-bit */ | |
67 int is32; /* flag to indicate if output should be 32-bit instead of 16-bit */ | |
66 enum decorrelation_type decorrelation; | 68 enum decorrelation_type decorrelation; |
67 | 69 |
68 int32_t *decoded[MAX_CHANNELS]; | 70 int32_t *decoded[MAX_CHANNELS]; |
69 uint8_t *bitstream; | 71 uint8_t *bitstream; |
70 unsigned int bitstream_size; | 72 unsigned int bitstream_size; |
166 s->channels = get_bits(&gb, 3) + 1; | 168 s->channels = get_bits(&gb, 3) + 1; |
167 s->bps = get_bits(&gb, 5) + 1; | 169 s->bps = get_bits(&gb, 5) + 1; |
168 | 170 |
169 avctx->channels = s->channels; | 171 avctx->channels = s->channels; |
170 avctx->sample_rate = s->samplerate; | 172 avctx->sample_rate = s->samplerate; |
173 avctx->bits_per_raw_sample = s->bps; | |
174 if (s->bps > 16) | |
175 avctx->sample_fmt = SAMPLE_FMT_S32; | |
176 else | |
177 avctx->sample_fmt = SAMPLE_FMT_S16; | |
171 | 178 |
172 s->samples = get_bits_long(&gb, 32) << 4; | 179 s->samples = get_bits_long(&gb, 32) << 4; |
173 s->samples |= get_bits_long(&gb, 4); | 180 s->samples |= get_bits_long(&gb, 4); |
174 | 181 |
175 skip_bits(&gb, 64); /* md5 sum */ | 182 skip_bits(&gb, 64); /* md5 sum */ |
464 else { | 471 else { |
465 av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", | 472 av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", |
466 sample_size_code); | 473 sample_size_code); |
467 return -1; | 474 return -1; |
468 } | 475 } |
476 if (bps > 16) { | |
477 s->avctx->sample_fmt = SAMPLE_FMT_S32; | |
478 s->sample_shift = 32 - bps; | |
479 s->is32 = 1; | |
480 } else { | |
481 s->avctx->sample_fmt = SAMPLE_FMT_S16; | |
482 s->sample_shift = 16 - bps; | |
483 s->is32 = 0; | |
484 } | |
485 s->bps = s->avctx->bits_per_raw_sample = bps; | |
469 | 486 |
470 if (get_bits1(&s->gb)) { | 487 if (get_bits1(&s->gb)) { |
471 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); | 488 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); |
472 return -1; | 489 return -1; |
473 } | 490 } |
544 void *data, int *data_size, | 561 void *data, int *data_size, |
545 const uint8_t *buf, int buf_size) | 562 const uint8_t *buf, int buf_size) |
546 { | 563 { |
547 FLACContext *s = avctx->priv_data; | 564 FLACContext *s = avctx->priv_data; |
548 int tmp = 0, i, j = 0, input_buf_size = 0; | 565 int tmp = 0, i, j = 0, input_buf_size = 0; |
549 int16_t *samples = data; | 566 int16_t *samples_16 = data; |
567 int32_t *samples_32 = data; | |
550 int alloc_data_size= *data_size; | 568 int alloc_data_size= *data_size; |
551 | 569 |
552 *data_size=0; | 570 *data_size=0; |
553 | 571 |
554 if (s->max_framesize == 0) { | 572 if (s->max_framesize == 0) { |
606 #define DECORRELATE(left, right)\ | 624 #define DECORRELATE(left, right)\ |
607 assert(s->channels == 2);\ | 625 assert(s->channels == 2);\ |
608 for (i = 0; i < s->blocksize; i++) {\ | 626 for (i = 0; i < s->blocksize; i++) {\ |
609 int a= s->decoded[0][i];\ | 627 int a= s->decoded[0][i];\ |
610 int b= s->decoded[1][i];\ | 628 int b= s->decoded[1][i];\ |
611 *samples++ = ((left) << (24 - s->bps)) >> 8;\ | 629 if (s->is32) {\ |
612 *samples++ = ((right) << (24 - s->bps)) >> 8;\ | 630 *samples_32++ = (left) << s->sample_shift;\ |
631 *samples_32++ = (right) << s->sample_shift;\ | |
632 } else {\ | |
633 *samples_16++ = (left) << s->sample_shift;\ | |
634 *samples_16++ = (right) << s->sample_shift;\ | |
635 }\ | |
613 }\ | 636 }\ |
614 break; | 637 break; |
615 | 638 |
616 switch (s->decorrelation) { | 639 switch (s->decorrelation) { |
617 case INDEPENDENT: | 640 case INDEPENDENT: |
618 for (j = 0; j < s->blocksize; j++) { | 641 for (j = 0; j < s->blocksize; j++) { |
619 for (i = 0; i < s->channels; i++) | 642 for (i = 0; i < s->channels; i++) { |
620 *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8; | 643 if (s->is32) |
644 *samples_32++ = s->decoded[i][j] << s->sample_shift; | |
645 else | |
646 *samples_16++ = s->decoded[i][j] << s->sample_shift; | |
647 } | |
621 } | 648 } |
622 break; | 649 break; |
623 case LEFT_SIDE: | 650 case LEFT_SIDE: |
624 DECORRELATE(a,a-b) | 651 DECORRELATE(a,a-b) |
625 case RIGHT_SIDE: | 652 case RIGHT_SIDE: |
626 DECORRELATE(a+b,b) | 653 DECORRELATE(a+b,b) |
627 case MID_SIDE: | 654 case MID_SIDE: |
628 DECORRELATE( (a-=b>>1) + b, a) | 655 DECORRELATE( (a-=b>>1) + b, a) |
629 } | 656 } |
630 | 657 |
631 *data_size = (int8_t *)samples - (int8_t *)data; | 658 *data_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); |
632 | 659 |
633 end: | 660 end: |
634 i= (get_bits_count(&s->gb)+7)/8; | 661 i= (get_bits_count(&s->gb)+7)/8; |
635 if (i > buf_size) { | 662 if (i > buf_size) { |
636 av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); | 663 av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); |