removed // comments and added stack_alloc.h (not used everywhere yet)

to make the code more C89-friendly.
This commit is contained in:
Jean-Marc Valin 2008-02-20 11:59:30 +11:00
parent 2991af5b8e
commit a85657bd29
15 changed files with 224 additions and 107 deletions

View file

@ -23,11 +23,10 @@ libcelt_la_SOURCES = bands.c bitrdec.c bitree.c bitrenc.c celt.c cwrs.c \
libcelt_la_LDFLAGS = -version-info @CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@
noinst_HEADERS = arch.h bands.h bitrdec.h bitree.h bitrenc.h cwrs.h \
ecintrin.h entcode.h entdec.h entenc.h kiss_fft.h \
kiss_fftr.h _kiss_fft_guts.h laplace.h mdct.h \
mfrngcod.h modes.h os_support.h pgain_table.h pitch.h psy.h \
quant_bands.h quant_pitch.h rate.h vq.h
noinst_HEADERS = _kiss_fft_guts.h arch.h bands.h bitrdec.h bitree.h bitrenc.h \
cwrs.h ecintrin.h entcode.h entdec.h entenc.h kiss_fft.h kiss_fftr.h laplace.h \
mdct.h mfrngcod.h modes.h os_support.h pgain_table.h pitch.h psy.h \
quant_bands.h quant_pitch.h rate.h stack_alloc.h vq.h
noinst_PROGRAMS = testcelt
testcelt_SOURCES = testcelt.c

View file

@ -36,7 +36,7 @@
#define ARCH_H
#include "celt_types.h"
#include "stack_alloc.h"
#define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */
#define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */

View file

