diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2010-12-14 14:52:40 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2010-12-14 14:52:40 +0000 |
commit | 282255bbd21815ef6471298ce9e3422b58984678 (patch) | |
tree | ea22d2c64fa4cf5eea72895d17fada85f17d6025 /libavcodec/ac3enc.c | |
parent | e35c984a5d5702d2762e970f69bfb1f1265db579 (diff) | |
download | ffmpeg-282255bbd21815ef6471298ce9e3422b58984678.tar.gz |
Split setting of bandwidth into a separate function.
Originally committed as revision 25984 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r-- | libavcodec/ac3enc.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 6adc11f83c..296c156832 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1295,12 +1295,44 @@ static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) /** + * Set bandwidth for all channels. + * The user can optionally supply a cutoff frequency. Otherwise an appropriate + * default value will be used. + */ +static av_cold void set_bandwidth(AC3EncodeContext *s, int cutoff) +{ + int ch, bw_code; + + if (cutoff) { + /* calculate bandwidth based on user-specified cutoff frequency */ + int fbw_coeffs; + cutoff = av_clip(cutoff, 1, s->sample_rate >> 1); + fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; + bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); + } else { + /* use default bandwidth setting */ + /* XXX: should compute the bandwidth according to the frame + size, so that we avoid annoying high frequency artifacts */ + bw_code = 50; + } + + /* set number of coefficients for each channel */ + for (ch = 0; ch < s->fbw_channels; ch++) { + s->bandwidth_code[ch] = bw_code; + s->nb_coefs[ch] = bw_code * 3 + 73; + } + if (s->lfe_on) + s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */ +} + + +/** * Initialize the encoder. */ static av_cold int ac3_encode_init(AVCodecContext *avctx) { AC3EncodeContext *s = avctx->priv_data; - int ch, bw_code, ret; + int ret; avctx->frame_size = AC3_FRAME_SIZE; @@ -1318,25 +1350,7 @@ static av_cold int ac3_encode_init(AVCodecContext *avctx) s->samples_written = 0; s->frame_size = s->frame_size_min; - /* set bandwidth */ - if (avctx->cutoff) { - /* calculate bandwidth based on user-specified cutoff frequency */ - int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1); - int fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; - bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); - } else { - /* use default bandwidth setting */ - /* XXX: should compute the bandwidth according to the frame - size, so that we avoid annoying high frequency artifacts */ - bw_code = 50; - } - for (ch = 0; ch < s->fbw_channels; ch++) { - /* bandwidth for each channel */ - s->bandwidth_code[ch] = bw_code; - s->nb_coefs[ch] = bw_code * 3 + 73; - } - if (s->lfe_on) - s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */ + set_bandwidth(s, avctx->cutoff); /* initial snr offset */ s->coarse_snr_offset = 40; |