diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2012-12-19 14:58:57 -0500 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2013-01-07 21:49:06 -0500 |
commit | 074a00d192c0e749d677b008b337da42597e780f (patch) | |
tree | 3f828927503dfef5df7eee5c974ffab75f2407be /libavresample/dither.c | |
parent | 4d68269d58ca4f6f71b4baa30e0cf9fbde52bbc3 (diff) | |
download | ffmpeg-074a00d192c0e749d677b008b337da42597e780f.tar.gz |
lavr: add a public function for setting a custom channel map
This allows reordering, duplication, and silencing of input channels.
Diffstat (limited to 'libavresample/dither.c')
-rw-r--r-- | libavresample/dither.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libavresample/dither.c b/libavresample/dither.c index 9c1e1c1101..dfff03e756 100644 --- a/libavresample/dither.c +++ b/libavresample/dither.c @@ -53,6 +53,8 @@ typedef struct DitherState { struct DitherContext { DitherDSPContext ddsp; enum AVResampleDitherMethod method; + int apply_map; + ChannelMapInfo *ch_map_info; int mute_dither_threshold; // threshold for disabling dither int mute_reset_threshold; // threshold for resetting noise shaping @@ -251,17 +253,23 @@ int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src) return ret; } - if (src->sample_fmt != AV_SAMPLE_FMT_FLTP) { + if (src->sample_fmt != AV_SAMPLE_FMT_FLTP || c->apply_map) { /* make sure flt_data is large enough for the input */ ret = ff_audio_data_realloc(c->flt_data, src->nb_samples); if (ret < 0) return ret; flt_data = c->flt_data; + } + if (src->sample_fmt != AV_SAMPLE_FMT_FLTP) { /* convert input samples to fltp and scale to s16 range */ ret = ff_audio_convert(c->ac_in, flt_data, src); if (ret < 0) return ret; + } else if (c->apply_map) { + ret = ff_audio_data_copy(flt_data, src, c->ch_map_info); + if (ret < 0) + return ret; } else { flt_data = src; } @@ -333,7 +341,7 @@ static void dither_init(DitherDSPContext *ddsp, DitherContext *ff_dither_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, - int channels, int sample_rate) + int channels, int sample_rate, int apply_map) { AVLFG seed_gen; DitherContext *c; @@ -350,6 +358,10 @@ DitherContext *ff_dither_alloc(AVAudioResampleContext *avr, if (!c) return NULL; + c->apply_map = apply_map; + if (apply_map) + c->ch_map_info = &avr->ch_map_info; + if (avr->dither_method == AV_RESAMPLE_DITHER_TRIANGULAR_NS && sample_rate != 48000 && sample_rate != 44100) { av_log(avr, AV_LOG_WARNING, "sample rate must be 48000 or 44100 Hz " @@ -379,19 +391,20 @@ DitherContext *ff_dither_alloc(AVAudioResampleContext *avr, goto fail; c->ac_out = ff_audio_convert_alloc(avr, out_fmt, AV_SAMPLE_FMT_S16P, - channels, sample_rate); + channels, sample_rate, 0); if (!c->ac_out) goto fail; } - if (in_fmt != AV_SAMPLE_FMT_FLTP) { + if (in_fmt != AV_SAMPLE_FMT_FLTP || c->apply_map) { c->flt_data = ff_audio_data_alloc(channels, 1024, AV_SAMPLE_FMT_FLTP, "dither flt buffer"); if (!c->flt_data) goto fail; - + } + if (in_fmt != AV_SAMPLE_FMT_FLTP) { c->ac_in = ff_audio_convert_alloc(avr, AV_SAMPLE_FMT_FLTP, in_fmt, - channels, sample_rate); + channels, sample_rate, c->apply_map); if (!c->ac_in) goto fail; } |