Merge branch 'exp_api_change'

This commit is contained in:
Jean-Marc Valin 2011-01-30 12:15:12 -05:00
commit 665da0ba4d
17 changed files with 512 additions and 77 deletions

View file

@ -63,6 +63,32 @@ static const unsigned char tapset_icdf[3]={2,1,0};
#define COMBFILTER_MAXPERIOD 1024 #define COMBFILTER_MAXPERIOD 1024
#define COMBFILTER_MINPERIOD 15 #define COMBFILTER_MINPERIOD 15
static int resampling_factor(celt_int32 rate)
{
int ret;
switch (rate)
{
case 48000:
ret = 1;
break;
case 24000:
ret = 2;
break;
case 16000:
ret = 3;
break;
case 12000:
ret = 4;
break;
case 8000:
ret = 6;
break;
default:
ret = 0;
}
return ret;
}
/** Encoder state /** Encoder state
@brief Encoder state @brief Encoder state
*/ */
@ -73,6 +99,7 @@ struct CELTEncoder {
int force_intra; int force_intra;
int complexity; int complexity;
int upsample;
int start, end; int start, end;
celt_int32 vbr_rate_norm; /* Target number of 8th bits per frame */ celt_int32 vbr_rate_norm; /* Target number of 8th bits per frame */
@ -127,14 +154,44 @@ int celt_encoder_get_size(const CELTMode *mode, int channels)
return size; return size;
} }
CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error) CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error)
{ {
return celt_encoder_init( CELTEncoder *st;
(CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)), CELTMode *mode = celt_mode_create(48000, 960, NULL);
mode, channels, error); st = (CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels));
if (st!=NULL && celt_encoder_init(st, sampling_rate, channels, error)==NULL)
{
celt_encoder_destroy(st);
st = NULL;
}
return st;
} }
CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error) CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
{
CELTEncoder *st = (CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels));
if (st!=NULL && celt_encoder_init_custom(st, mode, channels, error)==NULL)
{
celt_encoder_destroy(st);
st = NULL;
}
return st;
}
CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error)
{
celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
st->upsample = resampling_factor(sampling_rate);
if (st->upsample==0)
{
if (error)
*error = CELT_BAD_ARG;
return NULL;
}
return st;
}
CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
{ {
if (channels < 0 || channels > 2) if (channels < 0 || channels > 2)
{ {
@ -143,7 +200,7 @@ CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channe
return NULL; return NULL;
} }
if (st==NULL) if (st==NULL || mode==NULL)
{ {
if (error) if (error)
*error = CELT_ALLOC_FAIL; *error = CELT_ALLOC_FAIL;
@ -156,6 +213,7 @@ CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channe
st->overlap = mode->overlap; st->overlap = mode->overlap;
st->channels = channels; st->channels = channels;
st->upsample = 1;
st->start = 0; st->start = 0;
st->end = st->mode->effEBands; st->end = st->mode->effEBands;
st->constrained_vbr = 1; st->constrained_vbr = 1;
@ -372,10 +430,11 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X
} while (++c<C); } while (++c<C);
} }
static void deemphasis(celt_sig *in[], celt_word16 *pcm, int N, int _C, const celt_word16 *coef, celt_sig *mem) static void deemphasis(celt_sig *in[], celt_word16 *pcm, int N, int _C, int downsample, const celt_word16 *coef, celt_sig *mem)
{ {
const int C = CHANNELS(_C); const int C = CHANNELS(_C);
int c; int c;
int count=0;
c=0; do { c=0; do {
int j; int j;
celt_sig * restrict x; celt_sig * restrict x;
@ -389,9 +448,15 @@ static void deemphasis(celt_sig *in[], celt_word16 *pcm, int N, int _C, const ce
m = MULT16_32_Q15(coef[0], tmp) m = MULT16_32_Q15(coef[0], tmp)
- MULT16_32_Q15(coef[1], *x); - MULT16_32_Q15(coef[1], *x);
tmp = SHL32(MULT16_32_Q15(coef[3], tmp), 2); tmp = SHL32(MULT16_32_Q15(coef[3], tmp), 2);
*y = SCALEOUT(SIG2WORD16(tmp));
x++; x++;
y+=C; /* Technically the store could be moved outside of the if because
the stores we don't want will just be overwritten */
if (++count==downsample)
{
*y = SCALEOUT(SIG2WORD16(tmp));
y+=C;
count=0;
}
} }
mem[c] = m; mem[c] = m;
} while (++c<C); } while (++c<C);
@ -829,6 +894,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
if (nbCompressedBytes<2 || pcm==NULL) if (nbCompressedBytes<2 || pcm==NULL)
return CELT_BAD_ARG; return CELT_BAD_ARG;
frame_size *= st->upsample;
for (LM=0;LM<4;LM++) for (LM=0;LM<4;LM++)
if (st->mode->shortMdctSize<<LM==frame_size) if (st->mode->shortMdctSize<<LM==frame_size)
break; break;
@ -907,19 +973,29 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
silence = 1; silence = 1;
c=0; do { c=0; do {
int count = 0;
const celt_word16 * restrict pcmp = pcm+c; const celt_word16 * restrict pcmp = pcm+c;
celt_sig * restrict inp = in+c*(N+st->overlap)+st->overlap; celt_sig * restrict inp = in+c*(N+st->overlap)+st->overlap;
for (i=0;i<N;i++) for (i=0;i<N;i++)
{ {
celt_sig x, tmp;
x = SCALEIN(*pcmp);
if (++count==st->upsample)
{
count=0;
pcmp+=C;
} else {
x = 0;
}
/* Apply pre-emphasis */ /* Apply pre-emphasis */
celt_sig tmp = MULT16_16(st->mode->preemph[2], SCALEIN(*pcmp)); tmp = MULT16_16(st->mode->preemph[2], x);
*inp = tmp + st->preemph_memE[c]; *inp = tmp + st->preemph_memE[c];
st->preemph_memE[c] = MULT16_32_Q15(st->mode->preemph[1], *inp) st->preemph_memE[c] = MULT16_32_Q15(st->mode->preemph[1], *inp)
- MULT16_32_Q15(st->mode->preemph[0], tmp); - MULT16_32_Q15(st->mode->preemph[0], tmp);
silence = silence && *inp == 0; silence = silence && *inp == 0;
inp++; inp++;
pcmp+=C;
} }
CELT_COPY(pre[c], prefilter_mem+c*COMBFILTER_MAXPERIOD, COMBFILTER_MAXPERIOD); CELT_COPY(pre[c], prefilter_mem+c*COMBFILTER_MAXPERIOD, COMBFILTER_MAXPERIOD);
CELT_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+st->overlap)+st->overlap, N); CELT_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+st->overlap)+st->overlap, N);
@ -1070,6 +1146,17 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
/* Compute MDCTs */ /* Compute MDCTs */
compute_mdcts(st->mode, shortBlocks, in, freq, C, LM); compute_mdcts(st->mode, shortBlocks, in, freq, C, LM);
if (st->upsample != 1)
{
c=0; do
{
int bound = N/st->upsample;
for (i=0;i<bound;i++)
freq[c*N+i] *= st->upsample;
for (;i<N;i++)
freq[c*N+i] = 0;
} while (++c<C);
}
ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
compute_band_energies(st->mode, freq, bandE, effEnd, C, M); compute_band_energies(st->mode, freq, bandE, effEnd, C, M);
@ -1404,7 +1491,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
} while (++c<C); } while (++c<C);
#endif /* ENABLE_POSTFILTER */ #endif /* ENABLE_POSTFILTER */
deemphasis(out_mem, (celt_word16*)pcm, N, C, st->mode->preemph, st->preemph_memD); deemphasis(out_mem, (celt_word16*)pcm, N, C, st->upsample, st->mode->preemph, st->preemph_memD);
st->prefilter_period_old = st->prefilter_period; st->prefilter_period_old = st->prefilter_period;
st->prefilter_gain_old = st->prefilter_gain; st->prefilter_gain_old = st->prefilter_gain;
st->prefilter_tapset_old = st->prefilter_tapset; st->prefilter_tapset_old = st->prefilter_tapset;
@ -1643,6 +1730,7 @@ struct CELTDecoder {
int overlap; int overlap;
int channels; int channels;
int downsample;
int start, end; int start, end;
/* Everything beyond this point gets cleared on a reset */ /* Everything beyond this point gets cleared on a reset */
@ -1677,14 +1765,44 @@ int celt_decoder_get_size(const CELTMode *mode, int channels)
return size; return size;
} }
CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error) CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error)
{ {
return celt_decoder_init( CELTDecoder *st;
(CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)), const CELTMode *mode = celt_mode_create(48000, 960, NULL);
mode, channels, error); st = (CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels));
if (st!=NULL && celt_decoder_init(st, sampling_rate, channels, error)==NULL)
{
celt_decoder_destroy(st);
st = NULL;
}
return st;
} }
CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error) CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
{
CELTDecoder *st = (CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels));
if (st!=NULL && celt_decoder_init_custom(st, mode, channels, error)==NULL)
{
celt_decoder_destroy(st);
st = NULL;
}
return st;
}
CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error)
{
celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
st->downsample = resampling_factor(sampling_rate);
if (st->downsample==0)
{
if (error)
*error = CELT_BAD_ARG;
return NULL;
}
return st;
}
CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
{ {
if (channels < 0 || channels > 2) if (channels < 0 || channels > 2)
{ {
@ -1706,6 +1824,7 @@ CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channe
st->overlap = mode->overlap; st->overlap = mode->overlap;
st->channels = channels; st->channels = channels;
st->downsample = 1;
st->start = 0; st->start = 0;
st->end = st->mode->effEBands; st->end = st->mode->effEBands;
@ -1934,7 +2053,7 @@ static void celt_decode_lost(CELTDecoder * restrict st, celt_word16 * restrict p
out_mem[c][MAX_PERIOD+i] = e[i]; out_mem[c][MAX_PERIOD+i] = e[i];
} while (++c<C); } while (++c<C);
deemphasis(out_syn, pcm, N, C, st->mode->preemph, st->preemph_memD); deemphasis(out_syn, pcm, N, C, st->downsample, st->mode->preemph, st->preemph_memD);
st->loss_count++; st->loss_count++;
@ -1995,6 +2114,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
if (pcm==NULL) if (pcm==NULL)
return CELT_BAD_ARG; return CELT_BAD_ARG;
frame_size *= st->downsample;
for (LM=0;LM<4;LM++) for (LM=0;LM<4;LM++)
if (st->mode->shortMdctSize<<LM==frame_size) if (st->mode->shortMdctSize<<LM==frame_size)
break; break;
@ -2204,10 +2324,13 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
for (i=0;i<M*st->mode->eBands[st->start];i++) for (i=0;i<M*st->mode->eBands[st->start];i++)
freq[c*N+i] = 0; freq[c*N+i] = 0;
while (++c<C); while (++c<C);
c=0; do c=0; do {
int bound = M*st->mode->eBands[effEnd];
if (st->downsample!=1)
bound = IMIN(bound, N/st->downsample);
for (i=M*st->mode->eBands[effEnd];i<N;i++) for (i=M*st->mode->eBands[effEnd];i<N;i++)
freq[c*N+i] = 0; freq[c*N+i] = 0;
while (++c<C); } while (++c<C);
out_syn[0] = out_mem[0]+MAX_PERIOD-N; out_syn[0] = out_mem[0]+MAX_PERIOD-N;
if (C==2) if (C==2)
@ -2264,7 +2387,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
} }
st->rng = dec->rng; st->rng = dec->rng;
deemphasis(out_syn, pcm, N, C, st->mode->preemph, st->preemph_memD); deemphasis(out_syn, pcm, N, C, st->downsample, st->mode->preemph, st->preemph_memD);
st->loss_count = 0; st->loss_count = 0;
RESTORE_STACK; RESTORE_STACK;
if (ec_dec_tell(dec,0) > 8*len || ec_dec_get_error(dec)) if (ec_dec_tell(dec,0) > 8*len || ec_dec_get_error(dec))

View file

@ -163,6 +163,14 @@ EXPORT int celt_encoder_get_size(const CELTMode *mode, int channels);
/** 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 channels Number of channels
@param error Returns an error code
@return Newly created encoder state.
*/
EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, 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 @param mode Contains all the information about the characteristics of
* the stream (must be the same characteristics as used for the * the stream (must be the same characteristics as used for the
* decoder) * decoder)
@ -170,9 +178,11 @@ EXPORT int celt_encoder_get_size(const CELTMode *mode, int channels);
@param error Returns an error code @param error Returns an error code
@return Newly created encoder state. @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 sampling_rate, int channels, int *error);
EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
/** Destroys a an encoder state. /** Destroys a an encoder state.
@param st Encoder state to be destroyed @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 @param error Returns an error code
@return Newly created decoder state. @return Newly created decoder state.
*/ */
EXPORT CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error); EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, 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 sampling_rate, int channels, int *error);
EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
/** Destroys a a decoder state. /** Destroys a a decoder state.
@param st Decoder state to be destroyed @param st Decoder state to be destroyed

View file

@ -644,7 +644,7 @@ celt_uint32 icwrs(int _n,int _k,celt_uint32 *_nc,const int *_y,
return i; return i;
} }
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
void get_required_bits(celt_int16 *_bits,int _n,int _maxk,int _frac){ void get_required_bits(celt_int16 *_bits,int _n,int _maxk,int _frac){
int k; int k;
/*_maxk==0 => there's nothing to do.*/ /*_maxk==0 => there's nothing to do.*/
@ -665,7 +665,7 @@ void get_required_bits(celt_int16 *_bits,int _n,int _maxk,int _frac){
RESTORE_STACK; RESTORE_STACK;
} }
} }
#endif /* STATIC_MODES */ #endif /* CUSTOM_MODES */
void encode_pulses(const int *_y,int _n,int _k,ec_enc *_enc){ void encode_pulses(const int *_y,int _n,int _k,ec_enc *_enc){
celt_uint32 i; celt_uint32 i;

View file

@ -312,9 +312,9 @@ int main(int argc, char **argv)
file = fopen(BASENAME ".c", "w"); file = fopen(BASENAME ".c", "w");
dump_modes(file, m, nb); dump_modes(file, m, nb);
fclose(file); fclose(file);
file = fopen(BASENAME ".h", "w"); /*file = fopen(BASENAME ".h", "w");
dump_header(file, m, nb); dump_header(file, m, nb);
fclose(file); fclose(file);*/
for (i=0;i<nb;i++) for (i=0;i<nb;i++)
celt_mode_destroy(m[i]); celt_mode_destroy(m[i]);
free(m); free(m);

View file

@ -495,7 +495,7 @@ static void ki_work(
} }
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
static static
void compute_bitrev_table( void compute_bitrev_table(
@ -651,7 +651,7 @@ void kiss_fft_free(const kiss_fft_state *cfg)
celt_free((kiss_fft_state*)cfg); celt_free((kiss_fft_state*)cfg);
} }
#endif /* STATIC_MODES */ #endif /* CUSTOM_MODES */
static void kiss_fft_stride(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride) static void kiss_fft_stride(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{ {

View file

@ -61,7 +61,7 @@
#define M_PI 3.141592653 #define M_PI 3.141592653
#endif #endif
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
void clt_mdct_init(mdct_lookup *l,int N, int maxshift) void clt_mdct_init(mdct_lookup *l,int N, int maxshift)
{ {
@ -104,7 +104,7 @@ void clt_mdct_clear(mdct_lookup *l)
celt_free((kiss_twiddle_scalar*)l->trig); celt_free((kiss_twiddle_scalar*)l->trig);
} }
#endif /* STATIC_MODES */ #endif /* CUSTOM_MODES */
void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, const celt_word16 *window, int overlap, int shift) void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, const celt_word16 *window, int overlap, int shift)
{ {

View file

@ -85,13 +85,13 @@ static const unsigned char band_allocation[] = {
}; };
#endif #endif
#ifdef STATIC_MODES #ifndef CUSTOM_MODES_ONLY
#ifdef FIXED_POINT #ifdef FIXED_POINT
#include "static_modes_fixed.c" #include "static_modes_fixed.c"
#else #else
#include "static_modes_float.c" #include "static_modes_float.c"
#endif #endif
#endif #endif /* CUSTOM_MODES_ONLY */
#ifndef M_PI #ifndef M_PI
#define M_PI 3.141592653 #define M_PI 3.141592653
@ -117,7 +117,7 @@ int celt_mode_info(const CELTMode *mode, int request, celt_int32 *value)
return CELT_OK; return CELT_OK;
} }
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
/* Defining 25 critical bands for the full 0-20 kHz audio bandwidth /* Defining 25 critical bands for the full 0-20 kHz audio bandwidth
Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */ Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */
@ -253,24 +253,11 @@ static void compute_allocation_table(CELTMode *mode)
mode->allocVectors = allocVectors; mode->allocVectors = allocVectors;
} }
#endif /* STATIC_MODES */ #endif /* CUSTOM_MODES */
CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
{ {
int i; int i;
#ifdef STATIC_MODES
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)
{
return (CELTMode*)static_mode_list[i];
}
}
if (error)
*error = CELT_BAD_ARG;
return NULL;
#else
int res; int res;
CELTMode *mode=NULL; CELTMode *mode=NULL;
celt_word16 *window; celt_word16 *window;
@ -291,6 +278,29 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
goto failure; goto failure;
#endif #endif
#ifndef CUSTOM_MODES_ONLY
for (i=0;i<TOTAL_MODES;i++)
{
int j;
for (j=0;j<4;j++)
{
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];
}
}
}
#endif /* CUSTOM_MODES_ONLY */
#ifndef CUSTOM_MODES
if (error)
*error = CELT_BAD_ARG;
return NULL;
#else
/* The good thing here is that permutation of the arguments will automatically be invalid */ /* The good thing here is that permutation of the arguments will automatically be invalid */
if (Fs < 8000 || Fs > 96000) if (Fs < 8000 || Fs > 96000)
@ -415,15 +425,24 @@ failure:
if (mode!=NULL) if (mode!=NULL)
celt_mode_destroy(mode); celt_mode_destroy(mode);
return NULL; return NULL;
#endif /* !STATIC_MODES */ #endif /* !CUSTOM_MODES */
} }
void celt_mode_destroy(CELTMode *mode) void celt_mode_destroy(CELTMode *mode)
{ {
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
int i;
if (mode == NULL) if (mode == NULL)
return; return;
#ifndef CUSTOM_MODES_ONLY
for (i=0;i<TOTAL_MODES;i++)
{
if (mode == static_mode_list[i])
{
return;
}
}
#endif /* CUSTOM_MODES_ONLY */
celt_free((celt_int16*)mode->eBands); celt_free((celt_int16*)mode->eBands);
celt_free((celt_int16*)mode->allocVectors); celt_free((celt_int16*)mode->allocVectors);

View file

@ -45,10 +45,6 @@
#define CELT_BITSTREAM_VERSION 0x8000000f #define CELT_BITSTREAM_VERSION 0x8000000f
#ifdef STATIC_MODES
#include "static_modes.h"
#endif
#define MAX_PERIOD 1024 #define MAX_PERIOD 1024
#ifndef CHANNELS #ifndef CHANNELS

View file

@ -52,7 +52,7 @@ static const unsigned char LOG2_FRAC_TABLE[24]={
32,33,34,34,35,36,36,37,37 32,33,34,34,35,36,36,37,37
}; };
#ifndef STATIC_MODES #ifdef CUSTOM_MODES
/*Determines if V(N,K) fits in a 32-bit unsigned integer. /*Determines if V(N,K) fits in a 32-bit unsigned integer.
N and K are themselves limited to 15 bits.*/ N and K are themselves limited to 15 bits.*/
@ -250,7 +250,7 @@ void compute_pulse_cache(CELTMode *m, int LM)
} }
} }
#endif /* !STATIC_MODES */ #endif /* !CUSTOM_MODES */
#define ALLOC_STEPS 6 #define ALLOC_STEPS 6

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -57,7 +57,7 @@ int main(int argc, char *argv[])
unsigned char data[MAX_PACKET]; unsigned char data[MAX_PACKET];
int rate; int rate;
int complexity; int complexity;
#if !(defined (FIXED_POINT) && defined(STATIC_MODES)) #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES))
int i; int i;
double rmsd = 0; double rmsd = 0;
#endif #endif
@ -107,13 +107,13 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
enc = celt_encoder_create(mode, channels, &err); enc = celt_encoder_create_custom(mode, channels, &err);
if (err != 0) if (err != 0)
{ {
fprintf(stderr, "Failed to create the encoder: %s\n", celt_strerror(err)); fprintf(stderr, "Failed to create the encoder: %s\n", celt_strerror(err));
return 1; return 1;
} }
dec = celt_decoder_create(mode, channels, &err); dec = celt_decoder_create_custom(mode, channels, &err);
if (err != 0) if (err != 0)
{ {
fprintf(stderr, "Failed to create the decoder: %s\n", celt_strerror(err)); fprintf(stderr, "Failed to create the decoder: %s\n", celt_strerror(err));
@ -174,7 +174,7 @@ int main(int argc, char *argv[])
for (i=0;i<frame_size*channels;i++) for (i=0;i<frame_size*channels;i++)
out[i] = in[i]; out[i] = in[i];
#endif #endif
#if !(defined (FIXED_POINT) && defined(STATIC_MODES)) #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES))
for (i=0;i<frame_size*channels;i++) for (i=0;i<frame_size*channels;i++)
{ {
rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]); rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]);

View file

@ -4,8 +4,8 @@
#define SKIP_CONFIG_H #define SKIP_CONFIG_H
#ifdef STATIC_MODES #ifndef CUSTOM_MODES
#undef STATIC_MODES #define CUSTOM_MODES
#endif #endif
#include <stdio.h> #include <stdio.h>

View file

@ -4,8 +4,8 @@
#define SKIP_CONFIG_H #define SKIP_CONFIG_H
#ifdef STATIC_MODES #ifndef CUSTOM_MODES
#undef STATIC_MODES #define CUSTOM_MODES
#endif #endif
#include <stdio.h> #include <stdio.h>

View file

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

View file

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

View file

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