Commit b6f90613 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

celt_encoder_ctl() is a bit more type-safe.

parent 25ec9ac3
......@@ -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,24 +719,34 @@ int celt_encode(CELTEncoder * restrict st, const celt_int16_t * pcm, celt_int16_
}
#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;
}
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;
}
/****************************************************************************/
......
......@@ -51,6 +51,8 @@ extern "C" {
#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 @@ extern "C" {
/** 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 @@ EXPORT int celt_encode(CELTEncoder *st, const celt_int16_t *pcm, celt_int16_t *o
@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 */
......
......@@ -69,7 +69,7 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32_t *value)
*value = CELT_BITSTREAM_VERSION;
break;
default:
return CELT_BAD_REQUEST;
return CELT_UNIMPLEMENTED;
}
return CELT_OK;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment