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

Some stereo work (breaks the decoder for now)

parent 95c59ea6
......@@ -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;
for (i=0;i<m->nbEBands;i++)
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
int j;
bank[i] = 1e-10;
for (j=B*eBands[i];j<B*eBands[i+1];j++)
bank[i] += X[j]*X[j];
bank[i] = sqrt(bank[i]);
for (i=0;i<m->nbEBands;i++)
{
int j;
float sum = 1e-10;
for (j=B*eBands[i];j<B*eBands[i+1];j++)
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;
for (i=0;i<m->nbEBands;i++)
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
int j;
float x = 1.f/(1e-10+bank[i]);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
X[j] *= x;
for (i=0;i<m->nbEBands;i++)
{
int j;
float g = 1.f/(1e-10+bank[i*C+c]);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
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;
for (i=0;i<m->nbEBands;i++)
B = m->nbMdctBlocks;
C = m->nbChannels;
for (c=0;c<C;c++)
{
int j;
float x = bank[i];
for (j=B*eBands[i];j<B*eBands[i+1];j++)
X[j] *= x;
for (i=0;i<m->nbEBands;i++)
{
int j;
float g = bank[i*C+c];
for (j=B*eBands[i];j<B*eBands[i+1];j++)
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;
}
......
......@@ -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)
......
......@@ -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 */
......@@ -335,13 +337,15 @@ int celt_encode(CELTEncoder *st, short *pcm)
printf ("%f\n", sum);*/
/* Residual quantisation */
quant_bands(st->mode, X, P, mask, &st->enc);
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);
time_idct(X, N, B, C);
if (C==2)
haar1(X, B*N*C, 1);
CELT_MOVE(st->out_mem, st->out_mem+C*B*N, C*(MAX_PERIOD-B*N));
......
......@@ -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 */
......
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