comparison ac3enc.c @ 6083:77d27412c35d libavcodec

use cutoff frequency to adjust bandwidth in ac3 encoder
author jbr
date Fri, 28 Dec 2007 06:13:55 +0000
parents f17aad297a38
children 75804d49f33b
comparison
equal deleted inserted replaced
6082:f17aad297a38 6083:77d27412c35d
630 int bitrate = avctx->bit_rate; 630 int bitrate = avctx->bit_rate;
631 int channels = avctx->channels; 631 int channels = avctx->channels;
632 AC3EncodeContext *s = avctx->priv_data; 632 AC3EncodeContext *s = avctx->priv_data;
633 int i, j, ch; 633 int i, j, ch;
634 float alpha; 634 float alpha;
635 int bw_code;
635 static const uint8_t channel_mode_defs[6] = { 636 static const uint8_t channel_mode_defs[6] = {
636 0x01, /* C */ 637 0x01, /* C */
637 0x02, /* L R */ 638 0x02, /* L R */
638 0x03, /* L C R */ 639 0x03, /* L C R */
639 0x06, /* L R SL SR */ 640 0x06, /* L R SL SR */
681 s->bits_written = 0; 682 s->bits_written = 0;
682 s->samples_written = 0; 683 s->samples_written = 0;
683 s->frame_size = s->frame_size_min; 684 s->frame_size = s->frame_size_min;
684 685
685 /* bit allocation init */ 686 /* bit allocation init */
687 if(avctx->cutoff) {
688 /* calculate bandwidth based on user-specified cutoff frequency */
689 int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);
690 int fbw_coeffs = cutoff * 512 / s->sample_rate;
691 bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
692 } else {
693 /* use default bandwidth setting */
694 /* XXX: should compute the bandwidth according to the frame
695 size, so that we avoid anoying high freq artefacts */
696 bw_code = 50;
697 }
686 for(ch=0;ch<s->nb_channels;ch++) { 698 for(ch=0;ch<s->nb_channels;ch++) {
687 /* bandwidth for each channel */ 699 /* bandwidth for each channel */
688 /* XXX: should compute the bandwidth according to the frame 700 s->chbwcod[ch] = bw_code;
689 size, so that we avoid anoying high freq artefacts */ 701 s->nb_coefs[ch] = bw_code * 3 + 73;
690 s->chbwcod[ch] = 50; /* sample bandwidth as mpeg audio layer 2 table 0 */
691 s->nb_coefs[ch] = ((s->chbwcod[ch] + 12) * 3) + 37;
692 } 702 }
693 if (s->lfe) { 703 if (s->lfe) {
694 s->nb_coefs[s->lfe_channel] = 7; /* fixed */ 704 s->nb_coefs[s->lfe_channel] = 7; /* fixed */
695 } 705 }
696 /* initial snr offset */ 706 /* initial snr offset */