celt_encoder_ctl() is a bit more type-safe.

This commit is contained in:
Jean-Marc Valin 2008-10-05 22:39:13 -04:00
parent 25ec9ac39a
commit b6f9061343
3 changed files with 25 additions and 10 deletions

View file

@ -51,6 +51,7 @@
#include "stack_alloc.h" #include "stack_alloc.h"
#include "mathops.h" #include "mathops.h"
#include "float_cast.h" #include "float_cast.h"
#include <stdarg.h>
static const celt_word16_t preemph = QCONST16(0.8f,15); static const celt_word16_t preemph = QCONST16(0.8f,15);
@ -718,24 +719,34 @@ int celt_encode(CELTEncoder * restrict st, const celt_int16_t * pcm, celt_int16_
} }
#endif #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) switch (request)
{ {
case CELT_SET_COMPLEXITY: case CELT_SET_COMPLEXITY_REQUEST:
{ {
if (*value<0 || *value>10) int value = va_arg(ap, int);
return CELT_BAD_ARG; if (value<0 || value>10)
if (*value<=2) goto bad_arg;
if (value<=2)
st->pitch_enabled = 0; st->pitch_enabled = 0;
else else
st->pitch_enabled = 1; st->pitch_enabled = 1;
} }
break; break;
default: default:
return CELT_BAD_REQUEST; goto bad_request;
} }
va_end(ap);
return CELT_OK; return CELT_OK;
bad_arg:
va_end(ap);
return CELT_BAD_ARG;
bad_request:
va_end(ap);
return CELT_UNIMPLEMENTED;
} }
/****************************************************************************/ /****************************************************************************/

View file

@ -51,6 +51,8 @@ extern "C" {
#define EXPORT #define EXPORT
#endif #endif
#define _celt_check_int(x) (((void)((x) == (int)0)), (int)(x))
/* Error codes */ /* Error codes */
/** No error */ /** No error */
#define CELT_OK 0 #define CELT_OK 0
@ -63,10 +65,12 @@ extern "C" {
/** The data passed (e.g. compressed data to decoder) is corrupted */ /** The data passed (e.g. compressed data to decoder) is corrupted */
#define CELT_CORRUPTED_DATA -4 #define CELT_CORRUPTED_DATA -4
/** Invalid/unsupported request number */ /** Invalid/unsupported request number */
#define CELT_BAD_REQUEST -5 #define CELT_UNIMPLEMENTED -5
/* Requests */ /* 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 */ /** GET the frame size used in the current mode */
#define CELT_GET_FRAME_SIZE 1000 #define CELT_GET_FRAME_SIZE 1000
@ -161,7 +165,7 @@ EXPORT int celt_encode(CELTEncoder *st, const celt_int16_t *pcm, celt_int16_t *o
@param value Pointer to a 32-bit int value @param value Pointer to a 32-bit int value
@return Error code @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 */ /* Decoder stuff */

View file

@ -69,7 +69,7 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *value)
*value = CELT_BITSTREAM_VERSION; *value = CELT_BITSTREAM_VERSION;
break; break;
default: default:
return CELT_BAD_REQUEST; return CELT_UNIMPLEMENTED;
} }
return CELT_OK; return CELT_OK;
} }