Some stereo work (breaks the decoder for now)

This commit is contained in:
Jean-Marc Valin 2008-01-09 10:44:18 +11:00
parent 95c59ea647
commit fdca84b42f
4 changed files with 73 additions and 46 deletions

View file

@ -91,50 +91,71 @@ static void exp_rotation(float *X, int len, float theta, int dir, int stride, in
/* Compute the amplitude (sqrt energy) in each of the bands */
void compute_band_energies(const CELTMode *m, float *X, float *bank)
{
int i, B;
int i, c, B, C;
const int *eBands = m->eBands;
B = m->nbMdctBlocks*m->nbChannels;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
{
int j;
bank[i] = 1e-10;
float sum = 1e-10;
for (j=B*eBands[i];j<B*eBands[i+1];j++)
bank[i] += X[j]*X[j];
bank[i] = sqrt(bank[i]);
sum += X[j*C+c]*X[j*C+c];
bank[i*C+c] = sqrt(C*sum);
//printf ("%f ", bank[i*C+c]);
}
}
//printf ("\n");
}
/* Normalise each band such that the energy is one. */
void normalise_bands(const CELTMode *m, float *X, float *bank)
{
int i, B;
int i, c, B, C;
const int *eBands = m->eBands;
B = m->nbMdctBlocks*m->nbChannels;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
{
int j;
float x = 1.f/(1e-10+bank[i]);
float g = 1.f/(1e-10+bank[i*C+c]);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
X[j] *= x;
X[j*C+c] *= g;
}
for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
}
for (i=B*C*eBands[m->nbEBands];i<B*C*eBands[m->nbEBands+1];i++)
X[i] = 0;
}
void renormalise_bands(const CELTMode *m, float *X)
{
float tmpE[m->nbEBands*m->nbChannels];
compute_band_energies(m, X, tmpE);
normalise_bands(m, X, tmpE);
}
/* De-normalise the energy to produce the synthesis from the unit-energy bands */
void denormalise_bands(const CELTMode *m, float *X, float *bank)
{
int i, B;
int i, c, B, C;
const int *eBands = m->eBands;
B = m->nbMdctBlocks*m->nbChannels;
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
for (i=0;i<m->nbEBands;i++)
{
int j;
float x = bank[i];
float g = bank[i*C+c];
for (j=B*eBands[i];j<B*eBands[i+1];j++)
X[j] *= x;
X[j*C+c] *= g;
}
for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
}
for (i=B*C*eBands[m->nbEBands];i<B*C*eBands[m->nbEBands+1];i++)
X[i] = 0;
}

View file

@ -52,6 +52,8 @@ void compute_band_energies(const CELTMode *m, float *X, float *bands);
*/
void normalise_bands(const CELTMode *m, float *X, float *bands);
void renormalise_bands(const CELTMode *m, float *X);
/** Denormalise each band of X to restore full amplitude
* @param m Mode data
* @param X Spectrum (returned de-normalised)

View file

@ -239,7 +239,7 @@ int celt_encode(CELTEncoder *st, short *pcm)
float X[B*C*N]; /**< Interleaved signal MDCTs */
float P[B*C*N]; /**< Interleaved pitch MDCTs*/
float mask[B*C*N]; /**< Masking curve */
float bandE[st->mode->nbEBands];
float bandE[st->mode->nbEBands*C];
float gains[st->mode->nbPBands];
int pitch_index;
@ -295,28 +295,30 @@ int celt_encode(CELTEncoder *st, short *pcm)
for (j=0;j<B*N;j++)
printf ("%f ", P[j]);
printf ("\n");*/
if (C==2)
{
haar1(X, B*N*C, 1);
haar1(P, B*N*C, 1);
}
/* Get a tiny bit more frequency resolution and prevent unstable energy when quantising */
time_dct(X, N, B, C);
time_dct(P, N, B, C);
/* Band normalisation */
compute_band_energies(st->mode, X, bandE);
normalise_bands(st->mode, X, bandE);
//for (i=0;i<st->mode->nbEBands;i++)printf("%f ", bandE[i]);printf("\n");
//for (i=0;i<N*B*C;i++)printf("%f ", X[i]);printf("\n");
/* Normalise the pitch vector as well (discard the energies) */
{
float bandEp[st->mode->nbEBands];
float bandEp[st->mode->nbEBands*st->mode->nbChannels];
compute_band_energies(st->mode, P, bandEp);
normalise_bands(st->mode, P, bandEp);
}
if (C==2)
{
haar1(X, B*N*C, 1);
haar1(P, B*N*C, 1);
}
/* Get a tiny bit more frequency resolution and prevent unstable energy when quantising */
time_dct(X, N, B, C);
time_dct(P, N, B, C);
quant_energy(st->mode, bandE, st->oldBandE, &st->enc);
/* Pitch prediction */
@ -336,13 +338,15 @@ int celt_encode(CELTEncoder *st, short *pcm)
/* Residual quantisation */
quant_bands(st->mode, X, P, mask, &st->enc);
/* Synthesis */
denormalise_bands(st->mode, X, bandE);
time_idct(X, N, B, C);
if (C==2)
haar1(X, B*N*C, 1);
renormalise_bands(st->mode, X);
/* Synthesis */
denormalise_bands(st->mode, X, bandE);
CELT_MOVE(st->out_mem, st->out_mem+C*B*N, C*(MAX_PERIOD-B*N));
compute_inv_mdcts(&st->mdct_lookup, st->window, X, st->out_mem, st->mdct_overlap, N, st->overlap, B, C);

View file

@ -163,16 +163,16 @@ const CELTMode mode3 = {
/* Stereo mode around 120 kbps */
const CELTMode mode4 = {
128, /**< overlap */
128, /**< mdctSize */
2, /**< nbMdctBlocks */
256, /**< mdctSize */
1, /**< nbMdctBlocks */
2, /**< channels */
NBANDS128, /**< nbEBands */
PBANDS128, /**< nbPBands */
PITCH_END128,/**< pitchEnd */
NBANDS256, /**< nbEBands */
PBANDS256, /**< nbPBands */
PITCH_END256,/**< pitchEnd */
qbank1, /**< eBands */
pbank1, /**< pBands*/
qbank3, /**< eBands */
pbank3, /**< pBands*/
qpulses2s, /**< nbPulses */
0.7, /**< ePredCoef */