conversion to modes complete

This commit is contained in:
Jean-Marc Valin 2007-12-05 21:14:22 +11:00
parent 3337e5d3e5
commit 96870d9334
5 changed files with 45 additions and 57 deletions

View file

@ -95,7 +95,7 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
const int *pBands = m->pBands; const int *pBands = m->pBands;
B = m->nbMdctBlocks; B = m->nbMdctBlocks;
float w[B*eBands[m->nbEBands]]; float w[B*eBands[m->nbEBands]];
for (i=0;i<NBANDS;i++) for (i=0;i<m->nbEBands;i++)
{ {
int j; int j;
for (j=B*eBands[i];j<B*eBands[i+1];j++) for (j=B*eBands[i];j<B*eBands[i+1];j++)
@ -129,71 +129,71 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
P[i] = 0; P[i] = 0;
} }
/* Progressively getting rid of this */
const int qbank[NBANDS+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
const int qpulses[NBANDS ] = {7, 5, 4, 4, 3, 3, 3, 4, 4, 4, -2, -1, -1, -1, 0};
#define WAVEFORM_END 36
int pbank[] = {0, 4, 8, 12, 20, WAVEFORM_END, 128};
/* Apply the (quantised) gain to each "pitch band" */ /* Apply the (quantised) gain to each "pitch band" */
void pitch_quant_bands(float *X, int B, float *P, float *gains) void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains)
{ {
int i; int i, B;
for (i=0;i<PBANDS;i++) const int *pBands = m->pBands;
B = m->nbMdctBlocks;
for (i=0;i<m->nbPBands;i++)
{ {
int j; int j;
for (j=B*pbank[i];j<B*pbank[i+1];j++) for (j=B*pBands[i];j<B*pBands[i+1];j++)
P[j] *= gains[i]; P[j] *= gains[i];
//printf ("%f ", gain); //printf ("%f ", gain);
} }
for (i=B*pbank[PBANDS];i<B*pbank[PBANDS+1];i++) for (i=B*pBands[m->nbPBands];i<B*pBands[m->nbPBands+1];i++)
P[i] = 0; P[i] = 0;
} }
void quant_bands(float *X, int B, float *P) void quant_bands(const CELTMode *m, float *X, float *P)
{ {
int i, j; int i, j, B;
float norm[B*qbank[NBANDS+1]]; const int *eBands = m->eBands;
B = m->nbMdctBlocks;
float norm[B*eBands[m->nbEBands+1]];
//float bits = 0; //float bits = 0;
for (i=0;i<NBANDS;i++) for (i=0;i<m->nbEBands;i++)
{ {
int q; int q;
q =qpulses[i]; q = m->nbPulses[i];
if (q>0) { if (q>0) {
float n = sqrt(B*(qbank[i+1]-qbank[i])); float n = sqrt(B*(eBands[i+1]-eBands[i]));
alg_quant2(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]); alg_quant2(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i]);
for (j=B*qbank[i];j<B*qbank[i+1];j++) for (j=B*eBands[i];j<B*eBands[i+1];j++)
norm[j] = X[j] * n; norm[j] = X[j] * n;
//bits += log2(ncwrs(B*(qbank[i+1]-qbank[i]), q)); //bits += log2(ncwrs(B*(qbank[i+1]-qbank[i]), q));
} else { } else {
float n = sqrt(B*(qbank[i+1]-qbank[i])); float n = sqrt(B*(eBands[i+1]-eBands[i]));
copy_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), -q, norm, B, qbank[i]); copy_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i]);
for (j=B*qbank[i];j<B*qbank[i+1];j++) for (j=B*eBands[i];j<B*eBands[i+1];j++)
norm[j] = X[j] * n; norm[j] = X[j] * n;
//bits += 1+log2(qbank[i])+log2(ncwrs(B*(qbank[i+1]-qbank[i]), -q)); //bits += 1+log2(qbank[i])+log2(ncwrs(B*(qbank[i+1]-qbank[i]), -q));
//noise_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]); //noise_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]);
} }
} }
//printf ("%f\n", bits); //printf ("%f\n", bits);
for (i=B*qbank[NBANDS];i<B*qbank[NBANDS+1];i++) for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
X[i] = 0; X[i] = 0;
} }
/* Scales the pulse-codebook entry in each band such that unit-energy is conserved when /* Scales the pulse-codebook entry in each band such that unit-energy is conserved when
adding the pitch */ adding the pitch */
void pitch_renormalise_bands(float *X, int B, float *P) void pitch_renormalise_bands(const CELTMode *m, float *X, float *P)
{ {
int i; int i, B;
for (i=0;i<NBANDS;i++) const int *eBands = m->eBands;
B = m->nbMdctBlocks;
for (i=0;i<m->nbEBands;i++)
{ {
int j; int j;
float Rpp=0; float Rpp=0;
float Rxp=0; float Rxp=0;
float Rxx=0; float Rxx=0;
float gain1; float gain1;
for (j=B*qbank[i];j<B*qbank[i+1];j++) for (j=B*eBands[i];j<B*eBands[i+1];j++)
{ {
Rxp += X[j]*P[j]; Rxp += X[j]*P[j];
Rpp += P[j]*P[j]; Rpp += P[j]*P[j];
@ -204,13 +204,13 @@ void pitch_renormalise_bands(float *X, int B, float *P)
arg = 0; arg = 0;
gain1 = sqrt(arg)-Rxp; gain1 = sqrt(arg)-Rxp;
Rxx = 0; Rxx = 0;
for (j=B*qbank[i];j<B*qbank[i+1];j++) for (j=B*eBands[i];j<B*eBands[i+1];j++)
{ {
X[j] = P[j]+gain1*X[j]; X[j] = P[j]+gain1*X[j];
Rxx += X[j]*X[j]; Rxx += X[j]*X[j];
} }
} }
for (i=B*qbank[NBANDS];i<B*qbank[NBANDS+1];i++) for (i=B*eBands[m->nbEBands];i<B*eBands[m->nbEBands+1];i++)
X[i] = 0; X[i] = 0;
} }

View file

@ -34,11 +34,6 @@
#include "modes.h" #include "modes.h"
/* Number of constant-energy bands */
#define NBANDS 15
/* Number of bands only for the pitch prediction */
#define PBANDS 5
void compute_band_energies(const CELTMode *m, float *X, float *bands); 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);
@ -47,10 +42,10 @@ void denormalise_bands(const CELTMode *m, float *X, float *bands);
void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, float *bank); void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, float *bank);
void pitch_quant_bands(float *X, int B, float *P, float *gains); void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains);
void quant_bands(float *X, int B, float *P); void quant_bands(const CELTMode *m, float *X, float *P);
void pitch_renormalise_bands(float *X, int B, float *P); void pitch_renormalise_bands(const CELTMode *m, float *X, float *P);
#endif /* BANDS_H */ #endif /* BANDS_H */

