Commit 70c8ffdd authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

More decoding work

parent fc08d0a6
......@@ -177,39 +177,29 @@ void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc)
X[i] = 0;
}
/* Scales the pulse-codebook entry in each band such that unit-energy is conserved when
adding the pitch */
void pitch_renormalise_bands(const CELTMode *m, float *X, float *P)
void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec)
{
int i, B;
int i, j, B;
const int *eBands = m->eBands;
B = m->nbMdctBlocks;
float norm[B*eBands[m->nbEBands+1]];
for (i=0;i<m->nbEBands;i++)
{
int j;
float Rpp=0;
float Rxp=0;
float Rxx=0;
float gain1;
for (j=B*eBands[i];j<B*eBands[i+1];j++)
{
Rxp += X[j]*P[j];
Rpp += P[j]*P[j];
Rxx += X[j]*X[j];
}
float arg = Rxp*Rxp + 1 - Rpp;
if (arg < 0)
arg = 0;
gain1 = sqrt(arg)-Rxp;
Rxx = 0;
for (j=B*eBands[i];j<B*eBands[i+1];j++)
{
X[j] = P[j]+gain1*X[j];
Rxx += X[j]*X[j];
int q, id;
q = m->nbPulses[i];
if (q>0) {
float n = sqrt(B*(eBands[i+1]-eBands[i]));
alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], dec);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
norm[j] = X[j] * n;
} else {
float n = sqrt(B*(eBands[i+1]-eBands[i]));
//copy_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i], dec);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
norm[j] = X[j] * n;
}
}
for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
X[i] = 0;
}
......@@ -35,6 +35,7 @@
#include "modes.h"
#include "entenc.h"
#include "entdec.h"
void compute_band_energies(const CELTMode *m, float *X, float *bands);
......@@ -48,6 +49,6 @@ void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains);
void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc);
void pitch_renormalise_bands(const CELTMode *m, float *X, float *P);
void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec);
#endif /* BANDS_H */
......@@ -243,6 +243,16 @@ int celt_encode(CELTEncoder *st, short *pcm)
/* Residual quantisation */
quant_bands(st->mode, X, P, &st->enc);
if (0) {//This is just for debugging
ec_enc_done(&st->enc);
ec_dec dec;
ec_byte_readinit(&st->buf,ec_byte_get_buffer(&st->buf),ec_byte_bytes(&st->buf));
ec_dec_init(&dec,&st->buf);
unquant_bands(st->mode, X, P, &dec);
//printf ("\n");
}
/* Synthesis */
denormalise_bands(st->mode, X, bandE);
......@@ -362,7 +372,17 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm)
float bandE[st->mode->nbEBands];
float gains[st->mode->nbPBands];
int pitch_index;
ec_dec dec;
ec_byte_buffer buf;
ec_byte_readinit(&buf,data,len);
ec_dec_init(&dec,&buf);
/* Get band energies */
/* Get the pitch index */
/* Pitch MDCT */
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index, P, N, B);
//haar1(P, B*N);
......@@ -373,12 +393,14 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm)
normalise_bands(st->mode, P, bandEp);
}
/* Apply pitch gains */
/* Decode fixed codebook */
/* Merge pitch and fixed codebook */
/* Get the pitch gains */
/* Apply pitch gains */
pitch_quant_bands(st->mode, X, P, gains);
/* Decode fixed codebook and merge with pitch */
unquant_bands(st->mode, X, P, &dec);
/* Synthesis */
denormalise_bands(st->mode, X, bandE);
......
......@@ -184,6 +184,8 @@ void alg_quant(float *x, int N, int K, float *p, ec_enc *enc)
}
int comb[K];
int signs[K];
//for (i=0;i<N;i++)
// printf ("%d ", iy[0][i]);
pulse2comb(N, K, comb, signs, iy[0]);
ec_enc_uint(enc,icwrs(N, K, comb, signs),ncwrs(N, K));
}
......@@ -267,7 +269,8 @@ void alg_unquant(float *x, int N, int K, float *p, ec_dec *dec)
id = ec_dec_uint(dec, ncwrs(N, K));
cwrsi(N, K, id, comb, signs);
comb2pulse(N, K, iy, comb, signs);
//for (i=0;i<N;i++)
// printf ("%d ", iy[i]);
for (i=0;i<N;i++)
Rpp += p[i]*p[i];
......@@ -275,7 +278,7 @@ void alg_unquant(float *x, int N, int K, float *p, ec_dec *dec)
Ryp += iy[i]*p[i];
for (i=0;i<N;i++)
y[i] = iy[i] - Ryp*p[i];
y[i] = iy[i] - alpha*Ryp*p[i];
/* Recompute after the projection (I think it's right) */
Ryp = 0;
......
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