ref: 9a0bba183ce20157ec4e421ef74c6f2605082df4
parent: 0bb05bc5ead56bacad2ed65d44f9e0e5c6cd47ef
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 20 09:08:50 EST 2008
Everything should now compile with a C89 compiler.
--- 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,12 +63,12 @@
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;
}
@@ -74,7 +75,7 @@
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++)
{
--- 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 @@
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 @@
#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 @@
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];
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -247,8 +247,8 @@
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)
--- 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
--- 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 @@
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,9 +164,6 @@
/*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;
@@ -155,6 +170,10 @@
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_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 @@
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 @@
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 @@
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 @@
best = B*ec_dec_uint(dec, max_pos);
/*printf ("%d %d ", sign, best);*/
- float pred_gain;
if (K>10)
pred_gain = pg[10];
else
--- 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"
--- 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)
--- 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"
--- 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>
--- 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>
--- 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>