shithub: opus

Download patch

ref: b3c9e79a8291e85c0cd5f91b55d1e856edd95ac1
parent: 2b011b64d8ca5f3f7b26806aeb77939ff7703c06
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue Jun 21 09:37:29 EDT 2016

Tune SILK rate for hybrid with FEC enabled

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -984,7 +984,7 @@
    return 0;
 }
 
-static int compute_silk_rate_for_hybrid(int rate, int bandwidth, int frame20ms, int vbr) {
+static int compute_silk_rate_for_hybrid(int rate, int bandwidth, int frame20ms, int vbr, int fec) {
    int entry;
    int i;
    int N;
@@ -991,16 +991,17 @@
    int silk_rate;
    static int rate_table[][5] = {
   /*  |total| |-------- SILK------------|
-              SWB-10  FB-10 SWB-20  FB-20 */
+              |-- No FEC -| |--- FEC ---|
+               10ms   20ms   10ms   20ms */
       {    0,     0,     0,     0,     0},
-      {12000, 10000, 10000, 10000, 10000},
-      {16000, 14000, 14000, 14000, 13500},
-      {20000, 16000, 16000, 16000, 16000},
-      {24000, 18000, 18000, 18000, 18000},
-      {32000, 22000, 22000, 22000, 22000},
-      {64000, 38000, 38000, 38000, 38000}
+      {12000, 10000, 10000, 11000, 11000},
+      {16000, 13500, 13500, 15000, 15000},
+      {20000, 16000, 16000, 18000, 18000},
+      {24000, 18000, 18000, 21000, 21000},
+      {32000, 22000, 22000, 28000, 28000},
+      {64000, 38000, 38000, 50000, 50000}
    };
-   entry = 1 + 2*frame20ms + (bandwidth==OPUS_BANDWIDTH_FULLBAND);
+   entry = 1 + frame20ms + 2*fec;
    N = sizeof(rate_table)/sizeof(rate_table[0]);
    for (i=1;i<N;i++)
    {
@@ -1024,6 +1025,8 @@
       /* Tiny boost to SILK for CBR. We should probably tune this better. */
       silk_rate += 100;
    }
+   if (bandwidth==OPUS_BANDWIDTH_SUPERWIDEBAND)
+      silk_rate += 300;
    return silk_rate;
 }
 
@@ -1741,7 +1744,7 @@
         if( st->mode == MODE_HYBRID ) {
             /* Base rate for SILK */
             st->silk_mode.bitRate = compute_silk_rate_for_hybrid(total_bitRate,
-                  curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr);
+                  curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded);
             if (!st->energy_masking)
             {
                /* Increasingly attenuate high band when it gets allocated fewer bits */
@@ -1850,7 +1853,7 @@
            {
               /* Compute SILK bitrate corresponding to the max total bits available */
               opus_int32 maxBitRate = compute_silk_rate_for_hybrid(nBytes*8*st->Fs / frame_size,
-                    curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr);
+                    curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded);
               st->silk_mode.maxBits = maxBitRate * frame_size / st->Fs;
            }
         }