diff --git a/libcelt/celt.c b/libcelt/celt.c index 46c7af254b8bd8b04d139c1e8a306d0e6a298ac3..7d720233722e357e03734bf8dbc1794c1317ec8e 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -42,7 +42,6 @@ #define MAX_PERIOD 1024 /* This is only for cheating until the decoder is complete */ -float cheating_ebands[100]; float cheating_pitch_gains[100]; @@ -227,15 +226,13 @@ int celt_encode(CELTEncoder *st, short *pcm) normalise_bands(st->mode, P, bandEp); } - quant_energy(st->mode, bandE, st->oldBandE); + quant_energy(st->mode, bandE, st->oldBandE, &st->enc); /* Pitch prediction */ compute_pitch_gain(st->mode, X, P, gains, bandE); //quantise_pitch(gains, PBANDS); pitch_quant_bands(st->mode, X, P, gains); - for (i=0;i<st->mode->nbEBands;i++) - cheating_ebands[i] = bandE[i]; for (i=0;i<st->mode->nbPBands;i++) cheating_pitch_gains[i] = gains[i]; @@ -401,9 +398,8 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm) ec_dec_init(&dec,&buf); /* Get band energies */ - for (i=0;i<st->mode->nbEBands;i++) - bandE[i] = cheating_ebands[i]; - + unquant_energy(st->mode, bandE, st->oldBandE, &dec); + /* Get the pitch index */ pitch_index = ec_dec_uint(&dec, MAX_PERIOD-(B+1)*N);; diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c index 801170342156b574696f64bdfa40a7eb707c1956..33afc04593734a9e4ce494eb11ebb79280a6f29d 100644 --- a/libcelt/quant_bands.c +++ b/libcelt/quant_bands.c @@ -33,7 +33,9 @@ #include "quant_bands.h" #include <math.h> -void quant_energy(CELTMode *m, float *eBands, float *oldEBands) +int dummy_qi[100]; + +void quant_energy(CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc) { int i; float prev = 0; @@ -49,6 +51,7 @@ void quant_energy(CELTMode *m, float *eBands, float *oldEBands) res = .25f*(i+3.f); //res = 1; qi = (int)floor(.5+(x-pred-prev)/res); + dummy_qi[i] = qi; q = qi*res; //printf("%f %f ", pred+prev+q, x); @@ -64,4 +67,29 @@ void quant_energy(CELTMode *m, float *eBands, float *oldEBands) //printf ("\n"); } - +void unquant_energy(CELTMode *m, float *eBands, float *oldEBands, ec_dec *dec) +{ + int i; + float prev = 0; + for (i=0;i<m->nbEBands;i++) + { + int qi; + float q; + float res; + float pred = .7*oldEBands[i]; + + res = .25f*(i+3.f); + qi = dummy_qi[i]; + q = qi*res; + + //printf("%f %f ", pred+prev+q, x); + //printf("%d ", qi); + //printf("%f ", x-pred-prev); + + oldEBands[i] = pred+prev+q; + eBands[i] = pow(10, .05*oldEBands[i])-.3; + if (eBands[i] < 0) + eBands[i] = 0; + prev = (prev + .5*q); + } +} diff --git a/libcelt/quant_bands.h b/libcelt/quant_bands.h index 2d2bca0f6bd53a49e08a16b67ddbe84ee0191d3b..0735ab90ae95431b2f66de2d437c30bab7ef9aa9 100644 --- a/libcelt/quant_bands.h +++ b/libcelt/quant_bands.h @@ -33,8 +33,11 @@ #define QUANT_BANDS #include "modes.h" +#include "entenc.h" +#include "entdec.h" -void quant_energy(CELTMode *m, float *eBands, float *oldEBands); +void quant_energy(CELTMode *m, float *eBands, float *oldEBands, ec_enc *enc); +void unquant_energy(CELTMode *m, float *eBands, float *oldEBands, ec_dec *dec); #endif /* QUANT_BANDS */