diff --git a/libcelt/bands.c b/libcelt/bands.c index 30021a6e..6fbcf54e 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -33,7 +33,11 @@ #include "bands.h" const int qbank[NBANDS+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128}; +int qpulses[] = {4, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 0, 0, 0}; //c: 134 bits +#define WAVEFORM_END 52 +/* Start frequency of each band */ +int pbank[] = {0, 4, 8, 12, 20, WAVEFORM_END, 128}; /* Compute the energy in each of the bands */ void compute_bands(float *X, int B, float *bank) @@ -56,7 +60,7 @@ void normalise_bands(float *X, int B, float *bank) for (i=0;i .90) + gain = .90; + if (gain < 0.0) + gain = 0.0; + + gains[i] = gain; + } + for (i=B*pbank[PBANDS];iin_mem = celt_alloc(N*sizeof(float)); st->mdct_overlap = celt_alloc(N*sizeof(float)); st->out_mem = celt_alloc(MAX_PERIOD*sizeof(float)); - st->bandE = celt_alloc(NBANDS*sizeof(float)); for (i=0;iwindow[i] = st->window[2*N-i-1] = sin(.5*M_PI* sin(.5*M_PI*(i+.5)/N) * sin(.5*M_PI*(i+.5)/N)); return st; @@ -99,8 +96,6 @@ void celt_encoder_destroy(CELTState *st) celt_free(st->mdct_overlap); celt_free(st->out_mem); - celt_free(st->bandE); - celt_free(st); } @@ -131,6 +126,9 @@ int celt_encode(CELTState *st, short *pcm) float X[B*N]; /**< Interleaved signal MDCTs */ float P[B*N]; /**< Interleaved pitch MDCTs*/ + float bandEp[NBANDS]; + float bandE[NBANDS]; + float gains[PBANDS]; int pitch_index; /* FIXME: Add preemphasis */ @@ -164,18 +162,34 @@ int celt_encode(CELTState *st, short *pcm) printf ("\n");*/ /* Band normalisation */ - compute_bands(X, B, st->bandE); - normalise_bands(X, B, st->bandE); + compute_bands(X, B, bandE); + //for (i=0;ibandE); - normalise_bands(P, B, st->bandE); + compute_bands(P, B, bandEp); + normalise_bands(P, B, bandEp); /* Pitch prediction */ + compute_pitch_gain(X, B, P, gains, bandE); + //quantise_pitch(gains, PBANDS); + pitch_quant_bands(X, B, P, gains); + + for (i=0;ibandE); + denormalise_bands(X, B, bandE); CELT_MOVE(st->out_mem, st->out_mem+B*N, MAX_PERIOD-B*N); /* Compute inverse MDCTs */