swresample: move dither init up
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 18 Aug 2016 09:44:42 +0000 (11:44 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 18 Aug 2016 09:50:14 +0000 (11:50 +0200)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libswresample/dither.c
libswresample/swresample.c

index 08c793d..76f8ccf 100644 (file)
@@ -123,15 +123,6 @@ av_cold int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AV
         s->dither.method = SWR_DITHER_TRIANGULAR_HIGHPASS;
     }
 
-    av_assert0(!s->preout.count);
-    s->dither.noise = s->preout;
-    s->dither.temp  = s->preout;
-    if (s->dither.method > SWR_DITHER_NS) {
-        s->dither.noise.bps = 4;
-        s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP;
-        s->dither.noise_scale = 1;
-    }
-
     return 0;
 }
 
index 351623b..ade81ef 100644 (file)
@@ -322,6 +322,9 @@ av_assert0(s->out.ch_count);
     s->silence  = s->in;
     s->drop_temp= s->out;
 
+    if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
+        goto fail;
+
     if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
         s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
                                                    s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
@@ -362,8 +365,14 @@ av_assert0(s->out.ch_count);
         set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
     }
 
-    if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
-        goto fail;
+    av_assert0(!s->preout.count);
+    s->dither.noise = s->preout;
+    s->dither.temp  = s->preout;
+    if (s->dither.method > SWR_DITHER_NS) {
+        s->dither.noise.bps = 4;
+        s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP;
+        s->dither.noise_scale = 1;
+    }
 
     if(s->rematrix || s->dither.method) {
         ret = swri_rematrix_init(s);