Makes the CELT init() functions behave just like the Opus ones.
This commit is contained in:
parent
58686e6fe1
commit
875f8dbd56
4 changed files with 41 additions and 84 deletions
105
libcelt/celt.c
105
libcelt/celt.c
|
@ -197,57 +197,42 @@ int celt_encoder_get_size_custom(const CELTMode *mode, int channels)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error)
|
|
||||||
{
|
|
||||||
CELTEncoder *st;
|
|
||||||
st = (CELTEncoder *)opus_alloc(celt_encoder_get_size(channels));
|
|
||||||
if (st!=NULL && celt_encoder_init(st, sampling_rate, channels, error)==NULL)
|
|
||||||
{
|
|
||||||
celt_encoder_destroy(st);
|
|
||||||
st = NULL;
|
|
||||||
}
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
|
|
||||||
CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
|
CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
CELTEncoder *st = (CELTEncoder *)opus_alloc(celt_encoder_get_size_custom(mode, channels));
|
CELTEncoder *st = (CELTEncoder *)opus_alloc(celt_encoder_get_size_custom(mode, channels));
|
||||||
if (st!=NULL && celt_encoder_init_custom(st, mode, channels, error)==NULL)
|
/* init will handle the NULL case */
|
||||||
|
ret = celt_encoder_init_custom(st, mode, channels);
|
||||||
|
if (ret != CELT_OK)
|
||||||
{
|
{
|
||||||
celt_encoder_destroy(st);
|
celt_encoder_destroy(st);
|
||||||
st = NULL;
|
st = NULL;
|
||||||
|
if (error)
|
||||||
|
*error = ret;
|
||||||
}
|
}
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error)
|
int celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels)
|
||||||
{
|
{
|
||||||
celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
|
int ret;
|
||||||
|
ret = celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels);
|
||||||
|
if (ret != CELT_OK)
|
||||||
|
return ret;
|
||||||
st->upsample = resampling_factor(sampling_rate);
|
st->upsample = resampling_factor(sampling_rate);
|
||||||
if (st->upsample==0)
|
if (st->upsample==0)
|
||||||
{
|
return CELT_BAD_ARG;
|
||||||
if (error)
|
else
|
||||||
*error = CELT_BAD_ARG;
|
return CELT_OK;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
|
int celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels)
|
||||||
{
|
{
|
||||||
if (channels < 0 || channels > 2)
|
if (channels < 0 || channels > 2)
|
||||||
{
|
return CELT_BAD_ARG;
|
||||||
if (error)
|
|
||||||
*error = CELT_BAD_ARG;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (st==NULL || mode==NULL)
|
if (st==NULL || mode==NULL)
|
||||||
{
|
return CELT_ALLOC_FAIL;
|
||||||
if (error)
|
|
||||||
*error = CELT_ALLOC_FAIL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
OPUS_CLEAR((char*)st, celt_encoder_get_size_custom(mode, channels));
|
OPUS_CLEAR((char*)st, celt_encoder_get_size_custom(mode, channels));
|
||||||
|
|
||||||
|
@ -274,9 +259,7 @@ CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int
|
||||||
st->tapset_decision = 0;
|
st->tapset_decision = 0;
|
||||||
st->complexity = 5;
|
st->complexity = 5;
|
||||||
|
|
||||||
if (error)
|
return CELT_OK;
|
||||||
*error = CELT_OK;
|
|
||||||
return st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void celt_encoder_destroy(CELTEncoder *st)
|
void celt_encoder_destroy(CELTEncoder *st)
|
||||||
|
@ -1921,57 +1904,41 @@ int celt_decoder_get_size_custom(const CELTMode *mode, int channels)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error)
|
|
||||||
{
|
|
||||||
CELTDecoder *st;
|
|
||||||
st = (CELTDecoder *)opus_alloc(celt_decoder_get_size(channels));
|
|
||||||
if (st!=NULL && celt_decoder_init(st, sampling_rate, channels, error)==NULL)
|
|
||||||
{
|
|
||||||
celt_decoder_destroy(st);
|
|
||||||
st = NULL;
|
|
||||||
}
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
|
|
||||||
CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
|
CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
CELTDecoder *st = (CELTDecoder *)opus_alloc(celt_decoder_get_size_custom(mode, channels));
|
CELTDecoder *st = (CELTDecoder *)opus_alloc(celt_decoder_get_size_custom(mode, channels));
|
||||||
if (st!=NULL && celt_decoder_init_custom(st, mode, channels, error)==NULL)
|
ret = celt_decoder_init_custom(st, mode, channels);
|
||||||
|
if (ret != CELT_OK)
|
||||||
{
|
{
|
||||||
celt_decoder_destroy(st);
|
celt_decoder_destroy(st);
|
||||||
st = NULL;
|
st = NULL;
|
||||||
|
if (error)
|
||||||
|
*error = ret;
|
||||||
}
|
}
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error)
|
int celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels)
|
||||||
{
|
{
|
||||||
celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
|
int ret;
|
||||||
|
ret = celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels);
|
||||||
|
if (ret != CELT_OK)
|
||||||
|
return ret;
|
||||||
st->downsample = resampling_factor(sampling_rate);
|
st->downsample = resampling_factor(sampling_rate);
|
||||||
if (st->downsample==0)
|
if (st->downsample==0)
|
||||||
{
|
return CELT_BAD_ARG;
|
||||||
if (error)
|
else
|
||||||
*error = CELT_BAD_ARG;
|
return CELT_OK;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
|
int celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels)
|
||||||
{
|
{
|
||||||
if (channels < 0 || channels > 2)
|
if (channels < 0 || channels > 2)
|
||||||
{
|
return CELT_BAD_ARG;
|
||||||
if (error)
|
|
||||||
*error = CELT_BAD_ARG;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (st==NULL)
|
if (st==NULL)
|
||||||
{
|
return CELT_ALLOC_FAIL;
|
||||||
if (error)
|
|
||||||
*error = CELT_ALLOC_FAIL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
OPUS_CLEAR((char*)st, celt_decoder_get_size_custom(mode, channels));
|
OPUS_CLEAR((char*)st, celt_decoder_get_size_custom(mode, channels));
|
||||||
|
|
||||||
|
@ -1986,9 +1953,7 @@ CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int
|
||||||
|
|
||||||
st->loss_count = 0;
|
st->loss_count = 0;
|
||||||
|
|
||||||
if (error)
|
return CELT_OK;
|
||||||
*error = CELT_OK;
|
|
||||||
return st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void celt_decoder_destroy(CELTDecoder *st)
|
void celt_decoder_destroy(CELTDecoder *st)
|
||||||
|
|
|
@ -171,14 +171,6 @@ CELT_EXPORT int celt_encoder_get_size(int channels);
|
||||||
|
|
||||||
CELT_EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels);
|
CELT_EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels);
|
||||||
|
|
||||||
/** Creates a new encoder state. Each stream needs its own encoder
|
|
||||||
state (can't be shared across simultaneous streams).
|
|
||||||
@param channels Number of channels
|
|
||||||
@param error Returns an error code
|
|
||||||
@return Newly created encoder state.
|
|
||||||
*/
|
|
||||||
CELT_EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error);
|
|
||||||
|
|
||||||
/** Creates a new encoder state. Each stream needs its own encoder
|
/** Creates a new encoder state. Each stream needs its own encoder
|
||||||
state (can't be shared across simultaneous streams).
|
state (can't be shared across simultaneous streams).
|
||||||
@param mode Contains all the information about the characteristics of
|
@param mode Contains all the information about the characteristics of
|
||||||
|
@ -190,9 +182,9 @@ CELT_EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, in
|
||||||
*/
|
*/
|
||||||
CELT_EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
|
CELT_EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
|
||||||
|
|
||||||
CELT_EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error);
|
CELT_EXPORT int celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels);
|
||||||
|
|
||||||
CELT_EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
|
CELT_EXPORT int celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels);
|
||||||
|
|
||||||
/** Destroys a an encoder state.
|
/** Destroys a an encoder state.
|
||||||
@param st Encoder state to be destroyed
|
@param st Encoder state to be destroyed
|
||||||
|
@ -269,9 +261,9 @@ CELT_EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, in
|
||||||
*/
|
*/
|
||||||
CELT_EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
|
CELT_EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
|
||||||
|
|
||||||
CELT_EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error);
|
CELT_EXPORT int celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels);
|
||||||
|
|
||||||
CELT_EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
|
CELT_EXPORT int celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels);
|
||||||
|
|
||||||
/** Destroys a a decoder state.
|
/** Destroys a a decoder state.
|
||||||
@param st Decoder state to be destroyed
|
@param st Decoder state to be destroyed
|
||||||
|
|
|
@ -109,7 +109,7 @@ int opus_decoder_init(OpusDecoder *st, int Fs, int channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize CELT decoder */
|
/* Initialize CELT decoder */
|
||||||
celt_decoder_init(celt_dec, Fs, channels, &ret);
|
ret = celt_decoder_init(celt_dec, Fs, channels);
|
||||||
if (ret != CELT_OK)
|
if (ret != CELT_OK)
|
||||||
goto failure;
|
goto failure;
|
||||||
celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0));
|
celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0));
|
||||||
|
|
|
@ -154,7 +154,7 @@ int opus_encoder_init(OpusEncoder* st, int Fs, int channels, int application)
|
||||||
|
|
||||||
/* Create CELT encoder */
|
/* Create CELT encoder */
|
||||||
/* Initialize CELT encoder */
|
/* Initialize CELT encoder */
|
||||||
celt_encoder_init(celt_enc, Fs, channels, &err);
|
err = celt_encoder_init(celt_enc, Fs, channels);
|
||||||
if (err != CELT_OK)
|
if (err != CELT_OK)
|
||||||
goto failure;
|
goto failure;
|
||||||
celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
|
celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue