shithub: opus

Download patch

ref: c1959e7dc346fac747ca29efa63ff2a6ddb44f44
parent: 9ffce06c773b53e4d509420227df7bd88e0f2e74
author: Jean-Marc Valin <[email protected]>
date: Fri Nov 8 14:24:10 EST 2013

Taking into account the frame size in more encoder decisions

Stereo mode, stereo width, min bandwidth, VBR damping

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1295,6 +1295,7 @@
    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 @@
                (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 @@
      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 @@
    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;
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1099,7 +1099,7 @@
     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 @@
        }
 #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 @@
         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 @@
           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 @@
     }
     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) ) {