shithub: opus

Download patch

ref: 0bb05bc5ead56bacad2ed65d44f9e0e5c6cd47ef
parent: d3b86e53479266d0e27c86f0e0a8dea6dfe3a284
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 20 08:43:40 EST 2008

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

--- a/configure.ac
+++ b/configure.ac
@@ -5,9 +5,9 @@
 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
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -214,18 +214,23 @@
 {
    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 @@
    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 @@
 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 @@
 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 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 @@
    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);
    }
--- a/libcelt/mdct.c
+++ b/libcelt/mdct.c
@@ -80,11 +80,12 @@
 {
    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 @@
 {
    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++) 
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -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;
--- a/libcelt/psy.c
+++ b/libcelt/psy.c
@@ -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 @@
 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_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++)
--- a/libcelt/quant_pitch.c
+++ b/libcelt/quant_pitch.c
@@ -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 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]);
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -191,8 +191,10 @@
 {
    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 @@
    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,25 +243,27 @@
 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;
@@ -266,8 +270,6 @@
       /*printf ("lo = %d, hi = %d\n", lo, hi);*/
    }
    {
-      int bits1[len];
-      int bits2[len];
       int j;
       for (j=0;j<len;j++)
       {
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -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 @@
    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;