Adding constrained VBR mode
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 14 Mar 2011 19:11:44 +0000 (15:11 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Mon, 14 Mar 2011 19:11:44 +0000 (15:11 -0400)
celt
src/opus.h
src/opus_encoder.c
src/opus_encoder.h
src/test_opus.c

diff --git a/celt b/celt
index 7c328c2..6f6e8b3 160000 (submodule)
--- a/celt
+++ b/celt
@@ -1 +1 @@
-Subproject commit 7c328c2d7a9bb28b837d935658ec05bfd7746aa6
+Subproject commit 6f6e8b39842a7d175e89f47e4d37ad5de8143ad2
index a3aed13..f3704a5 100644 (file)
@@ -125,6 +125,11 @@ extern "C" {
 #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;
 
index ae36b85..89b39eb 100644 (file)
@@ -360,6 +360,7 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
             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 {
@@ -616,6 +617,18 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
             *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:
             fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request);
             break;
index ce721eb..336b9a7 100644 (file)
@@ -51,6 +51,7 @@ struct OpusEncoder {
     /* Sampling rate (at the API level) */
     int          Fs;
     int          use_vbr;
+    int          vbr_constraint;
     int          bitrate_bps;
     int          encoder_buffer;
     int          delay_compensation;
index ccbe6fa..dceed53 100644 (file)
@@ -82,6 +82,7 @@ int main(int argc, char *argv[])
    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 @@ int main(int argc, char *argv[])
         } 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 @@ int main(int argc, char *argv[])
    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));