diff --git a/libcelt/pitch.c b/libcelt/pitch.c
index 474f368f79b10aa6030089950ce3d692b170bf4d..38932f0ba36c592ebb1dff54036e0261526b4020 100644
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -32,6 +32,7 @@
 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, i;
+   float max_corr;
    VARDECL(float *xx);
    VARDECL(float *yy);
    VARDECL(float *X);
@@ -62,19 +63,19 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, float *x, fl
    
    for (i=1;i<C*n2;i++)
    {
-      float n;
+      float n, tmp;
       /*n = 1.f/(1e1+sqrt(sqrt((X[2*i-1]*X[2*i-1] + X[2*i  ]*X[2*i  ])*(Y[2*i-1]*Y[2*i-1] + Y[2*i  ]*Y[2*i  ]))));*/
       /*n = 1;*/
       n = 1.f/sqrt(1+curve[i]);
       /*n = 1.f/(1+curve[i]);*/
-      float tmp = X[2*i];
+      tmp = X[2*i];
       X[2*i] = (X[2*i  ]*Y[2*i  ] + X[2*i+1]*Y[2*i+1])*n;
       X[2*i+1] = (- X[2*i+1]*Y[2*i  ] + tmp*Y[2*i+1])*n;
    }
    X[0] = X[1] = 0;
    kiss_fftri(fft, X, xx);
    