View file

@ -159,9 +159,8 @@ int celt_encode(CELTState *st, short *pcm)
float X[B*N]; /**< Interleaved signal MDCTs */ float X[B*N]; /**< Interleaved signal MDCTs */
float P[B*N]; /**< Interleaved pitch MDCTs*/ float P[B*N]; /**< Interleaved pitch MDCTs*/
float bandEp[NBANDS]; float bandE[st->mode->nbEBands];
float bandE[NBANDS]; float gains[st->mode->nbPBands];
float gains[PBANDS];
int pitch_index; int pitch_index;
for (i=0;i<N;i++) for (i=0;i<N;i++)
@ -203,13 +202,16 @@ int celt_encode(CELTState *st, short *pcm)
normalise_bands(st->mode, X, bandE); normalise_bands(st->mode, X, bandE);
//for (i=0;i<NBANDS;i++)printf("%f ", bandE[i]);printf("\n"); //for (i=0;i<NBANDS;i++)printf("%f ", bandE[i]);printf("\n");
compute_band_energies(st->mode, P, bandEp); {
normalise_bands(st->mode, P, bandEp); float bandEp[st->mode->nbEBands];
compute_band_energies(st->mode, P, bandEp);
normalise_bands(st->mode, P, bandEp);
}
/* Pitch prediction */ /* Pitch prediction */
compute_pitch_gain(st->mode, X, P, gains, bandE); compute_pitch_gain(st->mode, X, P, gains, bandE);
//quantise_pitch(gains, PBANDS); //quantise_pitch(gains, PBANDS);
pitch_quant_bands(X, B, P, gains); pitch_quant_bands(st->mode, X, P, gains);
//for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n"); //for (i=0;i<B*N;i++) printf("%f ",P[i]);printf("\n");
/* Subtract the pitch prediction from the signal to encode */ /* Subtract the pitch prediction from the signal to encode */
@ -221,16 +223,7 @@ int celt_encode(CELTState *st, short *pcm)
sum += X[i]*X[i]; sum += X[i]*X[i];
printf ("%f\n", sum);*/ printf ("%f\n", sum);*/
/* Residual quantisation */ /* Residual quantisation */
#if 1 quant_bands(st->mode, X, P);
quant_bands(X, B, P);
#else
{
float tmpE[NBANDS];
compute_bands(X, B, tmpE);
normalise_bands(X, B, tmpE);
pitch_renormalise_bands(X, B, P);
}
#endif
/* Synthesis */ /* Synthesis */
denormalise_bands(st->mode, X, bandE); denormalise_bands(st->mode, X, bandE);

View file

@ -53,7 +53,7 @@ const CELTMode mode1 = {
qbank1, /**< eBands */ qbank1, /**< eBands */
pbank1, /**< pBands*/ pbank1, /**< pBands*/
qpulses1 /**< pulses */ qpulses1 /**< nbPulses */
}; };
const CELTMode const *celt_mode1 = &mode1; const CELTMode const *celt_mode1 = &mode1;

View file

@ -45,7 +45,7 @@ struct CELTMode_ {
const int *eBands; const int *eBands;
const int *pBands; const int *pBands;
const int *pulses; const int *nbPulses;
}; };
#endif #endif