fixed-point: first check-point on quant_energy_mono() conversion

This commit is contained in:
Jean-Marc Valin 2008-02-28 16:41:56 +11:00
parent 4e1328b09d
commit 43b3537d38

View file

@ -39,35 +39,51 @@
#include "os_support.h" #include "os_support.h"
#include "arch.h" #include "arch.h"
#ifdef FIXED_POINT
const float eMeans[24] = {11520, -2048, -3072, -640, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#else
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 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};
#endif
/*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}; 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};
#ifdef FIXED_POINT
#define Q8 256.f
#define Q8_1 (1.f/256.f)
#else
#define Q8 1.f
#define Q8_1 1.f
#endif
static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, ec_enc *enc) static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int budget, ec_enc *enc)
{ {
int i; int i;
int bits; int bits;
float prev = 0; celt_word16_t prev = 0;
float coef = m->ePredCoef; float coef = m->ePredCoef;
VARDECL(float *error); VARDECL(celt_word16_t *error);
/* The .7 is a heuristic */ /* The .7 is a heuristic */
float beta = .7*coef; float beta = .7*coef;
ALLOC(error, m->nbEBands, float); ALLOC(error, m->nbEBands, celt_word16_t);
bits = ec_enc_tell(enc, 0); bits = ec_enc_tell(enc, 0);
for (i=0;i<m->nbEBands;i++) for (i=0;i<m->nbEBands;i++)
{ {
int qi; int qi;
float q; celt_word16_t q; /* dB */
float res; celt_word16_t res; /* dB */
float x; celt_word16_t x; /* dB */
float f; celt_word16_t f; /* Q8 */
float mean = (1-coef)*eMeans[i]; celt_word16_t mean = (1-coef)*eMeans[i];
x = 20*log10(.3+ENER_SCALING_1*eBands[i]); x = DB_SCALING*20*log10(.3+ENER_SCALING_1*eBands[i]);
res = 6.; res = DB_SCALING*6;
f = (x-mean-coef*DB_SCALING_1*oldEBands[i]-prev)/res; f = QCONST16(1.f,8)*(x-mean-coef*oldEBands[i]-prev*1.f)/res;
#ifdef FIXED_POINT
/* Rounding to nearest integer here is really important! */
qi = (f+128)>>8;
#else
qi = (int)floor(.5+f); qi = (int)floor(.5+f);
#endif
/*ec_laplace_encode(enc, qi, i==0?11192:6192);*/ /*ec_laplace_encode(enc, qi, i==0?11192:6192);*/
/*ec_laplace_encode(enc, qi, 8500-i*200);*/ /*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 we don't have enough bits to encode all the energy, just assume something safe. */
@ -76,13 +92,13 @@ static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word1
else else
ec_laplace_encode(enc, qi, 6000-i*200); ec_laplace_encode(enc, qi, 6000-i*200);
q = qi*res; q = qi*res;
error[i] = f - qi; error[i] = f - SHL16(qi,8);
/*printf("%d ", qi);*/ /*printf("%d ", qi);*/
/*printf("%f %f ", pred+prev+q, x);*/ /*printf("%f %f ", pred+prev+q, x);*/
/*printf("%f ", x-pred);*/ /*printf("%f ", x-pred);*/
oldEBands[i] = DB_SCALING*(mean+coef*DB_SCALING_1*oldEBands[i]+prev+q); oldEBands[i] = mean+coef*oldEBands[i]+prev+q;
prev = mean+prev+(1-beta)*q; prev = mean+prev+(1-beta)*q;
} }
@ -91,7 +107,7 @@ static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word1
for (i=0;i<m->nbEBands;i++) for (i=0;i<m->nbEBands;i++)
{ {
int q2; int q2;
float offset = (error[i]+.5)*frac[i]; float offset = Q8_1*(error[i]+QCONST16(.5f,8))*frac[i];
/* FIXME: Instead of giving up without warning, we should degrade everything gracefully */ /* FIXME: Instead of giving up without warning, we should degrade everything gracefully */
if (ec_enc_tell(enc, 0) - bits +EC_ILOG(frac[i])> budget) if (ec_enc_tell(enc, 0) - bits +EC_ILOG(frac[i])> budget)
break; break;
@ -137,9 +153,9 @@ static void unquant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_wor
qi = ec_laplace_decode(dec, 6000-i*200); qi = ec_laplace_decode(dec, 6000-i*200);
q = qi*res; q = qi*res;
oldEBands[i] = DB_SCALING*(mean+coef*DB_SCALING_1*oldEBands[i]+prev+q); oldEBands[i] = DB_SCALING*(DB_SCALING_1*mean+coef*DB_SCALING_1*oldEBands[i]+prev+q);
prev = mean+prev+(1-beta)*q; prev = DB_SCALING_1*mean+prev+(1-beta)*q;
} }
for (i=0;i<m->nbEBands;i++) for (i=0;i<m->nbEBands;i++)
{ {