Another bunch of C99 array conversions (few more to go)

This commit is contained in:
Jean-Marc Valin 2008-02-20 13:43:40 +11:00
parent d3b86e5347
commit 0bb05bc5ea
8 changed files with 80 additions and 48 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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<N4;i++)

View file

@ -31,14 +31,18 @@
void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, float *x, float *y, int lag, int len, int C, int *pitch)
{
int c;
int c, i;
VARDECL(float *xx);
VARDECL(float *yy);
VARDECL(float *X);
VARDECL(float *Y);
VARDECL(float *curve);
int n2 = lag/2;
float xx[lag*C];
float yy[lag*C];
float X[lag*C];
float Y[lag*C];
float curve[n2*C];
int i;
ALLOC(xx, lag*C, float);
ALLOC(yy, lag*C, float);
ALLOC(X, lag*C, float);
ALLOC(Y, lag*C, float);
ALLOC(curve, n2*C, float);
for (i=0;i<C*lag;i++)
xx[i] = 0;

View file

@ -36,6 +36,7 @@
#include "psy.h"
#include <math.h>
#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<N;i++)
psd[i] = X[i*2]*X[i*2] + X[i*2+1]*X[i*2+1];
@ -138,7 +140,8 @@ void compute_masking(struct PsyDecay *decay, float *X, float *mask, int len, int
void compute_mdct_masking(struct PsyDecay *decay, float *X, float *mask, int len, int Fs)
{
int i;
float psd[len];
VARDECL(float *psd);
ALLOC(psd, len, float);
for (i=0;i<len;i++)
mask[i] = X[i]*X[i];
for (i=1;i<len-1;i++)

View file

@ -36,6 +36,7 @@
#include "quant_pitch.h"
#include <math.h>
#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;i<len;i++) printf ("%f ", gains[i]);printf ("\n");*/
for (i=0;i<len;i++)
g2[i] = 1-sqrt(1-gains[i]*gains[i]);

View file

@ -191,8 +191,10 @@ int interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int total, int
{
int lo, hi, out;
int j;
int bits[len];
int firstpass;
VARDECL(int *bits);
const int *bands = m->eBands;
ALLOC(bits, len, int);
lo = 0;
hi = 1<<BITRES;
while (hi-lo != 1)
@ -211,7 +213,7 @@ int interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int total, int
out = vec_bits2pulses(m, bands, bits, pulses, len);
/* Do some refinement to use up all bits. In the first pass, we can only add pulses to
bands that are under their allocated budget. In the second pass, anything goes */
int firstpass = 1;
firstpass = 1;
while(1)
{
int incremented = 0;
@ -241,33 +243,33 @@ int interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int total, int
int compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses)
{
int lo, hi, len;
VARDECL(int *bits1);
VARDECL(int *bits2);
len = m->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;j<len;j++)
{
bits[j] = (m->allocVectors[mid*len+j] + offsets[j])<<BITRES;
if (bits[j] < 0)
bits[j] = 0;
bits1[j] = (m->allocVectors[mid*len+j] + offsets[j])<<BITRES;
if (bits1[j] < 0)
bits1[j] = 0;
/*printf ("%d ", bits[j]);*/
}
/*printf ("\n");*/
if (vec_bits2pulses(m, m->eBands, bits, pulses, len) > total<<BITRES)
if (vec_bits2pulses(m, m->eBands, bits1, pulses, len) > total<<BITRES)
hi = mid;
else
lo = mid;
/*printf ("lo = %d, hi = %d\n", lo, hi);*/
}
{
int bits1[len];
int bits2[len];
int j;
for (j=0;j<len;j++)
{

View file

@ -29,8 +29,12 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "celt.h"
#include "arch.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@ -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;