ref: fdca84b42f627698219139f8d818e5f26fa55ba3
parent: 95c59ea6476d369d544a30feebca5dff3344af56
author: Jean-Marc Valin <[email protected]>
date: Wed Jan 9 05:44:18 EST 2008
Some stereo work (breaks the decoder for now)
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -91,50 +91,71 @@
/* 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;
}
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -52,6 +52,8 @@
*/
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)
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -239,7 +239,7 @@
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 @@
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 @@
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));
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -163,16 +163,16 @@
/* 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 */