shithub: opus

Download patch

ref: b55b66119bbce514a62f1a8dbcdce8abc667627d
parent: d8571e4b876f0381200b8a51d8dd0ec41bb56731
author: Jean-Marc Valin <[email protected]>
date: Mon Mar 14 11:11:44 EDT 2011

Adding constrained VBR mode

--- a/src/opus.h
+++ b/src/opus.h
@@ -125,6 +125,11 @@
 #define OPUS_GET_VOICE_RATIO_REQUEST 19
 #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __check_int_ptr(x)
 
+#define OPUS_SET_VBR_CONSTRAINT_REQUEST 20
+#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __check_int(x)
+#define OPUS_GET_VBR_CONSTRAINT_REQUEST 21
+#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __check_int_ptr(x)
+
 typedef struct OpusEncoder OpusEncoder;
 typedef struct OpusDecoder OpusDecoder;
 
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -360,6 +360,7 @@
             if (st->use_vbr)
             {
                 celt_encoder_ctl(st->celt_enc, CELT_SET_VBR(1));
+                celt_encoder_ctl(st->celt_enc, CELT_SET_VBR_CONSTRAINT(st->vbr_constraint));
                 celt_encoder_ctl(st->celt_enc, CELT_SET_BITRATE(st->bitrate_bps));
                 nb_compr_bytes = max_data_bytes-1;
             } else {
@@ -614,6 +615,18 @@
         {
             int *value = va_arg(ap, int*);
             *value = st->voice_ratio;
+        }
+        break;
+        case OPUS_SET_VBR_CONSTRAINT_REQUEST:
+        {
+            int value = va_arg(ap, int);
+            st->vbr_constraint = value;
+        }
+        break;
+        case OPUS_GET_VBR_CONSTRAINT_REQUEST:
+        {
+            int *value = va_arg(ap, int*);
+            *value = st->vbr_constraint;
         }
         break;
         default:
--- a/src/opus_encoder.h
+++ b/src/opus_encoder.h
@@ -51,6 +51,7 @@
     /* Sampling rate (at the API level) */
     int          Fs;
     int          use_vbr;
+    int          vbr_constraint;
     int          bitrate_bps;
     int          encoder_buffer;
     int          delay_compensation;
--- a/src/test_opus.c
+++ b/src/test_opus.c
@@ -82,6 +82,7 @@
    int complexity;
    int use_inbandfec;
    int use_dtx;
+   int cvbr = 0;
    int packet_loss_perc;
    int count=0, count_act=0, k;
    int skip;
@@ -169,6 +170,9 @@
         } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandfec" ) == 0 ) {
             use_inbandfec = 1;
             args++;
+        } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-cvbr" ) == 0 ) {
+            cvbr = 1;
+            args++;
         } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-dtx") == 0 ) {
             use_dtx = 1;
             args++;
@@ -222,6 +226,7 @@
    opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps));
    opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bandwidth));
    opus_encoder_ctl(enc, OPUS_SET_VBR_FLAG(use_vbr));
+   opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(cvbr));
    opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
    opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC_FLAG(use_inbandfec));
    opus_encoder_ctl(enc, OPUS_SET_DTX_FLAG(use_dtx));