From 0bb05bc5ead56bacad2ed65d44f9e0e5c6cd47ef Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 20 Feb 2008 13:43:40 +1100 Subject: [PATCH] Another bunch of C99 array conversions (few more to go) --- configure.ac | 4 ++-- libcelt/celt.c | 55 ++++++++++++++++++++++++++----------------- libcelt/mdct.c | 6 +++-- libcelt/pitch.c | 18 ++++++++------ libcelt/psy.c | 7 ++++-- libcelt/quant_pitch.c | 4 +++- libcelt/rate.c | 24 ++++++++++--------- libcelt/testcelt.c | 10 ++++++-- 8 files changed, 80 insertions(+), 48 deletions(-) diff --git a/configure.ac b/configure.ac index 41c0782d..fc7724dc 100644 --- a/configure.ac +++ b/configure.ac @@ -5,9 +5,9 @@ AC_INIT(libcelt/arch.h) AM_CONFIG_HEADER([config.h]) CELT_MAJOR_VERSION=0 -CELT_MINOR_VERSION=1 +CELT_MINOR_VERSION=2 CELT_MICRO_VERSION=0 -CELT_EXTRA_VERSION= +CELT_EXTRA_VERSION=-git CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION CELT_LT_CURRENT=0 diff --git a/libcelt/celt.c b/libcelt/celt.c index 8365276a..086cfef1 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -214,18 +214,23 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i { int i, c, N, B, C, N4; int has_pitch; + int pitch_index; + float curr_power, pitch_power; + VARDECL(float *in); + VARDECL(float *X); + VARDECL(float *P); + VARDECL(float *mask); + VARDECL(float *bandE); + VARDECL(float *gains); N = st->block_size; B = st->nb_blocks; C = st->mode->nbChannels; - float in[(B+1)*C*N]; - - float X[B*C*N]; /**< Interleaved signal MDCTs */ - float P[B*C*N]; /**< Interleaved pitch MDCTs*/ - float mask[B*C*N]; /**< Masking curve */ - float bandE[st->mode->nbEBands*C]; - float gains[st->mode->nbPBands]; - int pitch_index; - float curr_power, pitch_power; + ALLOC(in, (B+1)*C*N, float); + ALLOC(X, B*C*N, float); /**< Interleaved signal MDCTs */ + ALLOC(P, B*C*N, float); /**< Interleaved pitch MDCTs*/ + ALLOC(mask, B*C*N, float); /**< Masking curve */ + ALLOC(bandE,st->mode->nbEBands*C, float); + ALLOC(gains,st->mode->nbPBands, float); N4 = (N-st->overlap)/2; @@ -301,7 +306,8 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i if (curr_power + 1e5f < 10.f*pitch_power) { /* Normalise the pitch vector as well (discard the energies) */ - float bandEp[st->mode->nbEBands*st->mode->nbChannels]; + VARDECL(float *bandEp); + ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, float); compute_band_energies(st->mode, P, bandEp); normalise_bands(st->mode, P, bandEp); @@ -439,10 +445,11 @@ struct CELTDecoder { CELTDecoder *celt_decoder_new(const CELTMode *mode) { int i, N, B, C, N4; + CELTDecoder *st; N = mode->mdctSize; B = mode->nbMdctBlocks; C = mode->nbChannels; - CELTDecoder *st = celt_alloc(sizeof(CELTDecoder)); + st = celt_alloc(sizeof(CELTDecoder)); st->mode = mode; st->frame_size = B*N; @@ -499,11 +506,12 @@ void celt_decoder_destroy(CELTDecoder *st) static void celt_decode_lost(CELTDecoder *st, short *pcm) { int i, c, N, B, C; + int pitch_index; + VARDECL(float *X); N = st->block_size; B = st->nb_blocks; C = st->mode->nbChannels; - float X[C*B*N]; /**< Interleaved signal MDCTs */ - int pitch_index; + ALLOC(X,C*B*N, float); /**< Interleaved signal MDCTs */ pitch_index = st->last_pitch_index; @@ -535,17 +543,21 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm { int i, c, N, B, C; int has_pitch; + int pitch_index; + ec_dec dec; + ec_byte_buffer buf; + VARDECL(float *X); + VARDECL(float *P); + VARDECL(float *bandE); + VARDECL(float *gains); N = st->block_size; B = st->nb_blocks; C = st->mode->nbChannels; - float X[C*B*N]; /**< Interleaved signal MDCTs */ - float P[C*B*N]; /**< Interleaved pitch MDCTs*/ - float bandE[st->mode->nbEBands*C]; - float gains[st->mode->nbPBands]; - int pitch_index; - ec_dec dec; - ec_byte_buffer buf; + ALLOC(X, C*B*N, float); /**< Interleaved signal MDCTs */ + ALLOC(P, C*B*N, float); /**< Interleaved pitch MDCTs*/ + ALLOC(bandE, st->mode->nbEBands*C, float); + ALLOC(gains, st->mode->nbPBands, float); if (data == NULL) { @@ -576,7 +588,8 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C); { - float bandEp[st->mode->nbEBands*C]; + VARDECL(float *bandEp); + ALLOC(bandEp, st->mode->nbEBands*C, float); compute_band_energies(st->mode, P, bandEp); normalise_bands(st->mode, P, bandEp); } diff --git a/libcelt/mdct.c b/libcelt/mdct.c index cbbfc875..483a7497 100644 --- a/libcelt/mdct.c +++ b/libcelt/mdct.c @@ -80,11 +80,12 @@ void mdct_forward(mdct_lookup *l, float *in, float *out) { int i; int N, N2, N4, N8; + VARDECL(float *f); N = l->n; N2 = N/2; N4 = N/4; N8 = N/8; - float f[N2]; + ALLOC(f, N2, float); /* Consider the input to be compused of four blocks: [a, b, c, d] */ /* Shuffle, fold, pre-rotate (part 1) */ @@ -123,11 +124,12 @@ void mdct_backward(mdct_lookup *l, float *in, float *out) { int i; int N, N2, N4, N8; + VARDECL(float *f); N = l->n; N2 = N/2; N4 = N/4; N8 = N/8; - float f[N2]; + ALLOC(f, N2, float); /* Pre-rotate */ for(i=0;i #include "os_support.h" +#include "arch.h" /* The Vorbis freq<->Bark mapping */ #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)) @@ -124,8 +125,9 @@ static void spreading_func(struct PsyDecay *d, float *psd, float *mask, int len, void compute_masking(struct PsyDecay *decay, float *X, float *mask, int len, int Fs) { int i; + VARDECL(float *psd); int N=len/2; - float psd[N]; + ALLOC(psd, N, float); psd[0] = X[0]*X[0]; for (i=1;i #include "pgain_table.h" +#include "arch.h" /* Taken from Speex. Finds the index of the entry in a codebook that best matches the input*/ @@ -64,7 +65,8 @@ int vq_index(float *in, const float *codebook, int len, int entries) int quant_pitch(float *gains, int len, ec_enc *enc) { int i, id; - float g2[len]; + VARDECL(float *g2); + ALLOC(g2, len, float); /*for (i=0;ieBands; + ALLOC(bits, len, int); lo = 0; hi = 1<nbEBands; + ALLOC(bits1, len, float); + ALLOC(bits2, len, float); lo = 0; hi = m->nbAllocVectors - 1; while (hi-lo != 1) { int j; - int bits[len]; - int pulses[len]; int mid = (lo+hi) >> 1; for (j=0;jallocVectors[mid*len+j] + offsets[j])<allocVectors[mid*len+j] + offsets[j])<eBands, bits, pulses, len) > total<eBands, bits1, pulses, len) > total< #include #include @@ -100,8 +104,10 @@ int main(int argc, char *argv[]) celt_mode_info(mode, CELT_GET_NB_CHANNELS, &channels); while (!feof(fin)) { - celt_int16_t in[frame_size*channels]; - celt_int16_t out[frame_size*channels]; + VARDECL(celt_int16_t *in); + VARDECL(celt_int16_t *out); + ALLOC(in, frame_size*channels, celt_int16_t); + ALLOC(out, frame_size*channels, celt_int16_t); fread(in, sizeof(short), frame_size*channels, fin); if (feof(fin)) break;