aboutsummaryrefslogtreecommitdiffstats
path: root/libswresample/swresample.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-04-10 19:52:42 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-04-10 19:54:41 +0200
commitdb2eadb2f57ad5a580c9ad5b2d288c4f6a2eeecb (patch)
tree1f2a13cd4aa60f6c16490efd2731681f2cad98c2 /libswresample/swresample.c
parent5c1f312888fc0094e4755c10c9700af87c9c3a40 (diff)
downloadffmpeg-db2eadb2f57ad5a580c9ad5b2d288c4f6a2eeecb.tar.gz
swr: add dither support.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/swresample.c')
-rw-r--r--libswresample/swresample.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 73e88f08dc..23b7449930 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -53,6 +53,7 @@ static const AVOption options[]={
{"rmvol", "rematrix volume" , OFFSET(rematrix_volume), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, -1000, 1000, 0},
{"flags", NULL , OFFSET(flags) , AV_OPT_TYPE_FLAGS, {.dbl=0}, 0, UINT_MAX, 0, "flags"},
{"res", "force resampling", 0, AV_OPT_TYPE_CONST, {.dbl=SWR_FLAG_RESAMPLE}, INT_MIN, INT_MAX, 0, "flags"},
+{"dither", "dither method" , OFFSET(dither_method), AV_OPT_TYPE_INT, {.dbl=0}, 0, SWR_DITHER_NB-1, 0},
{0}
};
@@ -139,6 +140,7 @@ void swr_free(SwrContext **ss){
free_temp(&s->midbuf);
free_temp(&s->preout);
free_temp(&s->in_buffer);
+ free_temp(&s->dither);
swri_audio_convert_free(&s-> in_convert);
swri_audio_convert_free(&s->out_convert);
swri_audio_convert_free(&s->full_convert);
@@ -156,6 +158,7 @@ int swr_init(struct SwrContext *s){
free_temp(&s->midbuf);
free_temp(&s->preout);
free_temp(&s->in_buffer);
+ free_temp(&s->dither);
swri_audio_convert_free(&s-> in_convert);
swri_audio_convert_free(&s->out_convert);
swri_audio_convert_free(&s->full_convert);
@@ -281,6 +284,8 @@ av_assert0(s->out.ch_count);
s->in_buffer.planar = 1;
}
+ s->dither = s->preout;
+
if(s->rematrix)
return swri_rematrix_init(s);
@@ -505,6 +510,21 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
}
if(preout != out && out_count){
+ if(s->dither_method){
+ int ch, i;
+ av_assert0(preout != in);
+
+ if((ret=realloc_audio(&s->dither, out_count))<0)
+ return ret;
+ if(ret)
+ for(ch=0; ch<s->dither.ch_count; ch++)
+ swri_get_dither(s->dither.ch[ch], s->dither.count, 12345678913579<<ch, s->out_sample_fmt, s->int_sample_fmt, s->dither_method);
+ av_assert0(s->dither.ch_count == preout->ch_count);
+
+ for(ch=0; ch<preout->ch_count; ch++){
+ swri_sum2(s->int_sample_fmt, preout->ch[ch], preout->ch[ch], s->dither.ch[ch], 1, 1, out_count);
+ }
+ }
//FIXME packed doesnt need more than 1 chan here!
swri_audio_convert(s->out_convert, out, preout, out_count);
}