Skip to content
Snippets Groups Projects
Commit 81936d5f authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Properly take into account the frame size to decide the mode

parent 0c08a99a
No related branches found
No related tags found
No related merge requests found
......@@ -281,6 +281,12 @@ int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
st->mode = MODE_SILK_ONLY;
}
#endif
/* Override the chosen mode to make sure we meet the requested frame size */
if (st->mode == MODE_CELT_ONLY && frame_size > st->Fs/50)
st->mode = MODE_SILK_ONLY;
if (st->mode != MODE_CELT_ONLY && frame_size < st->Fs/100)
st->mode = MODE_CELT_ONLY;
if (st->prev_mode > 0 &&
((st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) ||
(st->mode == MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY)))
......@@ -348,20 +354,16 @@ int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
if (st->user_bandwidth != OPUS_BANDWIDTH_AUTO)
st->bandwidth = st->user_bandwidth;
/* Preventing nonsensical configurations, i.e. modes that don't exist */
/* Can't support higher than wideband for >20 ms frames */
if (frame_size > st->Fs/50 && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)
st->bandwidth = OPUS_BANDWIDTH_WIDEBAND;
/* Frame size < 10 ms */
if (frame_size < st->Fs/100 && st->mode != MODE_CELT_ONLY)
st->mode = MODE_CELT_ONLY;
/* Frame size > 20 ms */
if (50*frame_size > st->Fs)
{
st->mode = MODE_SILK_ONLY;
if (st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)
st->bandwidth = OPUS_BANDWIDTH_WIDEBAND;
}
/* CELT mode doesn't support mediumband, use wideband instead */
if (st->mode == MODE_CELT_ONLY && st->bandwidth == OPUS_BANDWIDTH_MEDIUMBAND)
st->bandwidth = OPUS_BANDWIDTH_WIDEBAND;
/* Chooses the appropriate mode for speech
*NEVER* switch to/from CELT-only mode here as this will */
if (st->mode == MODE_SILK_ONLY && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)
st->mode = MODE_HYBRID;
if (st->mode == MODE_HYBRID && st->bandwidth <= OPUS_BANDWIDTH_WIDEBAND)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment