Some stereo work (breaks the decoder for now)
This commit is contained in:
parent
95c59ea647
commit
fdca84b42f
4 changed files with 73 additions and 46 deletions
|
@ -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 */
|
/* Compute the amplitude (sqrt energy) in each of the bands */
|
||||||
void compute_band_energies(const CELTMode *m, float *X, float *bank)
|
void compute_band_energies(const CELTMode *m, float *X, float *bank)
|
||||||
{
|
{
|
||||||
int i, B;
|
int i, c, B, C;
|
||||||
const int *eBands = m->eBands;
|
const int *eBands = m->eBands;
|
||||||
B = m->nbMdctBlocks*m->nbChannels;
|
B = m->nbMdctBlocks;
|
||||||
for (i=0;i<m->nbEBands;i++)
|
C = m->nbChannels;
|
||||||
|
for (c=0;c<C;c++)
|
||||||
{
|
{
|
||||||
int j;
|
for (i=0;i<m->nbEBands;i++)
|
||||||
bank[i] = 1e-10;
|
{
|
||||||
for (j=B*eBands[i];j<B*eBands[i+1];j++)
|
int j;
|
||||||
bank[i] += X[j]*X[j];
|
float sum = 1e-10;
|
||||||
bank[i] = sqrt(bank[i]);
|
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. */
|
/* Normalise each band such that the energy is one. */
|
||||||
void normalise_bands(const CELTMode *m, float *X, float *bank)
|
void normalise_bands(const CELTMode *m, float *X, float *bank)
|
||||||
{
|
{
|
||||||
int i, B;
|
int i, c, B, C;
|
||||||
const int *eBands = m->eBands;
|
const int *eBands = m->eBands;
|
||||||
B = m->nbMdctBlocks*m->nbChannels;
|
B = m->nbMdctBlocks;
|
||||||
for (i=0;i<m->nbEBands;i++)
|
C = m->nbChannels;
|
||||||
|
for (c=0;c<C;c++)
|
||||||
{
|
{
|
||||||
int j;
|
for (i=0;i<m->nbEBands;i++)
|
||||||
float x = 1.f/(1e-10+bank[i]);
|
{
|
||||||
for (j=B*eBands[i];j<B*eBands[i+1];j++)
|
int j;
|
||||||
X[j] *= x;
|
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;
|
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 */
|
/* De-normalise the energy to produce the synthesis from the unit-energy bands */
|
||||||
void denormalise_bands(const CELTMode *m, float *X, float *bank)
|
void denormalise_bands(const CELTMode *m, float *X, float *bank)
|
||||||
{
|
{
|
||||||
int i, B;
|
int i, c, B, C;
|
||||||
const int *eBands = m->eBands;
|
const int *eBands = m->eBands;
|
||||||
B = m->nbMdctBlocks*m->nbChannels;
|
B = m->nbMdctBlocks;
|
||||||
for (i=0;i<m->nbEBands;i++)
|
C = m->nbChannels;
|
||||||
|
for (c=0;c<C;c++)
|
||||||
{
|
{
|
||||||
int j;
|
for (i=0;i<m->nbEBands;i++)
|
||||||
float x = bank[i];
|
{
|
||||||
for (j=B*eBands[i];j<B*eBands[i+1];j++)
|
int j;
|
||||||
X[j] *= x;
|
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;
|
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 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
|
/** Denormalise each band of X to restore full amplitude
|
||||||
* @param m Mode data
|
* @param m Mode data
|
||||||
* @param X Spectrum (returned de-normalised)
|
* @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 X[B*C*N]; /**< Interleaved signal MDCTs */
|
||||||
float P[B*C*N]; /**< Interleaved pitch MDCTs*/
|
float P[B*C*N]; /**< Interleaved pitch MDCTs*/
|
||||||
float mask[B*C*N]; /**< Masking curve */
|
float mask[B*C*N]; /**< Masking curve */
|
||||||
float bandE[st->mode->nbEBands];
|
float bandE[st->mode->nbEBands*C];
|
||||||
float gains[st->mode->nbPBands];
|
float gains[st->mode->nbPBands];
|
||||||
int pitch_index;
|
int pitch_index;
|
||||||
|
|
||||||
|
@ -295,28 +295,30 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
||||||
for (j=0;j<B*N;j++)
|
for (j=0;j<B*N;j++)
|
||||||
printf ("%f ", P[j]);
|
printf ("%f ", P[j]);
|
||||||
printf ("\n");*/
|
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 */
|
/* Band normalisation */
|
||||||
compute_band_energies(st->mode, X, bandE);
|
compute_band_energies(st->mode, X, bandE);
|
||||||
normalise_bands(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<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) */
|
/* 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);
|
compute_band_energies(st->mode, P, bandEp);
|
||||||
normalise_bands(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);
|
quant_energy(st->mode, bandE, st->oldBandE, &st->enc);
|
||||||
|
|
||||||
/* Pitch prediction */
|
/* Pitch prediction */
|
||||||
|
@ -336,13 +338,15 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
||||||
/* Residual quantisation */
|
/* Residual quantisation */
|
||||||
quant_bands(st->mode, X, P, mask, &st->enc);
|
quant_bands(st->mode, X, P, mask, &st->enc);
|
||||||
|
|
||||||
/* Synthesis */
|
|
||||||
denormalise_bands(st->mode, X, bandE);
|
|
||||||
|
|
||||||
time_idct(X, N, B, C);
|
time_idct(X, N, B, C);
|
||||||
if (C==2)
|
if (C==2)
|
||||||
haar1(X, B*N*C, 1);
|
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));
|
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);
|
compute_inv_mdcts(&st->mdct_lookup, st->window, X, st->out_mem, st->mdct_overlap, N, st->overlap, B, C);
|
||||||
|
|
|
@ -163,16 +163,16 @@ const CELTMode mode3 = {
|
||||||
/* Stereo mode around 120 kbps */
|
/* Stereo mode around 120 kbps */
|
||||||
const CELTMode mode4 = {
|
const CELTMode mode4 = {
|
||||||
128, /**< overlap */
|
128, /**< overlap */
|
||||||
128, /**< mdctSize */
|
256, /**< mdctSize */
|
||||||
2, /**< nbMdctBlocks */
|
1, /**< nbMdctBlocks */
|
||||||
2, /**< channels */
|
2, /**< channels */
|
||||||
|
|
||||||
NBANDS128, /**< nbEBands */
|
NBANDS256, /**< nbEBands */
|
||||||
PBANDS128, /**< nbPBands */
|
PBANDS256, /**< nbPBands */
|
||||||
PITCH_END128,/**< pitchEnd */
|
PITCH_END256,/**< pitchEnd */
|
||||||
|
|
||||||
qbank1, /**< eBands */
|
qbank3, /**< eBands */
|
||||||
pbank1, /**< pBands*/
|
pbank3, /**< pBands*/
|
||||||
qpulses2s, /**< nbPulses */
|
qpulses2s, /**< nbPulses */
|
||||||
|
|
||||||
0.7, /**< ePredCoef */
|
0.7, /**< ePredCoef */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue