diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2012-12-21 12:28:25 -0500 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2012-12-21 12:28:25 -0500 |
commit | 2dd3fb9d593eec5d4121ccfe19e927f03ed75931 (patch) | |
tree | 68cb0ec4cfd695acc2bd8b354055d6dc3e3f653c | |
parent | 5fb50adb7a4dc955a9d9a59e97fd8795ae7a08e9 (diff) | |
download | opus-2dd3fb9d593eec5d4121ccfe19e927f03ed75931.tar.gz |
Fixes bandwidth detection by not relying on uninitialized data
-rw-r--r-- | src/opus_encoder.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 705e57e4..d1df5bfa 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -89,6 +89,7 @@ struct OpusEncoder { opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2]; #ifndef FIXED_POINT TonalityAnalysisState analysis; + int detected_bandwidth; #endif opus_uint32 rangeFinal; }; @@ -857,9 +858,9 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ if (st->Fs <= 8000 && st->bandwidth > OPUS_BANDWIDTH_NARROWBAND) st->bandwidth = OPUS_BANDWIDTH_NARROWBAND; #ifndef FIXED_POINT - if (analysis_info.valid) + if (st->detected_bandwidth) { - st->bandwidth = IMIN(st->bandwidth, analysis_info.opus_bandwidth); + st->bandwidth = IMIN(st->bandwidth, st->detected_bandwidth); } #endif celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(lsb_depth)); @@ -983,9 +984,11 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ tonality_analysis(&st->analysis, &analysis_info, celt_enc, pcm_buf+i*(st->Fs/100)*st->channels, st->channels, lsb_depth); if (st->signal_type == OPUS_AUTO) st->voice_ratio = (int)floor(.5+100*(1-analysis_info.music_prob)); + st->detected_bandwidth = analysis_info.opus_bandwidth; } else { analysis_info.valid = 0; st->voice_ratio = -1; + st->detected_bandwidth = 0; } #endif |