@ -29,6 +29,10 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include "bands.h"
#include "modes.h"
@ -81,10 +85,10 @@ void compute_band_energies(const CELTMode *m, float *X, float *bank)
for (j=B*eBands[i];j<B*eBands[i+1];j++)
sum += X[j*C+c]*X[j*C+c];
bank[i*C+c] = sqrt(C*sum);
//printf ("%f ", bank[i*C+c]);
/*printf ("%f ", bank[i*C+c]);*/
}
}
//printf ("\n");
/*printf ("\n");*/
}
/* Normalise each band such that the energy is one. */
@ -110,7 +114,8 @@ void normalise_bands(const CELTMode *m, float *X, float *bank)
void renormalise_bands(const CELTMode *m, float *X)
{
float tmpE[m->nbEBands*m->nbChannels];
VARDECL(float *tmpE);
ALLOC(tmpE, m->nbEBands*m->nbChannels, float);
compute_band_energies(m, X, tmpE);
normalise_bands(m, X, tmpE);
}
@ -143,8 +148,9 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
int i, B;
const int *eBands = m->eBands;
const int *pBands = m->pBands;
VARDECL(float *w);
B = m->nbMdctBlocks*m->nbChannels;
float w[B*eBands[m->nbEBands]];
ALLOC(w, B*eBands[m->nbEBands], float);
for (i=0;i<m->nbEBands;i++)
{
int j;
@ -165,9 +171,6 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
Sxx += X[j]*X[j]*w[j];
}
gain = Sxy/(1e-10+Sxx);
//gain = Sxy/(2*(pbank[i+1]-pbank[i]));
//if (i<3)
//gain *= 1+.02*gain;
if (gain > 1.f)
gain = 1.f;
if (gain < 0.0f)
@ -175,7 +178,7 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
/* We need to be a bit conservative, otherwise residual doesn't quantise well */
gain *= .9f;
gains[i] = gain;
//printf ("%f ", 1-sqrt(1-gain*gain));
/*printf ("%f ", 1-sqrt(1-gain*gain));*/
}
/*if(rand()%10==0)
{
@ -198,7 +201,7 @@ void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains)
int j;
for (j=B*pBands[i];j<B*pBands[i+1];j++)
P[j] *= gains[i];
//printf ("%f ", gain);
/*printf ("%f ", gain);*/
}
for (i=B*pBands[m->nbPBands];i<B*pBands[m->nbPBands+1];i++)
P[i] = 0;
@ -210,11 +213,16 @@ void quant_bands(const CELTMode *m, float *X, float *P, float *W, int total_bits
{
int i, j, B, bits;
const int *eBands = m->eBands;
B = m->nbMdctBlocks*m->nbChannels;
float norm[B*eBands[m->nbEBands+1]];
int pulses[m->nbEBands];
int offsets[m->nbEBands];
float alpha = .7;
VARDECL(float *norm);
VARDECL(int *pulses);
VARDECL(int *offsets);
B = m->nbMdctBlocks*m->nbChannels;
ALLOC(norm, B*eBands[m->nbEBands+1], float);
ALLOC(pulses, m->nbEBands, int);
ALLOC(offsets, m->nbEBands, int);
for (i=0;i<m->nbEBands;i++)
offsets[i] = 0;
@ -232,7 +240,6 @@ void quant_bands(const CELTMode *m, float *X, float *P, float *W, int total_bits
int q;
float theta, n;
q = pulses[i];
//q = m->nbPulses[i];
n = sqrt(B*(eBands[i+1]-eBands[i]));
theta = .007*(B*(eBands[i+1]-eBands[i]))/(.1f+q);
@ -258,10 +265,7 @@ void quant_bands(const CELTMode *m, float *X, float *P, float *W, int total_bits
}
for (j=B*eBands[i];j<B*eBands[i+1];j++)
norm[j] = X[j] * n;
//printf ("%f ", log2(ncwrs64(B*(eBands[i+1]-eBands[i]), q))/(B*(eBands[i+1]-eBands[i])));
//printf ("%f ", log2(ncwrs64(B*(eBands[i+1]-eBands[i]), q)));
}
//printf ("\n");
for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
X[i] = 0;
}
@ -271,11 +275,16 @@ void unquant_bands(const CELTMode *m, float *X, float *P, int total_bits, ec_dec
{
int i, j, B, bits;
const int *eBands = m->eBands;
B = m->nbMdctBlocks*m->nbChannels;
float norm[B*eBands[m->nbEBands+1]];
int pulses[m->nbEBands];
int offsets[m->nbEBands];
float alpha = .7;
VARDECL(float *norm);
VARDECL(int *pulses);
VARDECL(int *offsets);
B = m->nbMdctBlocks*m->nbChannels;
ALLOC(norm, B*eBands[m->nbEBands+1], float);
ALLOC(pulses, m->nbEBands, int);
ALLOC(offsets, m->nbEBands, int);
for (i=0;i<m->nbEBands;i++)
offsets[i] = 0;
@ -288,7 +297,6 @@ void unquant_bands(const CELTMode *m, float *X, float *P, int total_bits, ec_dec
int q;
float theta, n;
q = pulses[i];
//q = m->nbPulses[i];
n = sqrt(B*(eBands[i+1]-eBands[i]));
theta = .007*(B*(eBands[i+1]-eBands[i]))/(.1f+q);

View file

@ -45,6 +45,9 @@
#define MAX_PERIOD 1024
#ifndef M_PI
#define M_PI 3.14159263
#endif
struct CELTEncoder {
const CELTMode *mode;
@ -234,7 +237,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
for (i=0;i<st->overlap;i++)
st->in_mem[C*i+c] = in[C*(N*(B+1)-N4-st->overlap+i)+c];
}
//for (i=0;i<(B+1)*C*N;i++) printf ("%f(%d) ", in[i], i); printf ("\n");
/*for (i=0;i<(B+1)*C*N;i++) printf ("%f(%d) ", in[i], i); printf ("\n");*/
/* Compute MDCTs */
curr_power = compute_mdcts(&st->mdct_lookup, st->window, in, X, N, B, C);
@ -264,7 +267,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
/* Compute MDCTs of the pitch part */
pitch_power = compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, P, N, B, C);
//printf ("%f %f\n", curr_power, pitch_power);
/*printf ("%f %f\n", curr_power, pitch_power);*/
/*int j;
for (j=0;j<B*N;j++)
printf ("%f ", X[j]);
@ -275,8 +278,8 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
/* Band normalisation */
compute_band_energies(st->mode, X, bandE);
normalise_bands(st->mode, X, bandE);
//for (i=0;i<st->mode->nbEBands;i++)printf("%f ", bandE[i]);printf("\n");
//for (i=0;i<N*B*C;i++)printf("%f ", X[i]);printf("\n");
/*for (i=0;i<st->mode->nbEBands;i++)printf("%f ", bandE[i]);printf("\n");*/
/*for (i=0;i<N*B*C;i++)printf("%f ", X[i]);printf("\n");*/
quant_energy(st->mode, bandE, st->oldBandE, nbCompressedBytes*8/3, &st->enc);
@ -296,8 +299,8 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
if (C==2)
stereo_mix(st->mode, P, bandE, 1);
/* Simulates intensity stereo */
//for (i=30;i<N*B;i++)
// X[i*C+1] = P[i*C+1] = 0;
/*for (i=30;i<N*B;i++)
X[i*C+1] = P[i*C+1] = 0;*/
/* Pitch prediction */
compute_pitch_gain(st->mode, X, P, gains, bandE);
@ -316,7 +319,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
pitch_quant_bands(st->mode, X, P, gains);
//for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n");
/*for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n");*/
/* Compute residual that we're going to encode */
for (i=0;i<B*C*N;i++)
X[i] -= P[i];
@ -358,7 +361,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 7)
celt_warning_int ("many unused bits: ", nbCompressedBytes*8-ec_enc_tell(&st->enc, 0));
//printf ("%d\n", ec_enc_tell(&st->enc, 0)-8*nbCompressedBytes);
/*printf ("%d\n", ec_enc_tell(&st->enc, 0)-8*nbCompressedBytes);*/
/* Finishing the stream with a 0101... pattern so that the decoder can check is everything's right */
{
int val = 0;
@ -377,7 +380,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
celt_warning_int ("got too many bytes:", nbBytes);
return CELT_INTERNAL_ERROR;
}
//printf ("%d\n", *nbBytes);
/*printf ("%d\n", *nbBytes);*/
data = ec_byte_get_buffer(&st->buf);
for (i=0;i<nbBytes;i++)
compressed[i] = data[i];
@ -621,6 +624,6 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
}
return 0;
//printf ("\n");
/*printf ("\n");*/
}

