Fixes a problem with the SILK toMono when we're encoding 40/60 ms frames
This commit is contained in:
parent
6e5f6d048a
commit
1e22a4b7e9
1 changed files with 28 additions and 18 deletions
|
@ -462,16 +462,17 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
else
|
else
|
||||||
voice_est = 64;
|
voice_est = 64;
|
||||||
|
|
||||||
|
if (st->force_channels!=OPUS_AUTO && st->channels == 2)
|
||||||
|
{
|
||||||
|
st->stream_channels = st->force_channels;
|
||||||
|
} else {
|
||||||
#ifdef FUZZING
|
#ifdef FUZZING
|
||||||
/* Random mono/stereo decision */
|
/* Random mono/stereo decision */
|
||||||
if (st->channels == 2 && (rand()&0x1F)==0)
|
if (st->channels == 2 && (rand()&0x1F)==0)
|
||||||
st->stream_channels = 3-st->stream_channels;
|
st->stream_channels = 3-st->stream_channels;
|
||||||
#else
|
#else
|
||||||
/* Rate-dependent mono-stereo decision */
|
/* Rate-dependent mono-stereo decision */
|
||||||
if (st->force_channels!=OPUS_AUTO && st->channels == 2)
|
if (st->channels == 2)
|
||||||
{
|
|
||||||
st->stream_channels = st->force_channels;
|
|
||||||
} else if (st->channels == 2)
|
|
||||||
{
|
{
|
||||||
opus_int32 stereo_threshold;
|
opus_int32 stereo_threshold;
|
||||||
stereo_threshold = stereo_music_threshold + ((voice_est*voice_est*(stereo_voice_threshold-stereo_music_threshold))>>14);
|
stereo_threshold = stereo_music_threshold + ((voice_est*voice_est*(stereo_voice_threshold-stereo_music_threshold))>>14);
|
||||||
|
@ -484,6 +485,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
st->stream_channels = st->channels;
|
st->stream_channels = st->channels;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0)
|
if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0)
|
||||||
{
|
{
|
||||||
|
@ -628,10 +630,11 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
VARDECL(unsigned char, tmp_data);
|
VARDECL(unsigned char, tmp_data);
|
||||||
VARDECL(unsigned char, rp_);
|
VARDECL(unsigned char, rp_);
|
||||||
int nb_frames;
|
int nb_frames;
|
||||||
int bak_mode, bak_bandwidth, bak_channels;
|
int bak_mode, bak_bandwidth, bak_channels, bak_to_mono;
|
||||||
OpusRepacketizer *rp;
|
OpusRepacketizer *rp;
|
||||||
int bytes_per_frame;
|
int bytes_per_frame;
|
||||||
|
|
||||||
|
|
||||||
nb_frames = frame_size > st->Fs/25 ? 3 : 2;
|
nb_frames = frame_size > st->Fs/25 ? 3 : 2;
|
||||||
bytes_per_frame = max_data_bytes/nb_frames-3;
|
bytes_per_frame = max_data_bytes/nb_frames-3;
|
||||||
|
|
||||||
|
@ -647,10 +650,16 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
st->user_forced_mode = st->mode;
|
st->user_forced_mode = st->mode;
|
||||||
st->user_bandwidth = st->bandwidth;
|
st->user_bandwidth = st->bandwidth;
|
||||||
st->force_channels = st->stream_channels;
|
st->force_channels = st->stream_channels;
|
||||||
|
bak_to_mono = st->silk_mode.toMono;
|
||||||
|
|
||||||
|
if (bak_to_mono)
|
||||||
|
st->force_channels = 1;
|
||||||
|
else
|
||||||
|
st->prev_channels = st->stream_channels;
|
||||||
for (i=0;i<nb_frames;i++)
|
for (i=0;i<nb_frames;i++)
|
||||||
{
|
{
|
||||||
int tmp_len;
|
int tmp_len;
|
||||||
|
st->silk_mode.toMono = 0;
|
||||||
tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data+i*bytes_per_frame, bytes_per_frame);
|
tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data+i*bytes_per_frame, bytes_per_frame);
|
||||||
ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len);
|
ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len);
|
||||||
}
|
}
|
||||||
|
@ -659,6 +668,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
|
||||||
st->user_forced_mode = bak_mode;
|
st->user_forced_mode = bak_mode;
|
||||||
st->user_bandwidth = bak_bandwidth;
|
st->user_bandwidth = bak_bandwidth;
|
||||||
st->force_channels = bak_channels;
|
st->force_channels = bak_channels;
|
||||||
|
st->silk_mode.toMono = bak_to_mono;
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue