diff --git a/silk/control_audio_bandwidth.c b/silk/control_audio_bandwidth.c index b645dd57f45202927acd408829c92f486eda0e95..ef02fedacd10d6f6e52729abe5addd29a68b06f2 100644 --- a/silk/control_audio_bandwidth.c +++ b/silk/control_audio_bandwidth.c @@ -115,6 +115,9 @@ opus_int silk_control_audio_bandwidth( psEncC->sLP.mode = 1; } } + } else { + if (psEncC->sLP.mode<0) + psEncC->sLP.mode = 1; } } } diff --git a/src/opus_encoder.c b/src/opus_encoder.c index ec7d6e7bb20f52acb9a14d228c3e50efb60d043e..a4983291d2cfe3842333bb8d17c92a91790d76ce 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -858,9 +858,15 @@ 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 + /* Use detected bandwidth to reduce the encoded bandwidth. */ if (st->detected_bandwidth && st->user_bandwidth == OPUS_AUTO) { - st->bandwidth = IMIN(st->bandwidth, st->detected_bandwidth); + /* When operating in SILK/hybrid mode, we don't go below wideband to avoid + more complicated switches that require redundancy */ + if (st->mode == MODE_CELT_ONLY) + st->bandwidth = IMIN(st->bandwidth, st->detected_bandwidth); + else + st->bandwidth = IMIN(st->bandwidth, IMAX(OPUS_BANDWIDTH_WIDEBAND, st->detected_bandwidth)); } #endif celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(lsb_depth));