shithub: opus

Download patch

ref: 663a7fe938b3e211ecef57966a14df0d1c9a03f5
parent: 018b0df9c93cb8907f34d028f16a9000f876f66a
author: Jean-Marc Valin <[email protected]>
date: Tue Sep 6 10:05:19 EDT 2011

Defining OPUS_BITRATE_MAX and moving some defines to opus_defines.h

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -250,7 +250,7 @@
    st->constrained_vbr = 1;
    st->clip = 1;
 
-   st->bitrate = -1;
+   st->bitrate = OPUS_BITRATE_MAX;
    st->vbr = 0;
    st->vbr_offset = 0;
    st->force_intra  = 0;
@@ -970,7 +970,7 @@
    nbCompressedBytes = IMIN(nbCompressedBytes,1275);
    nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
 
-   if (st->vbr && st->bitrate!=-1)
+   if (st->vbr && st->bitrate!=OPUS_BITRATE_MAX)
    {
       opus_int32 den=st->mode->Fs>>BITRES;
       vbr_rate=(st->bitrate*frame_size+(den>>1))/den;
@@ -983,7 +983,7 @@
       tmp = st->bitrate*frame_size;
       if (tell>1)
          tmp += tell;
-      if (st->bitrate!=-1)
+      if (st->bitrate!=OPUS_BITRATE_MAX)
          nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes,
                (tmp+4*st->mode->Fs)/(8*st->mode->Fs)-!!st->signalling));
       effectiveBytes = nbCompressedBytes;
@@ -1783,7 +1783,7 @@
       case OPUS_SET_BITRATE_REQUEST:
       {
          opus_int32 value = va_arg(ap, opus_int32);
-         if (value<=500 && value!=-1)
+         if (value<=500 && value!=OPUS_BITRATE_MAX)
             goto bad_arg;
          value = IMIN(value, 260000*st->channels);
          st->bitrate = value;
--- a/libcelt/opus_defines.h
+++ b/libcelt/opus_defines.h
@@ -75,7 +75,24 @@
 #define OPUS_ALLOC_FAIL       -7
 
 
+#define OPUS_BITRATE_AUTO       -2
+#define OPUS_BITRATE_MAX       -1
 
+#define OPUS_APPLICATION_VOIP        2000
+#define OPUS_APPLICATION_AUDIO       2001
+
+#define OPUS_SIGNAL_AUTO             3000
+#define OPUS_SIGNAL_VOICE            3001
+#define OPUS_SIGNAL_MUSIC            3002
+
+#define OPUS_BANDWIDTH_AUTO          1100
+#define OPUS_BANDWIDTH_NARROWBAND    1101
+#define OPUS_BANDWIDTH_MEDIUMBAND    1102
+#define OPUS_BANDWIDTH_WIDEBAND      1103
+#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104
+#define OPUS_BANDWIDTH_FULLBAND      1105
+
+
 /* OPUS_APPLICATION_VOIP or OPUS_APPLICATION_AUDIO */
 #define OPUS_SET_APPLICATION_REQUEST 4000
 #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
@@ -146,7 +163,7 @@
 
 /* For testing purposes: the encoder and decoder state should
    always be identical after coding a payload */
-#define OPUS_GET_FINAL_RANGE_REQUEST 29
+#define OPUS_GET_FINAL_RANGE_REQUEST 4031
 #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
 
 
--- a/src/opus.h
+++ b/src/opus.h
@@ -36,21 +36,6 @@
 #endif
 
 
-#define OPUS_BITRATE_AUTO       -1
-
-#define OPUS_APPLICATION_VOIP        2000
-#define OPUS_APPLICATION_AUDIO       2001
-
-#define OPUS_SIGNAL_AUTO             3000
-#define OPUS_SIGNAL_VOICE            3001
-#define OPUS_SIGNAL_MUSIC            3002
-
-#define OPUS_BANDWIDTH_AUTO          1100
-#define OPUS_BANDWIDTH_NARROWBAND    1101
-#define OPUS_BANDWIDTH_MEDIUMBAND    1102
-#define OPUS_BANDWIDTH_WIDEBAND      1103
-#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104
-#define OPUS_BANDWIDTH_FULLBAND      1105
 
 
 
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -383,6 +383,8 @@
 
     if (st->user_bitrate_bps==OPUS_BITRATE_AUTO)
         st->bitrate_bps = 60*st->Fs/frame_size + st->Fs*st->channels;
+    else if (st->user_bitrate_bps==OPUS_BITRATE_MAX)
+       st->bitrate_bps = max_data_bytes*8*st->Fs/frame_size;
     else
         st->bitrate_bps = st->user_bitrate_bps;
 
@@ -718,7 +720,7 @@
     if (st->mode != MODE_SILK_ONLY)
     {
         celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0));
-        celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(-1));
+        celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX));
         if (st->prev_mode == MODE_SILK_ONLY)
         {
             unsigned char dummy[10];
@@ -948,7 +950,7 @@
         case OPUS_SET_BITRATE_REQUEST:
         {
             opus_int32 value = va_arg(ap, opus_int32);
-            if (value != OPUS_BITRATE_AUTO)
+            if (value != OPUS_BITRATE_AUTO && value != OPUS_BITRATE_MAX)
             {
                 if (value <= 0)
                     goto bad_arg;