Commit 8143be30 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

energy decoding partially done (cheating a bit)

parent b726185d
......@@ -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);;
......
......@@ -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);
}
}
......@@ -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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment