ref: 1b16fec48451f12ad9ca6f2565b710e159e99791
parent: 0c0c5f940a3fc58c84b51765fc04f0294b42fd2d
author: Jean-Marc Valin <[email protected]>
date: Mon Mar 7 18:53:53 EST 2011
Fixes a few issues with PLC-based mode switching
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -152,7 +152,7 @@
}
if (audiosize > frame_size)
{
- fprintf(stderr, "PCM buffer too small");
+ fprintf(stderr, "PCM buffer too small: %d vs %d (mode = %d)\n", audiosize, frame_size, mode);
return -1;
} else {
frame_size = audiosize;
@@ -302,14 +302,11 @@
if (transition)
{
int plc_length, overlap;
- if (mode == MODE_CELT_ONLY)
- plc_length = IMIN(audiosize, 10+st->Fs/200);
- else
- plc_length = IMIN(audiosize, 10+st->Fs/400);
+ plc_length = IMIN(audiosize, 10+st->Fs/400);
for (i=0;i<plc_length;i++)
pcm[i] = pcm_transition[i];
- overlap = IMIN(st->Fs/100, IMAX(0, audiosize-plc_length));
+ overlap = IMIN(st->Fs/400, IMAX(0, audiosize-plc_length));
smooth_fade(pcm_transition+plc_length, pcm+plc_length, pcm+plc_length, overlap, st->channels);
}
#if OPUS_TEST_RANGE_CODER_STATE
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -124,8 +124,14 @@
celt_to_silk = (st->mode != MODE_CELT_ONLY);
if (!celt_to_silk)
{
- st->mode = st->prev_mode;
- to_celt = 1;
+ /* Switch to SILK/hybrid if frame size is 10 ms or more*/
+ if (frame_size >= st->Fs/100)
+ {
+ st->mode = st->prev_mode;
+ to_celt = 1;
+ } else {
+ redundancy=0;
+ }
}
}
@@ -230,12 +236,12 @@
celt_encoder_ctl(st->celt_enc, CELT_SET_BITRATE(510000));
if (st->prev_mode == MODE_SILK_ONLY)
{
- unsigned char dummy[2];
+ unsigned char dummy[10];
celt_encoder_ctl(st->celt_enc, CELT_RESET_STATE);
celt_encoder_ctl(st->celt_enc, CELT_SET_START_BAND(0));
celt_encoder_ctl(st->celt_enc, CELT_SET_PREDICTION(0));
/* FIXME: This wastes CPU a bit compared to just prefilling the buffer */
- celt_encode(st->celt_enc, &st->delay_buffer[(st->encoder_buffer-st->delay_compensation-120)*st->channels], 120, dummy, 10);
+ celt_encode(st->celt_enc, &st->delay_buffer[(st->encoder_buffer-st->delay_compensation-st->Fs/400)*st->channels], st->Fs/400, dummy, 10);
} else {
celt_encoder_ctl(st->celt_enc, CELT_SET_PREDICTION(2));
}