celt_encoder_create() now defaults to Opus standard mode

The old constructor is renamed celt_encoder_create_custom(). Same
for the decoder.
This commit is contained in:
Jean-Marc Valin 2011-01-28 23:07:32 -05:00
parent 5ad35bf3bf
commit c97b258c62
7 changed files with 83 additions and 18 deletions

View file

@ -127,14 +127,27 @@ int celt_encoder_get_size(const CELTMode *mode, int channels)
return size;
}
CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error)
CELTEncoder *celt_encoder_create(int channels, int *error)
{
CELTMode *mode = celt_mode_create(48000, 960, NULL);
return celt_encoder_init(
(CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)),
channels, error);
}
CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
{
return celt_encoder_init_custom(
(CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)),
mode, channels, error);
}
CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
CELTEncoder *celt_encoder_init(CELTEncoder *st, int channels, int *error)
{
return celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
}
CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
{
if (channels < 0 || channels > 2)
{
@ -1672,14 +1685,27 @@ int celt_decoder_get_size(const CELTMode *mode, int channels)
return size;
}
CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error)
CELTDecoder *celt_decoder_create(int channels, int *error)
{
const CELTMode *mode = celt_mode_create(48000, 960, NULL);
return celt_decoder_init(
(CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)),
channels, error);
}
CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
{
return celt_decoder_init_custom(
(CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)),
mode, channels, error);
}
CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
CELTDecoder *celt_decoder_init(CELTDecoder *st, int channels, int *error)
{
return celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
}
CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
{
if (channels < 0 || channels > 2)
{

View file

@ -161,6 +161,14 @@ EXPORT int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value);
EXPORT int celt_encoder_get_size(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.
*/
EXPORT CELTEncoder *celt_encoder_create(int channels, int *error);
/** Creates a new encoder state. Each stream needs its own encoder
state (can't be shared across simultaneous streams).
@param mode Contains all the information about the characteristics of
@ -170,9 +178,11 @@ EXPORT int celt_encoder_get_size(const CELTMode *mode, int channels);
@param error Returns an error code
@return Newly created encoder state.
*/
EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error);
EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int channels, int *error);
EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
/** Destroys a an encoder state.
@param st Encoder state to be destroyed
@ -235,9 +245,21 @@ EXPORT int celt_decoder_get_size(const CELTMode *mode, int channels);
@param error Returns an error code
@return Newly created decoder state.
*/
EXPORT CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error);
EXPORT CELTDecoder *celt_decoder_create(int channels, int *error);
EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
/** Creates a new decoder state. Each stream needs its own decoder state (can't
be shared across simultaneous streams).
@param mode Contains all the information about the characteristics of the
stream (must be the same characteristics as used for the encoder)
@param channels Number of channels
@param error Returns an error code
@return Newly created decoder state.
*/
EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int channels, int *error);
EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
/** Destroys a a decoder state.
@param st Decoder state to be destroyed

View file

@ -278,10 +278,16 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
for (i=0;i<TOTAL_MODES;i++)
{
if (Fs == static_mode_list[i]->Fs &&
frame_size == static_mode_list[i]->shortMdctSize*static_mode_list[i]->nbShortMdcts)
int j;
for (j=0;j<4;j++)
{
return (CELTMode*)static_mode_list[i];
if (Fs == static_mode_list[i]->Fs &&
(frame_size<<j) == static_mode_list[i]->shortMdctSize*static_mode_list[i]->nbShortMdcts)
{
if (error)
*error = CELT_OK;
return (CELTMode*)static_mode_list[i];
}
}
}
#ifndef CUSTOM_MODES

View file

@ -107,13 +107,13 @@ int main(int argc, char *argv[])
return 1;
}
enc = celt_encoder_create(mode, channels, &err);
enc = celt_encoder_create_custom(mode, channels, &err);
if (err != 0)
{
fprintf(stderr, "Failed to create the encoder: %s\n", celt_strerror(err));
return 1;
}
dec = celt_decoder_create(mode, channels, &err);
dec = celt_decoder_create_custom(mode, channels, &err);
if (err != 0)
{
fprintf(stderr, "Failed to create the decoder: %s\n", celt_strerror(err));

View file

@ -85,12 +85,12 @@ int async_tandem(int rate, int frame_size, int channels, int bitrate_min,
exit(1);
}
dec = celt_decoder_create(mode, channels, &error);
dec = celt_decoder_create_custom(mode, channels, &error);
if (error){
fprintf(stderr, "Error: celt_decoder_create returned %s\n", celt_strerror(error));
exit(1);
}
enc = celt_encoder_create(mode, channels, &error);
enc = celt_encoder_create_custom(mode, channels, &error);
if (error){
fprintf(stderr, "Error: celt_encoder_create returned %s\n", celt_strerror(error));
exit(1);
@ -167,7 +167,11 @@ int async_tandem(int rate, int frame_size, int channels, int bitrate_min,
int main(int argc, char *argv[])
{
#ifdef CUSTOM_MODES
int sizes[8]={960,480,240,120,512,256,128,64};
#else
int sizes[4]={960,480,240,120};
#endif
unsigned int seed;
int ch, n;
@ -184,6 +188,7 @@ int main(int argc, char *argv[])
srand(seed);
printf("CELT codec tests. Random seed: %u (%.4X)\n", seed, rand() % 65536);
#ifdef CUSTOM_MODES
for (n = 0; n < 8; n++) {
for (ch = 1; ch <= 2; ch++) {
async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
@ -192,6 +197,12 @@ int main(int argc, char *argv[])
async_tandem(16000, sizes[n], ch, 12000 * ch, 64000 * ch);
}
}
#else
for (n = 0; n < 4; n++) {
for (ch = 1; ch <= 2; ch++) {
async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
}
}
#endif
return 0;
}

View file

@ -315,7 +315,7 @@ static CELTDecoder *process_header(ogg_packet *op, celt_int32 enh_enabled, celt_
*channels = header.nb_channels;
*overlap=header.overlap;
st = celt_decoder_create(*mode, header.nb_channels, NULL);
st = celt_decoder_create_custom(*mode, header.nb_channels, NULL);
if (!st)
{
fprintf (stderr, "Decoder initialization failed.\n");

View file

@ -525,7 +525,7 @@ int main(int argc, char **argv)
}
/*Initialize CELT encoder*/
st = celt_encoder_create(mode, chan, NULL);
st = celt_encoder_create_custom(mode, chan, NULL);
if (!with_cbr)
{