diff mbox

[FFmpeg-devel] wmavoice: protect against zero-energy in adaptive gain control.

Message ID 1482274900-23137-1-git-send-email-rsbultje@gmail.com
State Accepted
Commit 33d7f822f8ed2d1870babc1d04d4d48cf8b6f240
Headers show

Commit Message

Ronald S. Bultje Dec. 20, 2016, 11:01 p.m. UTC
Otherwise the scale factor becomes NaN, resulting in corrupt output.
Fixes #5426.
---
 libavcodec/wmavoice.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paul B Mahol Dec. 21, 2016, 7:50 a.m. UTC | #1
On 12/21/16, Ronald S. Bultje <rsbultje@gmail.com> wrote:
> Otherwise the scale factor becomes NaN, resulting in corrupt output.
> Fixes #5426.
> ---
>  libavcodec/wmavoice.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
> index 90dfe20..cd5958c 100644
> --- a/libavcodec/wmavoice.c
> +++ b/libavcodec/wmavoice.c
> @@ -512,7 +512,8 @@ static void adaptive_gain_control(float *out, const
> float *in,
>          speech_energy     += fabsf(speech_synth[i]);
>          postfilter_energy += fabsf(in[i]);
>      }
> -    gain_scale_factor = (1.0 - alpha) * speech_energy / postfilter_energy;
> +    gain_scale_factor = postfilter_energy == 0.0 ? 0.0 :
> +                        (1.0 - alpha) * speech_energy / postfilter_energy;
>
>      for (i = 0; i < size; i++) {
>          mem = alpha * mem + gain_scale_factor;
> --
> 2.8.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

lgtm
Ronald S. Bultje Dec. 27, 2016, 3:07 p.m. UTC | #2
Hi,

On Wed, Dec 21, 2016 at 2:50 AM, Paul B Mahol <onemda@gmail.com> wrote:

> On 12/21/16, Ronald S. Bultje <rsbultje@gmail.com> wrote:
> > Otherwise the scale factor becomes NaN, resulting in corrupt output.
> > Fixes #5426.
> > ---
> >  libavcodec/wmavoice.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
> > index 90dfe20..cd5958c 100644
> > --- a/libavcodec/wmavoice.c
> > +++ b/libavcodec/wmavoice.c
> > @@ -512,7 +512,8 @@ static void adaptive_gain_control(float *out, const
> > float *in,
> >          speech_energy     += fabsf(speech_synth[i]);
> >          postfilter_energy += fabsf(in[i]);
> >      }
> > -    gain_scale_factor = (1.0 - alpha) * speech_energy /
> postfilter_energy;
> > +    gain_scale_factor = postfilter_energy == 0.0 ? 0.0 :
> > +                        (1.0 - alpha) * speech_energy /
> postfilter_energy;
> >
> >      for (i = 0; i < size; i++) {
> >          mem = alpha * mem + gain_scale_factor;
> > --
> > 2.8.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
> lgtm
>

Whole set pushed.

Ronald
diff mbox

Patch

diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index 90dfe20..cd5958c 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -512,7 +512,8 @@  static void adaptive_gain_control(float *out, const float *in,
         speech_energy     += fabsf(speech_synth[i]);
         postfilter_energy += fabsf(in[i]);
     }
-    gain_scale_factor = (1.0 - alpha) * speech_energy / postfilter_energy;
+    gain_scale_factor = postfilter_energy == 0.0 ? 0.0 :
+                        (1.0 - alpha) * speech_energy / postfilter_energy;
 
     for (i = 0; i < size; i++) {
         mem = alpha * mem + gain_scale_factor;