ref: f9e701ad2411b44c8689171ceb4091871574376c
parent: 875f8dbd56e303985a69ab9b4e0c7cf840741afa
author: Jean-Marc Valin <[email protected]>
date: Wed Aug 31 13:47:48 EDT 2011
Sharing more macros between the Opus code and the CELT low-level code
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -203,7 +203,7 @@
CELTEncoder *st = (CELTEncoder *)opus_alloc(celt_encoder_get_size_custom(mode, channels));
/* init will handle the NULL case */
ret = celt_encoder_init_custom(st, mode, channels);
- if (ret != CELT_OK)
+ if (ret != OPUS_OK)
{
celt_encoder_destroy(st);
st = NULL;
@@ -217,22 +217,22 @@
{
int ret;
ret = celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels);
- if (ret != CELT_OK)
+ if (ret != OPUS_OK)
return ret;
st->upsample = resampling_factor(sampling_rate);
if (st->upsample==0)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
else
- return CELT_OK;
+ return OPUS_OK;
}
int celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels)
{
if (channels < 0 || channels > 2)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
if (st==NULL || mode==NULL)
- return CELT_ALLOC_FAIL;
+ return OPUS_ALLOC_FAIL;
OPUS_CLEAR((char*)st, celt_encoder_get_size_custom(mode, channels));
@@ -259,7 +259,7 @@
st->tapset_decision = 0;
st->complexity = 5;
- return CELT_OK;
+ return OPUS_OK;
}
void celt_encoder_destroy(CELTEncoder *st)
@@ -919,7 +919,7 @@
ALLOC_STACK;
if (nbCompressedBytes<2 || pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
frame_size *= st->upsample;
for (LM=0;LM<=st->mode->maxLM;LM++)
@@ -926,7 +926,7 @@
if (st->mode->shortMdctSize<<LM==frame_size)
break;
if (LM>st->mode->maxLM)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
M=1<<LM;
N = M*st->mode->shortMdctSize;
@@ -956,7 +956,7 @@
{
int c0 = toOpus(compressed[0]);
if (c0<0)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
compressed[0] = c0;
}
compressed++;
@@ -1641,7 +1641,7 @@
RESTORE_STACK;
if (ec_get_error(enc))
- return CELT_INTERNAL_ERROR;
+ return OPUS_INTERNAL_ERROR;
else
return nbCompressedBytes;
}
@@ -1662,7 +1662,7 @@
ALLOC_STACK;
if (pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
C = CHANNELS(st->channels);
N = frame_size;
@@ -1689,7 +1689,7 @@
ALLOC_STACK;
if (pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
C=CHANNELS(st->channels);
N=frame_size;
@@ -1721,7 +1721,7 @@
va_start(ap, request);
switch (request)
{
- case CELT_SET_COMPLEXITY_REQUEST:
+ case OPUS_SET_COMPLEXITY_REQUEST:
{
int value = va_arg(ap, opus_int32);
if (value<0 || value>10)
@@ -1754,7 +1754,7 @@
st->force_intra = value==0;
}
break;
- case CELT_SET_LOSS_PERC_REQUEST:
+ case OPUS_SET_PACKET_LOSS_PERC_REQUEST:
{
int value = va_arg(ap, opus_int32);
if (value<0 || value>100)
@@ -1762,19 +1762,19 @@
st->loss_rate = value;
}
break;
- case CELT_SET_VBR_CONSTRAINT_REQUEST:
+ case OPUS_SET_VBR_CONSTRAINT_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
st->constrained_vbr = value;
}
break;
- case CELT_SET_VBR_REQUEST:
+ case OPUS_SET_VBR_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
st->vbr = value;
}
break;
- case CELT_SET_BITRATE_REQUEST:
+ case OPUS_SET_BITRATE_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if (value<=500 && value!=-1)
@@ -1791,7 +1791,7 @@
st->stream_channels = value;
}
break;
- case CELT_RESET_STATE:
+ case OPUS_RESET_STATE:
{
OPUS_CLEAR((char*)&st->ENCODER_RESET_START,
celt_encoder_get_size_custom(st->mode, st->channels)-
@@ -1823,7 +1823,7 @@
*value=st->mode;
}
break;
- case CELT_GET_RANGE_REQUEST:
+ case OPUS_GET_FINAL_RANGE_REQUEST:
{
opus_uint32 * value = va_arg(ap, opus_uint32 *);
if (value==0)
@@ -1836,13 +1836,13 @@
goto bad_request;
}
va_end(ap);
- return CELT_OK;
+ return OPUS_OK;
bad_arg:
va_end(ap);
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
bad_request:
va_end(ap);
- return CELT_UNIMPLEMENTED;
+ return OPUS_UNIMPLEMENTED;
}
/**********************************************************************/
@@ -1909,7 +1909,7 @@
int ret;
CELTDecoder *st = (CELTDecoder *)opus_alloc(celt_decoder_get_size_custom(mode, channels));
ret = celt_decoder_init_custom(st, mode, channels);
- if (ret != CELT_OK)
+ if (ret != OPUS_OK)
{
celt_decoder_destroy(st);
st = NULL;
@@ -1923,22 +1923,22 @@
{
int ret;
ret = celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels);
- if (ret != CELT_OK)
+ if (ret != OPUS_OK)
return ret;
st->downsample = resampling_factor(sampling_rate);
if (st->downsample==0)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
else
- return CELT_OK;
+ return OPUS_OK;
}
int celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels)
{
if (channels < 0 || channels > 2)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
if (st==NULL)
- return CELT_ALLOC_FAIL;
+ return OPUS_ALLOC_FAIL;
OPUS_CLEAR((char*)st, celt_decoder_get_size_custom(mode, channels));
@@ -1953,7 +1953,7 @@
st->loss_count = 0;
- return CELT_OK;
+ return OPUS_OK;
}
void celt_decoder_destroy(CELTDecoder *st)
@@ -2280,7 +2280,7 @@
{
data0 = fromOpus(data0);
if (data0<0)
- return CELT_CORRUPTED_DATA;
+ return OPUS_CORRUPTED_DATA;
}
st->end = IMAX(1, st->mode->effEBands-2*(data0>>5));
LM = (data0>>3)&0x3;
@@ -2288,9 +2288,9 @@
data++;
len--;
if (LM>st->mode->maxLM)
- return CELT_CORRUPTED_DATA;
+ return OPUS_CORRUPTED_DATA;
if (frame_size < st->mode->shortMdctSize<<LM)
- return CELT_BUFFER_TOO_SMALL;
+ return OPUS_BUFFER_TOO_SMALL;
else
frame_size = st->mode->shortMdctSize<<LM;
} else {
@@ -2298,12 +2298,12 @@
if (st->mode->shortMdctSize<<LM==frame_size)
break;
if (LM>st->mode->maxLM)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
}
M=1<<LM;
if (len<0 || len>1275 || pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
N = M*st->mode->shortMdctSize;
@@ -2575,7 +2575,7 @@
st->loss_count = 0;
RESTORE_STACK;
if (ec_tell(dec) > 8*len)
- return CELT_INTERNAL_ERROR;
+ return OPUS_INTERNAL_ERROR;
if(ec_get_error(dec))
st->error = 1;
return frame_size/st->downsample;
@@ -2597,7 +2597,7 @@
ALLOC_STACK;
if (pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
C = CHANNELS(st->channels);
N = frame_size;
@@ -2627,7 +2627,7 @@
ALLOC_STACK;
if (pcm==NULL)
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
C = CHANNELS(st->channels);
N = frame_size;
@@ -2686,7 +2686,7 @@
st->error = 0;
}
break;
- case CELT_GET_LOOKAHEAD_REQUEST:
+ case OPUS_GET_LOOKAHEAD_REQUEST:
{
int *value = va_arg(ap, int*);
if (value==NULL)
@@ -2694,7 +2694,7 @@
*value = st->overlap/st->downsample;
}
break;
- case CELT_RESET_STATE:
+ case OPUS_RESET_STATE:
{
OPUS_CLEAR((char*)&st->DECODER_RESET_START,
celt_decoder_get_size_custom(st->mode, st->channels)-
@@ -2716,7 +2716,7 @@
st->signalling = value;
}
break;
- case CELT_GET_RANGE_REQUEST:
+ case OPUS_GET_FINAL_RANGE_REQUEST:
{
opus_uint32 * value = va_arg(ap, opus_uint32 *);
if (value==0)
@@ -2729,13 +2729,13 @@
goto bad_request;
}
va_end(ap);
- return CELT_OK;
+ return OPUS_OK;
bad_arg:
va_end(ap);
- return CELT_BAD_ARG;
+ return OPUS_BAD_ARG;
bad_request:
va_end(ap);
- return CELT_UNIMPLEMENTED;
+ return OPUS_UNIMPLEMENTED;
}
const char *celt_strerror(int error)
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -36,6 +36,7 @@
#define CELT_H
#include "opus_types.h"
+#include "opus_defines.h"
#ifdef __cplusplus
extern "C" {
@@ -49,81 +50,35 @@
#define CELT_EXPORT
#endif
-#define _celt_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
-#define _celt_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
-#define _celt_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
-/* Error codes */
-/** No error */
-#define CELT_OK 0
-/** An (or more) invalid argument (e.g. out of range) */
-#define CELT_BAD_ARG -1
-/** The mode struct passed is invalid */
-#define CELT_BUFFER_TOO_SMALL -2
-/** An internal error was detected */
-#define CELT_INTERNAL_ERROR -3
-/** The data passed (e.g. compressed data to decoder) is corrupted */
-#define CELT_CORRUPTED_DATA -4
-/** Invalid/unsupported request number */
-#define CELT_UNIMPLEMENTED -5
-/** An encoder or decoder structure is invalid or already freed */
-#define CELT_INVALID_STATE -6
-/** Memory allocation has failed */
-#define CELT_ALLOC_FAIL -7
-
/* Encoder/decoder Requests */
-#define CELT_SET_COMPLEXITY_REQUEST 2
-/** Controls the complexity from 0-10 (int) */
-#define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
-
-#define CELT_SET_PREDICTION_REQUEST 4
+#define CELT_SET_PREDICTION_REQUEST 3002
/** Controls the use of interframe prediction.
0=Independent frames
1=Short term interframe prediction allowed
2=Long term prediction allowed
*/
-#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int(x)
+#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x)
-#define CELT_SET_BITRATE_REQUEST 6
-/** Set the target VBR rate in bits per second(int); 0=CBR (default) */
-#define CELT_SET_BITRATE(x) CELT_SET_BITRATE_REQUEST, _celt_check_int(x)
+#define CELT_SET_INPUT_CLIPPING_REQUEST 3004
+#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x)
-#define CELT_RESET_STATE_REQUEST 8
-/** Reset the encoder/decoder memories to zero*/
-#define CELT_RESET_STATE CELT_RESET_STATE_REQUEST
+#define CELT_GET_AND_CLEAR_ERROR_REQUEST 3005
+#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x)
-#define CELT_SET_VBR_CONSTRAINT_REQUEST 10
-#define CELT_SET_VBR_CONSTRAINT(x) CELT_SET_VBR_CONSTRAINT_REQUEST, _celt_check_int(x)
+#define CELT_SET_CHANNELS_REQUEST 3008
+#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x)
-#define CELT_SET_VBR_REQUEST 12
-#define CELT_SET_VBR(x) CELT_SET_VBR_REQUEST, _celt_check_int(x)
-#define CELT_SET_INPUT_CLIPPING_REQUEST 14
-#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x)
-
-#define CELT_GET_AND_CLEAR_ERROR_REQUEST 15
-#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, _celt_check_int_ptr(x)
-
-#define CELT_GET_LOOKAHEAD_REQUEST 17
-#define CELT_GET_LOOKAHEAD(x) CELT_GET_LOOKAHEAD_REQUEST, _celt_check_int_ptr(x)
-
-#define CELT_SET_CHANNELS_REQUEST 18
-#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, _celt_check_int(x)
-
-#define CELT_SET_LOSS_PERC_REQUEST 20
-#define CELT_SET_LOSS_PERC(x) CELT_SET_LOSS_PERC_REQUEST, _celt_check_int(x)
-
/* Internal */
#define CELT_SET_START_BAND_REQUEST 10000
-#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
+#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x)
#define CELT_SET_END_BAND_REQUEST 10001
-#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, _celt_check_int(x)
+#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x)
-#define CELT_GET_RANGE_REQUEST 10002
-#define CELT_GET_RANGE(x) CELT_GET_RANGE_REQUEST, _celt_check_uint_ptr(x)
/** Contains the state of an encoder. One encoder state is needed
for each stream. It is initialised once at the beginning of the
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -246,7 +246,7 @@
(frame_size<<j) == static_mode_list[i]->shortMdctSize*static_mode_list[i]->nbShortMdcts)
{
if (error)
- *error = CELT_OK;
+ *error = OPUS_OK;
return (CELTMode*)static_mode_list[i];
}
}
@@ -255,7 +255,7 @@
#ifndef CUSTOM_MODES
if (error)
- *error = CELT_BAD_ARG;
+ *error = OPUS_BAD_ARG;
return NULL;
#else
@@ -264,13 +264,13 @@
if (Fs < 8000 || Fs > 96000)
{
if (error)
- *error = CELT_BAD_ARG;
+ *error = OPUS_BAD_ARG;
return NULL;
}
if (frame_size < 40 || frame_size > 1024 || frame_size%2!=0)
{
if (error)
- *error = CELT_BAD_ARG;
+ *error = OPUS_BAD_ARG;
return NULL;
}
/* Frames of less than 1ms are not supported. */
@@ -277,7 +277,7 @@
if ((opus_int32)frame_size*1000 < Fs)
{
if (error)
- *error = CELT_BAD_ARG;
+ *error = OPUS_BAD_ARG;
return NULL;
}
@@ -299,7 +299,7 @@
if ((opus_int32)(frame_size>>LM)*300 > Fs)
{
if (error)
- *error = CELT_BAD_ARG;
+ *error = OPUS_BAD_ARG;
return NULL;
}
@@ -385,12 +385,12 @@
goto failure;
if (error)
- *error = CELT_OK;
+ *error = OPUS_OK;
return mode;
failure:
if (error)
- *error = CELT_ALLOC_FAIL;
+ *error = OPUS_ALLOC_FAIL;
if (mode!=NULL)
celt_mode_destroy(mode);
return NULL;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -95,7 +95,7 @@
#ifdef OPUS_BUILD
#define CELT_SET_SIGNALLING_REQUEST 10003
-#define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, _celt_check_int(x)
+#define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x)
#define CELT_GET_MODE_REQUEST 10004
/** Get the CELTMode used by an encoder or decoder */
--- /dev/null
+++ b/libcelt/opus_defines.h
@@ -1,0 +1,157 @@
+/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
+ Written by Jean-Marc Valin and Koen Vos */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef OPUS_DEFINES_H
+#define OPUS_DEFINES_H
+
+#include "opus_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(__GNUC__) && defined(OPUS_BUILD)
+
+# define OPUS_EXPORT __attribute__ ((visibility ("default")))
+
+#elif defined(WIN32)
+
+# ifdef OPUS_BUILD
+# define OPUS_EXPORT __declspec(dllexport)
+# else
+# define OPUS_EXPORT __declspec(dllimport)
+# endif
+
+#else
+
+# define OPUS_EXPORT
+
+#endif
+
+#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
+#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
+#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
+
+/* Error codes */
+/** No error */
+#define OPUS_OK 0
+/** An (or more) invalid argument (e.g. out of range) */
+#define OPUS_BAD_ARG -1
+/** The mode struct passed is invalid */
+#define OPUS_BUFFER_TOO_SMALL -2
+/** An internal error was detected */
+#define OPUS_INTERNAL_ERROR -3
+/** The data passed (e.g. compressed data to decoder) is corrupted */
+#define OPUS_CORRUPTED_DATA -4
+/** Invalid/unsupported request number */
+#define OPUS_UNIMPLEMENTED -5
+/** An encoder or decoder structure is invalid or already freed */
+#define OPUS_INVALID_STATE -6
+/** Memory allocation has failed */
+#define OPUS_ALLOC_FAIL -7
+
+
+
+/* OPUS_APPLICATION_VOIP or OPUS_APPLICATION_AUDIO */
+#define OPUS_SET_APPLICATION_REQUEST 0
+#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
+#define OPUS_GET_APPLICATION_REQUEST 1
+#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
+
+/* Coding bit-rate in bit/second */
+#define OPUS_SET_BITRATE_REQUEST 2
+#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
+#define OPUS_GET_BITRATE_REQUEST 3
+#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
+
+/* 0 for CBR, 1 for VBR */
+#define OPUS_SET_VBR_REQUEST 6
+#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
+#define OPUS_GET_VBR_REQUEST 7
+#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_BANDWIDTH_REQUEST 8
+#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
+#define OPUS_GET_BANDWIDTH_REQUEST 9
+#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_COMPLEXITY_REQUEST 10
+#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
+#define OPUS_GET_COMPLEXITY_REQUEST 11
+#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_INBAND_FEC_REQUEST 12
+#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
+#define OPUS_GET_INBAND_FEC_REQUEST 13
+#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 14
+#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
+#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 15
+#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_DTX_REQUEST 16
+#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
+#define OPUS_GET_DTX_REQUEST 17
+#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_VOICE_RATIO_REQUEST 18
+#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
+#define OPUS_GET_VOICE_RATIO_REQUEST 19
+#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_VBR_CONSTRAINT_REQUEST 20
+#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
+#define OPUS_GET_VBR_CONSTRAINT_REQUEST 21
+#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_FORCE_MONO_REQUEST 22
+#define OPUS_SET_FORCE_MONO(x) OPUS_SET_FORCE_MONO_REQUEST, __opus_check_int(x)
+#define OPUS_GET_FORCE_MONO_REQUEST 23
+#define OPUS_GET_FORCE_MONO(x) OPUS_GET_FORCE_MONO_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_SET_SIGNAL_REQUEST 24
+#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
+#define OPUS_GET_SIGNAL_REQUEST 25
+#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_GET_LOOKAHEAD_REQUEST 27
+#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
+
+#define OPUS_RESET_STATE 28
+
+/* 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(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OPUS_H */
--- a/src/opus.h
+++ b/src/opus.h
@@ -29,51 +29,13 @@
#define OPUS_H
#include "opus_types.h"
+#include "opus_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
-#if defined(__GNUC__) && defined(OPUS_BUILD)
-# define OPUS_EXPORT __attribute__ ((visibility ("default")))
-
-#elif defined(WIN32)
-
-# ifdef OPUS_BUILD
-# define OPUS_EXPORT __declspec(dllexport)
-# else
-# define OPUS_EXPORT __declspec(dllimport)
-# endif
-
-#else
-
-# define OPUS_EXPORT
-
-#endif
-
-#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
-#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
-#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
-
-/* Error codes */
-/** No error */
-#define OPUS_OK 0
-/** An (or more) invalid argument (e.g. out of range) */
-#define OPUS_BAD_ARG -1
-/** The mode struct passed is invalid */
-#define OPUS_BUFFER_TOO_SMALL -2
-/** An internal error was detected */
-#define OPUS_INTERNAL_ERROR -3
-/** The data passed (e.g. compressed data to decoder) is corrupted */
-#define OPUS_CORRUPTED_DATA -4
-/** Invalid/unsupported request number */
-#define OPUS_UNIMPLEMENTED -5
-/** An encoder or decoder structure is invalid or already freed */
-#define OPUS_INVALID_STATE -6
-/** Memory allocation has failed */
-#define OPUS_ALLOC_FAIL -7
-
#define OPUS_BITRATE_AUTO -1
#define OPUS_APPLICATION_VOIP 2000
@@ -91,78 +53,6 @@
#define OPUS_BANDWIDTH_FULLBAND 1105
-/* OPUS_APPLICATION_VOIP or OPUS_APPLICATION_AUDIO */
-#define OPUS_SET_APPLICATION_REQUEST 0
-#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
-#define OPUS_GET_APPLICATION_REQUEST 1
-#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
-
-/* Coding bit-rate in bit/second */
-#define OPUS_SET_BITRATE_REQUEST 2
-#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
-#define OPUS_GET_BITRATE_REQUEST 3
-#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
-
-/* 0 for CBR, 1 for VBR */
-#define OPUS_SET_VBR_REQUEST 6
-#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
-#define OPUS_GET_VBR_REQUEST 7
-#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_BANDWIDTH_REQUEST 8
-#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
-#define OPUS_GET_BANDWIDTH_REQUEST 9
-#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_COMPLEXITY_REQUEST 10
-#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
-#define OPUS_GET_COMPLEXITY_REQUEST 11
-#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_INBAND_FEC_REQUEST 12
-#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
-#define OPUS_GET_INBAND_FEC_REQUEST 13
-#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 14
-#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
-#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 15
-#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_DTX_REQUEST 16
-#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
-#define OPUS_GET_DTX_REQUEST 17
-#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_VOICE_RATIO_REQUEST 18
-#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
-#define OPUS_GET_VOICE_RATIO_REQUEST 19
-#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_VBR_CONSTRAINT_REQUEST 20
-#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
-#define OPUS_GET_VBR_CONSTRAINT_REQUEST 21
-#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_FORCE_MONO_REQUEST 22
-#define OPUS_SET_FORCE_MONO(x) OPUS_SET_FORCE_MONO_REQUEST, __opus_check_int(x)
-#define OPUS_GET_FORCE_MONO_REQUEST 23
-#define OPUS_GET_FORCE_MONO(x) OPUS_GET_FORCE_MONO_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_SET_SIGNAL_REQUEST 24
-#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
-#define OPUS_GET_SIGNAL_REQUEST 25
-#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_GET_LOOKAHEAD_REQUEST 27
-#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
-
-#define OPUS_RESET_STATE 28
-
-/* 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(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
typedef struct OpusEncoder OpusEncoder;
typedef struct OpusDecoder OpusDecoder;
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -110,7 +110,7 @@
/* Initialize CELT decoder */
ret = celt_decoder_init(celt_dec, Fs, channels);
- if (ret != CELT_OK)
+ if (ret != OPUS_OK)
goto failure;
celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0));
@@ -373,8 +373,8 @@
{
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0));
celt_decode_with_ec(celt_dec, data+len, redundancy_bytes, redundant_audio, F5, NULL);
- celt_decoder_ctl(celt_dec, CELT_GET_RANGE(&redundant_rng));
- celt_decoder_ctl(celt_dec, CELT_RESET_STATE);
+ celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng));
+ celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
}
/* MUST be after PLC */
@@ -381,7 +381,7 @@
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(start_band));
if (transition)
- celt_decoder_ctl(celt_dec, CELT_RESET_STATE);
+ celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
if (mode != MODE_SILK_ONLY)
{
@@ -413,11 +413,11 @@
/* 5 ms redundant frame for SILK->CELT */
if (redundancy && !celt_to_silk)
{
- celt_decoder_ctl(celt_dec, CELT_RESET_STATE);
+ celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0));
celt_decode_with_ec(celt_dec, data+len, redundancy_bytes, redundant_audio, F5, NULL);
- celt_decoder_ctl(celt_dec, CELT_GET_RANGE(&redundant_rng));
+ celt_decoder_ctl(celt_dec, OPUS_GET_FINAL_RANGE(&redundant_rng));
smooth_fade(pcm+st->channels*(frame_size-F2_5), redundant_audio+st->channels*F2_5,
pcm+st->channels*(frame_size-F2_5), F2_5, st->channels, window, st->Fs);
}
@@ -766,7 +766,7 @@
opus_decoder_get_size(st->channels)-
((char*)&st->OPUS_DECODER_RESET_START - (char*)st));
- celt_decoder_ctl(celt_dec, CELT_RESET_STATE);
+ celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
silk_InitDecoder( silk_dec );
st->stream_channels = st->channels;
st->frame_size = st->Fs/400;
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -155,7 +155,7 @@
/* Create CELT encoder */
/* Initialize CELT encoder */
err = celt_encoder_init(celt_enc, Fs, channels);
- if (err != CELT_OK)
+ if (err != OPUS_OK)
goto failure;
celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
@@ -593,12 +593,12 @@
}
if (st->mode != MODE_SILK_ONLY)
{
- celt_encoder_ctl(celt_enc, CELT_SET_VBR(0));
- celt_encoder_ctl(celt_enc, CELT_SET_BITRATE(-1));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0));
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(-1));
if (st->prev_mode == MODE_SILK_ONLY)
{
unsigned char dummy[10];
- celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
+ celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0));
/* TODO: This wastes CPU a bit compared to just prefilling the buffer */
@@ -621,9 +621,9 @@
} else {
if (st->use_vbr)
{
- celt_encoder_ctl(celt_enc, CELT_SET_VBR(1));
- celt_encoder_ctl(celt_enc, CELT_SET_VBR_CONSTRAINT(st->vbr_constraint));
- celt_encoder_ctl(celt_enc, CELT_SET_BITRATE(st->bitrate_bps));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(st->vbr_constraint));
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps));
nb_compr_bytes = max_data_bytes-1;
} else {
nb_compr_bytes = bytes_target;
@@ -703,10 +703,10 @@
if (redundancy && celt_to_silk)
{
celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
- celt_encoder_ctl(celt_enc, CELT_SET_VBR(0));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0));
celt_encode_with_ec(celt_enc, pcm_buf, st->Fs/200, data+nb_compr_bytes, redundancy_bytes, NULL);
- celt_encoder_ctl(celt_enc, CELT_GET_RANGE(&redundant_rng));
- celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
+ celt_encoder_ctl(celt_enc, OPUS_GET_FINAL_RANGE(&redundant_rng));
+ celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
}
celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(start_band));
@@ -723,7 +723,7 @@
N2 = st->Fs/200;
N4 = st->Fs/400;
- celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
+ celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0));
@@ -731,7 +731,7 @@
celt_encode_with_ec(celt_enc, pcm_buf+st->channels*(frame_size-N2-N4), N4, data+nb_compr_bytes, redundancy_bytes, NULL);
celt_encode_with_ec(celt_enc, pcm_buf+st->channels*(frame_size-N2), N2, data+nb_compr_bytes, redundancy_bytes, NULL);
- celt_encoder_ctl(celt_enc, CELT_GET_RANGE(&redundant_rng));
+ celt_encoder_ctl(celt_enc, OPUS_GET_FINAL_RANGE(&redundant_rng));
}
@@ -894,7 +894,7 @@
{
opus_int32 value = va_arg(ap, opus_int32);
st->silk_mode.complexity = value;
- celt_encoder_ctl(celt_enc, CELT_SET_COMPLEXITY(value));
+ celt_encoder_ctl(celt_enc, OPUS_SET_COMPLEXITY(value));
}
break;
case OPUS_GET_COMPLEXITY_REQUEST:
@@ -921,7 +921,7 @@
if (value < 0 || value > 100)
return OPUS_BAD_ARG;
st->silk_mode.packetLossPercentage = value;
- celt_encoder_ctl(celt_enc, CELT_SET_LOSS_PERC(value));
+ celt_encoder_ctl(celt_enc, OPUS_SET_PACKET_LOSS_PERC(value));
}
break;
case OPUS_GET_PACKET_LOSS_PERC_REQUEST:
@@ -1003,7 +1003,7 @@
opus_encoder_get_size(st->channels)-
((char*)&st->OPUS_ENCODER_RESET_START - (char*)st));
- celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
+ celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
silk_InitEncoder( silk_enc, &dummy );
st->stream_channels = st->channels;
st->hybrid_stereo_width_Q14 = 1 << 14;