Taking into account the frame size in more encoder decisions

Stereo mode, stereo width, min bandwidth, VBR damping
This commit is contained in:
Jean-Marc Valin 2013-11-08 19:24:10 -05:00
parent 9ffce06c77
commit c1959e7dc3
2 changed files with 16 additions and 12 deletions

View file

@ -1295,6 +1295,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
opus_val16 surround_masking=0;
opus_val16 temporal_vbr=0;
opus_val16 surround_trim = 0;
opus_int32 equiv_rate = 510000;
VARDECL(opus_val16, surround_dynalloc);
ALLOC_STACK;
@ -1376,6 +1377,8 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
(tmp+4*mode->Fs)/(8*mode->Fs)-!!st->signalling));
effectiveBytes = nbCompressedBytes;
}
if (st->bitrate != OPUS_BITRATE_MAX)
equiv_rate = st->bitrate - (40*C+20)*((400>>LM) - 50);
if (enc==NULL)
{
@ -1830,7 +1833,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
if (st->constrained_vbr)
base_target += (st->vbr_offset>>lm_diff);
target = compute_vbr(mode, &st->analysis, base_target, LM, st->bitrate,
target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate,
st->lastCodedBands, C, st->intensity, st->constrained_vbr,
st->stereo_saving, tot_boost, tf_estimate, pitch_change, maxDepth,
st->variable_duration, st->lfe, st->energy_mask!=NULL, surround_masking,
@ -1914,13 +1917,13 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
if (st->analysis.valid)
{
int min_bandwidth;
if (st->bitrate < (opus_int32)32000*C)
if (equiv_rate < (opus_int32)32000*C)
min_bandwidth = 13;
else if (st->bitrate < (opus_int32)48000*C)
else if (equiv_rate < (opus_int32)48000*C)
min_bandwidth = 16;
else if (st->bitrate < (opus_int32)60000*C)
else if (equiv_rate < (opus_int32)60000*C)
min_bandwidth = 18;
else if (st->bitrate < (opus_int32)80000*C)
else if (equiv_rate < (opus_int32)80000*C)
min_bandwidth = 19;
else
min_bandwidth = 20;

View file

@ -1099,7 +1099,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
max_rate = frame_rate*max_data_bytes*8;
/* Equivalent 20-ms rate for mode/channel/bandwidth decisions */
equiv_rate = st->bitrate_bps - 60*(st->Fs/frame_size - 50);
equiv_rate = st->bitrate_bps - (40*st->channels+20)*(st->Fs/frame_size - 50);
if (st->signal_type == OPUS_SIGNAL_VOICE)
voice_est = 127;
@ -1140,6 +1140,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
}
#endif
}
equiv_rate = st->bitrate_bps - (40*st->stream_channels+20)*(st->Fs/frame_size - 50);
/* Mode selection depending on application and signal type */
if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
@ -1329,7 +1330,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
if (st->Fs <= 8000 && st->bandwidth > OPUS_BANDWIDTH_NARROWBAND)
st->bandwidth = OPUS_BANDWIDTH_NARROWBAND;
#ifndef FIXED_POINT
#ifndef DISABLE_FLOAT_API
/* Use detected bandwidth to reduce the encoded bandwidth. */
if (st->detected_bandwidth && st->user_bandwidth == OPUS_AUTO)
{
@ -1338,13 +1339,13 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
gets it wrong when we could have coded a high bandwidth transparently.
When operating in SILK/hybrid mode, we don't go below wideband to avoid
more complicated switches that require redundancy. */
if (st->bitrate_bps <= 18000*st->stream_channels && st->mode == MODE_CELT_ONLY)
if (equiv_rate <= 18000*st->stream_channels && st->mode == MODE_CELT_ONLY)
min_detected_bandwidth = OPUS_BANDWIDTH_NARROWBAND;
else if (st->bitrate_bps <= 24000*st->stream_channels && st->mode == MODE_CELT_ONLY)
else if (equiv_rate <= 24000*st->stream_channels && st->mode == MODE_CELT_ONLY)
min_detected_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
else if (st->bitrate_bps <= 30000*st->stream_channels)
else if (equiv_rate <= 30000*st->stream_channels)
min_detected_bandwidth = OPUS_BANDWIDTH_WIDEBAND;
else if (st->bitrate_bps <= 44000*st->stream_channels)
else if (equiv_rate <= 44000*st->stream_channels)
min_detected_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
else
min_detected_bandwidth = OPUS_BANDWIDTH_FULLBAND;
@ -1765,7 +1766,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
}
st->prev_HB_gain = HB_gain;
if (st->mode != MODE_HYBRID || st->stream_channels==1)
st->silk_mode.stereoWidth_Q14 = IMIN((1<<14),IMAX(0,st->bitrate_bps-32000));
st->silk_mode.stereoWidth_Q14 = IMIN((1<<14),IMAX(0,equiv_rate-32000));
if( !st->energy_masking && 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) ) {