View file

@ -67,7 +67,7 @@ void ec_laplace_encode(ec_enc *enc, int value, int decay)
fl = 0;
if (s)
fl += fs;
//printf ("enc: %d %d %d\n", fl, fs, ft);
/*printf ("enc: %d %d %d\n", fl, fs, ft);*/
ec_encode(enc, fl, fl+fs, ft);
}
@ -78,7 +78,7 @@ int ec_laplace_decode(ec_dec *dec, int decay)
ft = ec_laplace_get_total(decay);
fm = ec_decode(dec, ft);
//printf ("fm: %d/%d\n", fm, ft);
/*printf ("fm: %d/%d\n", fm, ft);*/
fl = 0;
fs = 1<<15;
fh = fs;

View file

@ -47,6 +47,10 @@
#include <math.h>
#include "os_support.h"
#ifndef M_PI
#define M_PI 3.14159263
#endif
void mdct_init(mdct_lookup *l,int N)
{
int i;

View file

@ -91,14 +91,14 @@ static int *compute_ebands(int Fs, int frame_size, int *nbEBands)
int i, res, min_width, lin, low, high;
res = (Fs+frame_size)/(2*frame_size);
min_width = MIN_BINS*res;
//printf ("min_width = %d\n", min_width);
/*printf ("min_width = %d\n", min_width);*/
/* Find where the linear part ends (i.e. where the spacing is more than min_width */
for (lin=0;lin<BARK_BANDS;lin++)
if (bark_freq[lin+1]-bark_freq[lin] >= min_width)
break;
//printf ("lin = %d (%d Hz)\n", lin, bark_freq[lin]);
/*printf ("lin = %d (%d Hz)\n", lin, bark_freq[lin]);*/
low = ((bark_freq[lin]/res)+(MIN_BINS-1))/MIN_BINS;
high = BARK_BANDS-lin;
*nbEBands = low+high;
@ -145,7 +145,7 @@ static void compute_pbands(CELTMode *mode, int res)
for (j=0;j<mode->nbEBands;j++)
if (mode->eBands[j] <= pBands[i] && mode->eBands[j+1] > pBands[i])
break;
//printf ("%d %d\n", i, j);
/*printf ("%d %d\n", i, j);*/
if (mode->eBands[j] != pBands[i])
{
if (pBands[i]-mode->eBands[j] < mode->eBands[j+1]-pBands[i] &&
@ -181,7 +181,6 @@ static void compute_allocation_table(CELTMode *mode, int res)
int num, den;
num = band_allocation[i*BARK_BANDS+j] * (edge-bark_freq[j]);
den = bark_freq[j+1]-bark_freq[j];
//low = band_allocation[i*BARK_BANDS+j] * (edge-bark_freq[j])/(bark_freq[j+1]-bark_freq[j]);
low = (num+den/2)/den;
allocVectors[i*mode->nbEBands+eband] += low;
eband++;
@ -250,7 +249,7 @@ CELTMode *celt_mode_create(int Fs, int channels, int frame_size, int lookahead,
compute_allocation_table(mode, res);
compute_alloc_cache(mode);
//printf ("%d bands\n", mode->nbEBands);
/*printf ("%d bands\n", mode->nbEBands);*/
return mode;
}

View file

@ -56,10 +56,10 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, float *x, fl
for (i=1;i<C*n2;i++)
{
float n;
//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/(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]);
/*n = 1.f/(1+curve[i]);*/
float 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;
@ -68,18 +68,17 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, float *x, fl
kiss_fftri(fft, X, xx);
float max_corr=-1e10;
//int pitch;
*pitch = 0;
for (i=0;i<lag-len;i++)
{
//printf ("%f ", xx[i]);
/*printf ("%f ", xx[i]);*/
if (xx[i] > max_corr)
{
*pitch = i;
max_corr = xx[i];
}
}
//printf ("\n");
//printf ("%d %f\n", *pitch, max_corr);
//printf ("%d\n", *pitch);
/*printf ("\n");
printf ("%d %f\n", *pitch, max_corr);
printf ("%d\n", *pitch);*/
}

View file

@ -61,7 +61,7 @@ void psydecay_init(struct PsyDecay *decay, int len, int Fs)
decay->decayR[i] = pow(.1f, deriv);
/* decay corresponding to -25dB/Bark */
decay->decayL[i] = pow(0.0031623f, deriv);
//printf ("%f %f\n", decayL[i], decayR[i]);
/*printf ("%f %f\n", decayL[i], decayR[i]);*/
}
}
@ -75,7 +75,7 @@ static void spreading_func(struct PsyDecay *d, float *psd, float *mask, int len,
{
int i;
float mem;
//for (i=0;i<len;i++) printf ("%f ", psd[i]);
/*for (i=0;i<len;i++) printf ("%f ", psd[i]);*/
/* Compute right slope (-10 dB/Bark) */
mem=psd[0];
for (i=0;i<len;i++)
@ -90,7 +90,7 @@ static void spreading_func(struct PsyDecay *d, float *psd, float *mask, int len,
mask[i] = (1-d->decayR[i])*mask[i] + d->decayL[i]*mem;
mem = mask[i];
}
//for (i=0;i<len;i++) printf ("%f ", mask[i]); printf ("\n");
/*for (i=0;i<len;i++) printf ("%f ", mask[i]); printf ("\n");*/
#if 0 /* Prints signal and mask energy per critical band */
for (i=0;i<25;i++)
{
@ -139,7 +139,7 @@ void compute_mdct_masking(struct PsyDecay *decay, float *X, float *mask, int len
mask[i] = X[i]*X[i];
for (i=1;i<len-1;i++)
psd[i] = .5*mask[i] + .25*(mask[i-1]+mask[i+1]);
//psd[0] = .5*mask[0]+.25*(mask[1]+mask[2]);
/*psd[0] = .5*mask[0]+.25*(mask[1]+mask[2]);*/
psd[0] = .5*mask[0]+.5*mask[1];
psd[len-1] = .5*(mask[len-1]+mask[len-2]);
/* TODO: Do tone masking */

View file

@ -37,7 +37,7 @@
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};
//const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
/*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc)
@ -60,13 +60,10 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
float mean = (1-coef)*eMeans[i];
x = 20*log10(.3+eBands[i]);
res = 6.;
//res = 1;
f = (x-mean-coef*oldEBands[i]-prev)/res;
qi = (int)floor(.5+f);
//if (i> 4 && qi<-2)
// qi = -2;
//ec_laplace_encode(enc, qi, i==0?11192:6192);
//ec_laplace_encode(enc, qi, 8500-i*200);
/*ec_laplace_encode(enc, qi, i==0?11192:6192);*/
/*ec_laplace_encode(enc, qi, 8500-i*200);*/
/* If we don't have enough bits to encode all the energy, just assume something safe. */
if (ec_enc_tell(enc, 0) - bits > budget)
qi = -1;
@ -75,16 +72,16 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
q = qi*res;
error[i] = f - qi;
//printf("%d ", qi);
//printf("%f %f ", pred+prev+q, x);
//printf("%f ", x-pred);
/*printf("%d ", qi);*/
/*printf("%f %f ", pred+prev+q, x);*/
/*printf("%f ", x-pred);*/
oldEBands[i] = mean+coef*oldEBands[i]+prev+q;
prev = mean+prev+(1-beta)*q;
}
//bits = ec_enc_tell(enc, 0) - bits;
//printf ("%d\n", bits);
/*bits = ec_enc_tell(enc, 0) - bits;*/
/*printf ("%d\n", bits);*/
for (i=0;i<m->nbEBands;i++)
{
int q2;
@ -98,7 +95,7 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
ec_enc_uint(enc, q2, frac[i]);
offset = ((q2+.5)/frac[i])-.5;
oldEBands[i] += 6.*offset;
//printf ("%f ", error[i] - offset);
/*printf ("%f ", error[i] - offset);*/
}
for (i=0;i<m->nbEBands;i++)
{
@ -106,9 +103,9 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
if (eBands[i] < 0)
eBands[i] = 0;
}
//printf ("%d\n", ec_enc_tell(enc, 0)-9);
/*printf ("%d\n", ec_enc_tell(enc, 0)-9);*/
//printf ("\n");
/*printf ("\n");*/
}
static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec)
@ -150,12 +147,12 @@ static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBan
}
for (i=0;i<m->nbEBands;i++)
{
//printf ("%f ", error[i] - offset);
/*printf ("%f ", error[i] - offset);*/
eBands[i] = pow(10, .05*oldEBands[i])-.3;
if (eBands[i] < 0)
eBands[i] = 0;
}
//printf ("\n");
/*printf ("\n");*/
}

