Fixes a few issues with PLC-based mode switching
This commit is contained in:
parent
0c0c5f940a
commit
1b16fec484
2 changed files with 13 additions and 10 deletions
|
@ -152,7 +152,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
|
|||
}
|
||||
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 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
|
|||
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);
|
||||
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
|
||||
|
|
|
@ -123,9 +123,15 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
|
|||
redundancy = 1;
|
||||
celt_to_silk = (st->mode != MODE_CELT_ONLY);
|
||||
if (!celt_to_silk)
|
||||
{
|
||||
/* 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 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
|
|||
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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue