diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2015-10-07 09:17:50 -0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2015-10-07 09:23:33 -0400 |
commit | 7c49ad0c5b1cd5ee830f449a34cc32b469db3cee (patch) | |
tree | 719c2440d2f734395240c899e4e2486aff4ec9b8 | |
parent | 5dca296833ce4941dceadf956ff0fb6fe59fe4e8 (diff) | |
download | opus-7c49ad0c5b1cd5ee830f449a34cc32b469db3cee.tar.gz |
Preventing NaNs from crashing surround_analysis()
-rw-r--r-- | src/opus_encoder.c | 3 | ||||
-rw-r--r-- | src/opus_multistream_encoder.c | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c index d94163f4..d11e972f 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -1465,7 +1465,10 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ /* This should filter out both NaNs and ridiculous signals that could cause NaNs further down. */ if (!(sum < 1e9f) || celt_isnan(sum)) + { OPUS_CLEAR(&pcm_buf[total_buffer*st->channels], frame_size*st->channels); + st->hp_mem[0] = st->hp_mem[1] = st->hp_mem[2] = st->hp_mem[3] = 0; + } } #endif diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c index 7163d144..b55ab7ac 100644 --- a/src/opus_multistream_encoder.c +++ b/src/opus_multistream_encoder.c @@ -41,6 +41,7 @@ #include "modes.h" #include "bands.h" #include "quant_bands.h" +#include "pitch.h" typedef struct { int nb_streams; @@ -259,6 +260,19 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b OPUS_COPY(in, mem+c*overlap, overlap); (*copy_channel_in)(x, 1, pcm, channels, c, len); celt_preemphasis(x, in+overlap, frame_size, 1, upsample, celt_mode->preemph, preemph_mem+c, 0); +#ifndef FIXED_POINT + { + opus_val32 sum; + sum = celt_inner_prod(in, in, frame_size+overlap, 0); + /* This should filter out both NaNs and ridiculous signals that could + cause NaNs further down. */ + if (!(sum < 1e9f) || celt_isnan(sum)) + { + OPUS_CLEAR(in, frame_size+overlap); + preemph_mem[c] = 0; + } + } +#endif clt_mdct_forward(&celt_mode->mdct, in, freq, celt_mode->window, overlap, celt_mode->maxLM-LM, 1); if (upsample != 1) { |