-   float max_corr=-1e10;
+   max_corr=-1e10;
    *pitch = 0;
    for (i=0;i<lag-len;i++)
    {
diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c
index 5ea71c94aaf920159b1604e78b7ac30424e9dfa4..2c73eba9142c9ddfe6f1367b40396644c611bcd2 100644
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -37,6 +37,7 @@
 #include "laplace.h"
 #include <math.h>
 #include "os_support.h"
+#include "arch.h"
 
 const float eMeans[24] = {45.f, -8.f, -12.f, -2.5f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
 
@@ -49,9 +50,11 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
    int bits;
    float prev = 0;
    float coef = m->ePredCoef;
-   float error[m->nbEBands];
+   VARDECL(float *error);
    /* The .7 is a heuristic */
    float beta = .7*coef;
+   
+   ALLOC(error, m->nbEBands, float);
    bits = ec_enc_tell(enc, 0);
    for (i=0;i<m->nbEBands;i++)
    {
@@ -172,10 +175,11 @@ void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget
 #if 1
    {
       int c;
+      VARDECL(float *E);
+      ALLOC(E, m->nbEBands, float);
       for (c=0;c<C;c++)
       {
          int i;
-         float E[m->nbEBands];
          for (i=0;i<m->nbEBands;i++)
             E[i] = eBands[C*i+c];
          quant_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, enc);
@@ -230,10 +234,11 @@ void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budg
       unquant_energy_mono(m, eBands, oldEBands, budget, dec);
    else {
       int c;
+      VARDECL(float *E);
+      ALLOC(E, m->nbEBands, float);
       for (c=0;c<C;c++)
       {
          int i;
-         float E[m->nbEBands];
          unquant_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, dec);
          for (i=0;i<m->nbEBands;i++)
             eBands[C*i+c] = E[i];
diff --git a/libcelt/rate.c b/libcelt/rate.c
index a2b7a9844f2b5a05bd0c85df5414d9d1624d90e9..b7d8c1a387eac1726b54cca9b5f40ce58847e25b 100644
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -247,8 +247,8 @@ int compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses)
    VARDECL(int *bits2);
    
    len = m->nbEBands;
-   ALLOC(bits1, len, float);
-   ALLOC(bits2, len, float);
+   ALLOC(bits1, len, int);
+   ALLOC(bits2, len, int);
    lo = 0;
    hi = m->nbAllocVectors - 1;
    while (hi-lo != 1)
diff --git a/libcelt/stack_alloc.h b/libcelt/stack_alloc.h
index 5264e666b04bca98172e38eff938483dbacc56ca..1e643c6647d272f702ad9c5fa69315170cd5b728 100644
--- a/libcelt/stack_alloc.h
+++ b/libcelt/stack_alloc.h
@@ -107,8 +107,9 @@
 #define VARDECL(var) var
 #define ALLOC(var, size, type) var = alloca(sizeof(type)*(size))
 #else
-#define VARDECL(var) var
-#define ALLOC(var, size, type) var = PUSH(stack, size, type)
+/*#define VARDECL(var) var
+#define ALLOC(var, size, type) var = PUSH(stack, size, type)*/
+#error scratchpad not yet supported, you need to define either VAR_ARRAYS or USE_ALLOCA
 #endif
 
 
diff --git a/libcelt/vq.c b/libcelt/vq.c
index 5f6e4d806670c15f598881a3454a02ac66ba65f9..57969baac564bb32411be43f9ddfb4e1a8ebaa36 100644
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include "cwrs.h"
 #include "vq.h"
+#include "arch.h"
 
 /* Enable this or define your own implementation if you want to speed up the
    VQ search (used in inner loop only) */
@@ -74,31 +75,48 @@ struct NBest {
 void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *enc)
 {
    int L = 3;
-   float _y[L][N];
-   int _iy[L][N];
-   float _ny[L][N];
-   int _iny[L][N];
-   float *(ny[L]), *(y[L]);
-   int *(iny[L]), *(iy[L]);
+   VARDECL(float *_y);
+   VARDECL(float *_ny);
+   VARDECL(int *_iy);
+   VARDECL(int *_iny);
+   VARDECL(float **y);
+   VARDECL(float **ny);
+   VARDECL(int **iy);
+   VARDECL(int **iny);
    int i, j, k, m;
    int pulsesLeft;
-   float xy[L];
-   float yy[L];
-   float yp[L];
-   struct NBest _nbest[L];
-   struct NBest *(nbest[L]);
+   VARDECL(float *xy);
+   VARDECL(float *yy);
+   VARDECL(float *yp);
+   VARDECL(struct NBest *_nbest);
+   VARDECL(struct NBest **nbest);
    float Rpp=0, Rxp=0;
    int maxL = 1;
    
+   ALLOC(_y, L*N, float);
+   ALLOC(_ny, L*N, float);
+   ALLOC(_iy, L*N, int);
+   ALLOC(_iny, L*N, int);
+   ALLOC(y, L*N, float*);
+   ALLOC(ny, L*N, float*);
+   ALLOC(iy, L*N, int*);
+   ALLOC(iny, L*N, int*);
+   
+   ALLOC(xy, L, float);
+   ALLOC(yy, L, float);
+   ALLOC(yp, L, float);
+   ALLOC(_nbest, L, struct NBest);
+   ALLOC(nbest, L, struct NBest *);
+
    for (m=0;m<L;m++)
       nbest[m] = &_nbest[m];
    
    for (m=0;m<L;m++)
    {
-      ny[m] = _ny[m];
-      iny[m] = _iny[m];
-      y[m] = _y[m];
-      iy[m] = _iy[m];
+      ny[m] = &_ny[m*N];
+      iny[m] = &_iny[m*N];
+      y[m] = &_y[m*N];
+      iy[m] = &_iy[m*N];
    }
    
    for (j=0;j<N;j++)
@@ -146,15 +164,16 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
             /*if (x[j]>0) sign=1; else sign=-1;*/
             for (sign=-1;sign<=1;sign+=2)
             {
-               /* All pulses at one location must have the same sign. */
-               if (iy[m][j]*sign < 0)
-                  continue;
                /*fprintf (stderr, "%d/%d %d/%d %d/%d\n", i, K, m, L2, j, N);*/
                float tmp_xy, tmp_yy, tmp_yp;
                float score;
                float g;
                float s = sign*pulsesAtOnce;
                
+               /* All pulses at one location must have the same sign. */
+               if (iy[m][j]*sign < 0)
+                  continue;
+
                /* Updating the sums of the new pulse(s) */
                tmp_xy = xy[m] + s*x[j]               - alpha*s*p[j]*Rxp;
                tmp_yy = yy[m] + 2.f*s*y[m][j] + s*s      +s*s*alpha*alpha*p[j]*p[j]*Rpp - 2.f*alpha*s*p[j]*yp[m] - 2.f*s*s*alpha*p[j]*p[j];
@@ -290,10 +309,13 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
 void alg_unquant(float *x, int N, int K, float *p, float alpha, ec_dec *dec)
 {
    int i;
-   int iy[N];
-   float y[N];
    float Rpp=0, Ryp=0, Ryy=0;
    float g;
+   VARDECL(int *iy);
+   VARDECL(float *y);
+   
+   ALLOC(iy, N, int);
+   ALLOC(y, N, float);
 
    decode_pulses(iy, N, K, dec);
 
@@ -333,6 +355,7 @@ void intra_prediction(float *x, float *W, int N, int K, float *Y, float *P, int
    float s = 1;
    int sign;
    float E;
+   float pred_gain;
    int max_pos = N0-N/B;
    if (max_pos > 32)
       max_pos = 32;
@@ -367,7 +390,6 @@ void intra_prediction(float *x, float *W, int N, int K, float *Y, float *P, int
    ec_enc_uint(enc,best/B,max_pos);
    /*printf ("%d %f\n", best, best_score);*/
    
-   float pred_gain;
    if (K>10)
       pred_gain = pg[10];
    else
@@ -401,6 +423,7 @@ void intra_unquant(float *x, int N, int K, float *Y, float *P, int B, int N0, ec
    float s;
    int best;
    float E;
+   float pred_gain;
    int max_pos = N0-N/B;
    if (max_pos > 32)
       max_pos = 32;
@@ -414,7 +437,6 @@ void intra_unquant(float *x, int N, int K, float *Y, float *P, int B, int N0, ec
    best = B*ec_dec_uint(dec, max_pos);
    /*printf ("%d %d ", sign, best);*/
 
-   float pred_gain;
    if (K>10)
       pred_gain = pg[10];
    else
diff --git a/tests/cwrs32-test.c b/tests/cwrs32-test.c
index 202c5dd435a3de635e5cdf279878a29a6375352e..0ea7e44ffdbecfec7fe8721940b46805e06d1b7b 100644
--- a/tests/cwrs32-test.c
+++ b/tests/cwrs32-test.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include "cwrs.h"
 
diff --git a/tests/cwrs64-test.c b/tests/cwrs64-test.c
index 472095cf419d83d7c9ffc87aad3093594cda5d5f..eccc5ce7300fcbc516706c523555e83e78ae9ae1 100644
--- a/tests/cwrs64-test.c
+++ b/tests/cwrs64-test.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include "cwrs.h"
 #define NMAX (32)
diff --git a/tests/dft-test.c b/tests/dft-test.c
index d348d32c01d1c7634dafd6b50544eed26e6a4f08..c314267704b97a78c87ffd468cf6e6562ff22f2e 100644
--- a/tests/dft-test.c
+++ b/tests/dft-test.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include "kiss_fft.h"
 
diff --git a/tests/ectest.c b/tests/ectest.c
index a03ad2c17625b9b33479659c1103163a6dc6ee2a..cf935c1dd968c01bc4c6de4d493676b3b239acb9 100644
--- a/tests/ectest.c
+++ b/tests/ectest.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
diff --git a/tests/real-fft-test.c b/tests/real-fft-test.c
index 1295d0c13509e0cc029ddb779cf0064ae786cd36..c85890d003b861ba9fde7e02ef6ded3f5bc467ec 100644
--- a/tests/real-fft-test.c
+++ b/tests/real-fft-test.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "kiss_fftr.h"
 #include "_kiss_fft_guts.h"
 #include <sys/times.h>
diff --git a/tests/type-test.c b/tests/type-test.c
index 58dfbd8e68770a8adfb114ebfbfc177149a91cb9..792b155fc3e47dc4aa56573116ed2c90a0da4960 100644
--- a/tests/type-test.c
+++ b/tests/type-test.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "celt_types.h"
 #include <stdio.h>