View file

@ -61,12 +61,12 @@ int quant_pitch(float *gains, int len, ec_enc *enc)
{
int i, id;
float g2[len];
//for (i=0;i<len;i++) printf ("%f ", gains[i]);printf ("\n");
/*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]);
id = vq_index(g2, pgain_table, len, 128);
ec_enc_uint(enc, id, 128);
//for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");
/*for (i=0;i<len;i++) printf ("%f ", pgain_table[id*len+i]);printf ("\n");*/
for (i=0;i<len;i++)
gains[i] = (sqrt(1-(1-pgain_table[id*len+i])*(1-pgain_table[id*len+i])));
return id!=0;

View file

@ -49,17 +49,17 @@ static int log2_frac(ec_uint32 val, int frac)
int i;
/* EC_ILOG() actually returns log2()+1, go figure */
int L = EC_ILOG(val)-1;
//printf ("in: %d %d ", val, L);
/*printf ("in: %d %d ", val, L);*/
if (L>14)
val >>= L-14;
else if (L<14)
val <<= 14-L;
L <<= frac;
//printf ("%d\n", val);
/*printf ("%d\n", val);*/
for (i=0;i<frac;i++)
{
val = (val*val) >> 15;
//printf ("%d\n", val);
/*printf ("%d\n", val);*/
if (val > 16384)
L |= (1<<(frac-i-1));
else
@ -73,17 +73,17 @@ static int log2_frac64(ec_uint64 val, int frac)
int i;
/* EC_ILOG64() actually returns log2()+1, go figure */
int L = EC_ILOG64(val)-1;
//printf ("in: %d %d ", val, L);
/*printf ("in: %d %d ", val, L);*/
if (L>14)
val >>= L-14;
else if (L<14)
val <<= 14-L;
L <<= frac;
//printf ("%d\n", val);
/*printf ("%d\n", val);*/
for (i=0;i<frac;i++)
{
val = (val*val) >> 15;
//printf ("%d\n", val);
/*printf ("%d\n", val);*/
if (val > 16384)
L |= (1<<(frac-i-1));
else
@ -179,7 +179,7 @@ int vec_bits2pulses(const CELTMode *m, const int *bands, int *bits, int *pulses,
pulses[i] = bits2pulses(m, i, bits[i]);
sum += m->bits[i][pulses[i]];
}
//printf ("sum = %d\n", sum);
/*printf ("sum = %d\n", sum);*/
return sum;
}
@ -201,7 +201,7 @@ int interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int total, int
else
lo = mid;
}
//printf ("interp bisection gave %d\n", lo);
/*printf ("interp bisection gave %d\n", lo);*/
for (j=0;j<len;j++)
bits[j] = ((1<<BITRES)-lo)*bits1[j] + lo*bits2[j];
out = vec_bits2pulses(m, bands, bits, pulses, len);
@ -220,7 +220,6 @@ int interp_bits2pulses(const CELTMode *m, int *bits1, int *bits2, int total, int
out = out+m->bits[j][pulses[j]+1]-m->bits[j][pulses[j]];
pulses[j] += 1;
incremented = 1;
//printf ("INCREMENT %d\n", j);
}
}
}
@ -253,14 +252,14 @@ int compute_allocation(const CELTMode *m, int *offsets, int total, int *pulses)
bits[j] = (m->allocVectors[mid*len+j] + offsets[j])<<BITRES;
if (bits[j] < 0)
bits[j] = 0;
//printf ("%d ", bits[j]);
/*printf ("%d ", bits[j]);*/
}
//printf ("\n");
/*printf ("\n");*/
if (vec_bits2pulses(m, m->eBands, bits, pulses, len) > total<<BITRES)
hi = mid;
else
lo = mid;
//printf ("lo = %d, hi = %d\n", lo, hi);
/*printf ("lo = %d, hi = %d\n", lo, hi);*/
}
{
int bits1[len];

115
libcelt/stack_alloc.h Normal file
View file

@ -0,0 +1,115 @@
/* Copyright (C) 2002 Jean-Marc Valin */
/**
@file stack_alloc.h
@brief Temporary memory allocation on stack
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef STACK_ALLOC_H
#define STACK_ALLOC_H
#ifdef USE_ALLOCA
# ifdef WIN32
# include <malloc.h>
# else
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# include <stdlib.h>
# endif
# endif
#endif
/**
* @def ALIGN(stack, size)
*
* Aligns the stack to a 'size' boundary
*
* @param stack Stack
* @param size New size boundary
*/
/**
* @def PUSH(stack, size, type)
*
* Allocates 'size' elements of type 'type' on the stack
*
* @param stack Stack
* @param size Number of elements
* @param type Type of element
*/
/**
* @def VARDECL(var)
*
* Declare variable on stack
*
* @param var Variable to declare
*/
/**
* @def ALLOC(var, size, type)
*
* Allocate 'size' elements of 'type' on stack
*
* @param var Name of variable to allocate
* @param size Number of elements
* @param type Type of element
*/
#ifdef ENABLE_VALGRIND
#include <valgrind/memcheck.h>
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
#else
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
#endif
#if defined(VAR_ARRAYS)
#define VARDECL(var)
#define ALLOC(var, size, type) type var[size]
#elif defined(USE_ALLOCA)
#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)
#endif
#endif

View file

@ -92,7 +92,6 @@ int main(int argc, char *argv[])
return 1;
}
//mode = celt_mode_create(44100, 1, 192, 64);
/* Use mode4 for stereo and don't forget to change the value of CHANNEL above */
enc = celt_encoder_new(mode);
dec = celt_decoder_new(mode);
@ -112,8 +111,6 @@ int main(int argc, char *argv[])
fprintf (stderr, "celt_encode() returned %d\n", len);
return 1;
}
//printf ("\n");
//printf ("%d\n", len);
/* This is to simulate packet loss */
#if 1
if (rand()%100==-1)
@ -124,7 +121,6 @@ int main(int argc, char *argv[])
for (i=0;i<frame_size*channels;i++)
out[i] = in[i];
#endif
//printf ("\n");
for (i=0;i<frame_size*channels;i++)
rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]);
count++;

