Commit bc2eebdf authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Fixes glithes when switching between SILK-only and hybrid

We now reset the CELT state when swithing to hybrid and we "drain"
the CELT MDCT overlap when switching away from hybrid.
parent 0c5085ad
......@@ -390,11 +390,21 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (mode != MODE_SILK_ONLY)
{
int celt_frame_size = IMIN(F20, frame_size);
/* Make sure to discard any previous CELT state */
if (st->prev_mode == MODE_SILK_ONLY)
celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
/* Decode CELT */
celt_ret = celt_decode_with_ec(celt_dec, decode_fec?NULL:data, len, pcm, celt_frame_size, &dec);
} else {
unsigned char silence[2] = {0xFF, 0xFF};
for (i=0;i<frame_size*st->channels;i++)
pcm[i] = 0;
/* For hybrid -> SILK transitions, we let the CELT MDCT do a fade-out by decoding a silence frame */
if (st->prev_mode == MODE_HYBRID)
{
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0));
celt_decode_with_ec(celt_dec, silence, 2, pcm, F2_5, NULL);
}
}
if (mode != MODE_CELT_ONLY)
......
......@@ -891,7 +891,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
if (st->mode != MODE_HYBRID || st->stream_channels==1)
st->silk_mode.stereoWidth_Q14 = 1<<14;
st->hybrid_stereo_width_Q14 = st->silk_mode.stereoWidth_Q14 = 1<<14;
if( st->channels == 2 ) {
/* Apply stereo width reduction (at low bitrates) */
if( st->hybrid_stereo_width_Q14 < (1 << 14) || st->silk_mode.stereoWidth_Q14 < (1 << 14) ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment