Mercurial > libavcodec.hg
comparison flacdec.c @ 9208:443f056ba7e7 libavcodec
share channel mode constants between the FLAC decoder and FLAC encoder
author | jbr |
---|---|
date | Sat, 21 Mar 2009 00:44:42 +0000 |
parents | f534d0cca450 |
children | ca10c935dc56 |
comparison
equal
deleted
inserted
replaced
9207:058ade8fcc89 | 9208:443f056ba7e7 |
---|---|
44 #include "flac.h" | 44 #include "flac.h" |
45 | 45 |
46 #undef NDEBUG | 46 #undef NDEBUG |
47 #include <assert.h> | 47 #include <assert.h> |
48 | 48 |
49 enum decorrelation_type { | |
50 INDEPENDENT, | |
51 LEFT_SIDE, | |
52 RIGHT_SIDE, | |
53 MID_SIDE, | |
54 }; | |
55 | |
56 typedef struct FLACContext { | 49 typedef struct FLACContext { |
57 FLACSTREAMINFO | 50 FLACSTREAMINFO |
58 | 51 |
59 AVCodecContext *avctx; ///< parent AVCodecContext | 52 AVCodecContext *avctx; ///< parent AVCodecContext |
60 GetBitContext gb; ///< GetBitContext initialized to start at the current frame | 53 GetBitContext gb; ///< GetBitContext initialized to start at the current frame |
61 | 54 |
62 int blocksize; ///< number of samples in the current frame | 55 int blocksize; ///< number of samples in the current frame |
63 int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits | 56 int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits |
64 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit | 57 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit |
65 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit | 58 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit |
66 enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame | 59 int decorrelation; ///< channel decorrelation type in the current frame |
67 int got_streaminfo; ///< indicates if the STREAMINFO has been read | 60 int got_streaminfo; ///< indicates if the STREAMINFO has been read |
68 | 61 |
69 int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples | 62 int32_t *decoded[FLAC_MAX_CHANNELS]; ///< decoded samples |
70 uint8_t *bitstream; | 63 uint8_t *bitstream; |
71 unsigned int bitstream_size; | 64 unsigned int bitstream_size; |
443 int type, wasted = 0; | 436 int type, wasted = 0; |
444 int i, tmp; | 437 int i, tmp; |
445 | 438 |
446 s->curr_bps = s->bps; | 439 s->curr_bps = s->bps; |
447 if (channel == 0) { | 440 if (channel == 0) { |
448 if (s->decorrelation == RIGHT_SIDE) | 441 if (s->decorrelation == FLAC_CHMODE_RIGHT_SIDE) |
449 s->curr_bps++; | 442 s->curr_bps++; |
450 } else { | 443 } else { |
451 if (s->decorrelation == LEFT_SIDE || s->decorrelation == MID_SIDE) | 444 if (s->decorrelation == FLAC_CHMODE_LEFT_SIDE || s->decorrelation == FLAC_CHMODE_MID_SIDE) |
452 s->curr_bps++; | 445 s->curr_bps++; |
453 } | 446 } |
454 | 447 |
455 if (get_bits1(&s->gb)) { | 448 if (get_bits1(&s->gb)) { |
456 av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n"); | 449 av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n"); |
506 | 499 |
507 sample_rate_code = get_bits(&s->gb, 4); | 500 sample_rate_code = get_bits(&s->gb, 4); |
508 | 501 |
509 assignment = get_bits(&s->gb, 4); /* channel assignment */ | 502 assignment = get_bits(&s->gb, 4); /* channel assignment */ |
510 if (assignment < FLAC_MAX_CHANNELS && s->channels == assignment+1) | 503 if (assignment < FLAC_MAX_CHANNELS && s->channels == assignment+1) |
511 decorrelation = INDEPENDENT; | 504 decorrelation = FLAC_CHMODE_INDEPENDENT; |
512 else if (assignment >= FLAC_MAX_CHANNELS && assignment < 11 && s->channels == 2) | 505 else if (assignment >= FLAC_MAX_CHANNELS && assignment < 11 && s->channels == 2) |
513 decorrelation = LEFT_SIDE + assignment - 8; | 506 decorrelation = assignment; |
514 else { | 507 else { |
515 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", | 508 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", |
516 assignment, s->channels); | 509 assignment, s->channels); |
517 return -1; | 510 return -1; |
518 } | 511 } |
708 }\ | 701 }\ |
709 }\ | 702 }\ |
710 break; | 703 break; |
711 | 704 |
712 switch (s->decorrelation) { | 705 switch (s->decorrelation) { |
713 case INDEPENDENT: | 706 case FLAC_CHMODE_INDEPENDENT: |
714 for (j = 0; j < s->blocksize; j++) { | 707 for (j = 0; j < s->blocksize; j++) { |
715 for (i = 0; i < s->channels; i++) { | 708 for (i = 0; i < s->channels; i++) { |
716 if (s->is32) | 709 if (s->is32) |
717 *samples_32++ = s->decoded[i][j] << s->sample_shift; | 710 *samples_32++ = s->decoded[i][j] << s->sample_shift; |
718 else | 711 else |
719 *samples_16++ = s->decoded[i][j] << s->sample_shift; | 712 *samples_16++ = s->decoded[i][j] << s->sample_shift; |
720 } | 713 } |
721 } | 714 } |
722 break; | 715 break; |
723 case LEFT_SIDE: | 716 case FLAC_CHMODE_LEFT_SIDE: |
724 DECORRELATE(a,a-b) | 717 DECORRELATE(a,a-b) |
725 case RIGHT_SIDE: | 718 case FLAC_CHMODE_RIGHT_SIDE: |
726 DECORRELATE(a+b,b) | 719 DECORRELATE(a+b,b) |
727 case MID_SIDE: | 720 case FLAC_CHMODE_MID_SIDE: |
728 DECORRELATE( (a-=b>>1) + b, a) | 721 DECORRELATE( (a-=b>>1) + b, a) |
729 } | 722 } |
730 | 723 |
731 end: | 724 end: |
732 if (bytes_read > buf_size) { | 725 if (bytes_read > buf_size) { |