View file

@ -70,10 +70,8 @@ struct NBest {
void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *enc)
{
int L = 3;
//float tata[200];
float _y[L][N];
int _iy[L][N];
//float tata2[200];
float _ny[L][N];
int _iny[L][N];
float *(ny[L]), *(y[L]);
@ -125,7 +123,7 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
pulsesAtOnce = 1;
if (pulsesLeft-pulsesAtOnce > 3 || N > 30)
Lupdate = 1;
//printf ("%d %d %d/%d %d\n", Lupdate, pulsesAtOnce, pulsesLeft, K, N);
/*printf ("%d %d %d/%d %d\n", Lupdate, pulsesAtOnce, pulsesLeft, K, N);*/
L2 = Lupdate;
if (L2>maxL)
{
@ -147,7 +145,7 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
/* 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);
/*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;
@ -232,8 +230,8 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
float err=0;
for (i=0;i<N;i++)
err += (x[i]-nbest[0]->gain*y[0][i])*(x[i]-nbest[0]->gain*y[0][i]);
//if (N<=10)
//printf ("%f %d %d\n", err, K, N);
/*if (N<=10)
printf ("%f %d %d\n", err, K, N);*/
}
for (i=0;i<N;i++)
x[i] = p[i]+nbest[0]->gain*y[0][i];
@ -243,11 +241,11 @@ void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *
int ABS = 0;
for (i=0;i<N;i++)
ABS += abs(iy[0][i]);
//if (K != ABS)
// printf ("%d %d\n", K, ABS);
/*if (K != ABS)
printf ("%d %d\n", K, ABS);*/
for (i=0;i<N;i++)
E += x[i]*x[i];
//printf ("%f\n", E);
/*printf ("%f\n", E);*/
E = 1/sqrt(E);
for (i=0;i<N;i++)
x[i] *= E;
@ -295,8 +293,8 @@ void alg_unquant(float *x, int N, int K, float *p, float alpha, ec_dec *dec)
decode_pulses(iy, N, K, dec);
//for (i=0;i<N;i++)
// printf ("%d ", iy[i]);
/*for (i=0;i<N;i++)
printf ("%d ", iy[i]);*/
for (i=0;i<N;i++)
Rpp += p[i]*p[i];
@ -360,10 +358,10 @@ void intra_prediction(float *x, float *W, int N, int K, float *Y, float *P, int
sign = 1;
else
sign = 0;
//printf ("%d %d ", sign, best);
/*printf ("%d %d ", sign, best);*/
ec_enc_uint(enc,sign,2);
ec_enc_uint(enc,best/B,max_pos);
//printf ("%d %f\n", best, best_score);
/*printf ("%d %f\n", best, best_score);*/
float pred_gain;
if (K>10)
@ -387,8 +385,8 @@ void intra_prediction(float *x, float *W, int N, int K, float *Y, float *P, int
for (j=0;j<N;j++)
x[j] = P[j];
}
//printf ("quant ");
//for (j=0;j<N;j++) printf ("%f ", P[j]);
/*printf ("quant ");*/
/*for (j=0;j<N;j++) printf ("%f ", P[j]);*/
}
@ -410,7 +408,7 @@ void intra_unquant(float *x, int N, int K, float *Y, float *P, int B, int N0, ec
s = -1;
best = B*ec_dec_uint(dec, max_pos);
//printf ("%d %d ", sign, best);
/*printf ("%d %d ", sign, best);*/
float pred_gain;
if (K>10)