shithub: opus

Download patch

ref: b6f906134349949daf9eb18e465bb9c81d88e592
parent: 25ec9ac39aee6544e8347aec342443cb96fc37c9
author: Jean-Marc Valin <[email protected]>
date: Sun Oct 5 18:39:13 EDT 2008

celt_encoder_ctl() is a bit more type-safe.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -51,6 +51,7 @@
 #include "stack_alloc.h"
 #include "mathops.h"
 #include "float_cast.h"
+#include <stdarg.h>
 
 static const celt_word16_t preemph = QCONST16(0.8f,15);
 
@@ -718,15 +719,18 @@
 }
 #endif
 
-int celt_encoder_ctl(CELTEncoder * restrict st, int request, celt_int32_t *value)
+int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...)
 {
+   va_list ap;
+   va_start(ap, request);
    switch (request)
    {
-      case CELT_SET_COMPLEXITY:
+      case CELT_SET_COMPLEXITY_REQUEST:
       {
-         if (*value<0 || *value>10)
-            return CELT_BAD_ARG;
-         if (*value<=2)
+         int value = va_arg(ap, int);
+         if (value<0 || value>10)
+            goto bad_arg;
+         if (value<=2)
             st->pitch_enabled = 0;
          else
             st->pitch_enabled = 1;
@@ -733,9 +737,16 @@
       }
       break;
       default:
-         return CELT_BAD_REQUEST;
+         goto bad_request;
    }
+   va_end(ap);
    return CELT_OK;
+bad_arg:
+   va_end(ap);
+   return CELT_BAD_ARG;
+bad_request:
+   va_end(ap);
+   return CELT_UNIMPLEMENTED;
 }
 
 /****************************************************************************/
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -51,6 +51,8 @@
 #define EXPORT
 #endif
 
+#define _celt_check_int(x) (((void)((x) == (int)0)), (int)(x))
+
 /* Error codes */
 /** No error */
 #define CELT_OK                0
@@ -63,10 +65,12 @@
 /** The data passed (e.g. compressed data to decoder) is corrupted */
 #define CELT_CORRUPTED_DATA   -4
 /** Invalid/unsupported request number */
-#define CELT_BAD_REQUEST      -5
+#define CELT_UNIMPLEMENTED    -5
 
 /* Requests */
-#define CELT_SET_COMPLEXITY    0
+/** Controls the complexity from 0-10 (int) */
+#define CELT_SET_COMPLEXITY_REQUEST    2
+#define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
 
 /** GET the frame size used in the current mode */
 #define CELT_GET_FRAME_SIZE   1000
@@ -161,7 +165,7 @@
  @param value Pointer to a 32-bit int value
  @return Error code
 */
-EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, celt_int32_t *value);
+EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...);
 
 /* Decoder stuff */
 
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -69,7 +69,7 @@
          *value = CELT_BITSTREAM_VERSION;
          break;
       default:
-         return CELT_BAD_REQUEST;
+         return CELT_UNIMPLEMENTED;
    }
    return CELT_OK;
 }