diff --git a/libcelt/bands.c b/libcelt/bands.c index 75fd66e6..b1a75803 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -35,6 +35,74 @@ #include "vq.h" #include "cwrs.h" +/* Applies a series of rotations so that pulses are spread like a two-sided expo +nential */ +static void exp_rotation(float *X, int len, float theta, int dir) +{ + int i; + float c, s; + c = cos(theta); + s = sin(theta); + if (dir > 0) + { + for (i=0;i<(len/2)-1;i++) + { + float x1, x2; + x1 = X[2*i]; + x2 = X[2*i+2]; + X[2*i] = c*x1 - s*x2; + X[2*i+2] = c*x2 + s*x1; + + x1 = X[2*i+1]; + x2 = X[2*i+3]; + X[2*i+1] = c*x1 - s*x2; + X[2*i+3] = c*x2 + s*x1; + } + for (i=(len/2)-3;i>=0;i--) + { + float x1, x2; + x1 = X[2*i]; + x2 = X[2*i+2]; + X[2*i] = c*x1 - s*x2; + X[2*i+2] = c*x2 + s*x1; + + x1 = X[2*i+1]; + x2 = X[2*i+3]; + X[2*i+1] = c*x1 - s*x2; + X[2*i+3] = c*x2 + s*x1; + } + + } else { + for (i=0;i<(len/2)-2;i++) + { + float x1, x2; + x1 = X[2*i]; + x2 = X[2*i+2]; + X[2*i] = c*x1 + s*x2; + X[2*i+2] = c*x2 - s*x1; + + x1 = X[2*i+1]; + x2 = X[2*i+3]; + X[2*i+1] = c*x1 + s*x2; + X[2*i+3] = c*x2 - s*x1; + } + + for (i=(len/2)-2;i>=0;i--) + { + float x1, x2; + x1 = X[2*i]; + x2 = X[2*i+2]; + X[2*i] = c*x1 + s*x2; + X[2*i+2] = c*x2 - s*x1; + + x1 = X[2*i+1]; + x2 = X[2*i+3]; + X[2*i+1] = c*x1 + s*x2; + X[2*i+3] = c*x2 - s*x1; + } + } +} + /* Compute the energy in each of the bands */ void compute_band_energies(const CELTMode *m, float *X, float *bank) @@ -159,16 +227,18 @@ void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc) q = m->nbPulses[i]; if (q>0) { float n = sqrt(B*(eBands[i+1]-eBands[i])); - alg_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], enc); + alg_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, enc); for (j=B*eBands[i];jnbPulses[i]; if (q>0) { float n = sqrt(B*(eBands[i+1]-eBands[i])); - alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], dec); + alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, dec); for (j=B*eBands[i];jnbEBands];inbEBands+1];i++) X[i] = 0; } + +void band_rotation(const CELTMode *m, float *X, int dir) +{ + int i, B; + const int *eBands = m->eBands; + B = m->nbMdctBlocks*m->nbChannels; + for (i=0;inbEBands;i++) + { + float theta; + theta = pow(.1f,1.f*abs(m->nbPulses[i])/(B*(eBands[i+1]-eBands[i]))); + exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, dir); + } + //printf ("\n"); +} diff --git a/libcelt/bands.h b/libcelt/bands.h index 922bea91..01d69fcd 100644 --- a/libcelt/bands.h +++ b/libcelt/bands.h @@ -51,4 +51,6 @@ void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc); void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec); +void band_rotation(const CELTMode *m, float *X, int dir); + #endif /* BANDS_H */ diff --git a/libcelt/celt.c b/libcelt/celt.c index 19ef1f84..0bcf53be 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -266,6 +266,9 @@ int celt_encode(CELTEncoder *st, short *pcm) normalise_bands(st->mode, P, bandEp); } + band_rotation(st->mode, X, -1); + band_rotation(st->mode, P, -1); + quant_energy(st->mode, bandE, st->oldBandE, &st->enc); /* Pitch prediction */ @@ -295,6 +298,8 @@ int celt_encode(CELTEncoder *st, short *pcm) //printf ("\n"); } + band_rotation(st->mode, X, 1); + /* Synthesis */ denormalise_bands(st->mode, X, bandE); @@ -495,6 +500,7 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm) compute_band_energies(st->mode, P, bandEp); normalise_bands(st->mode, P, bandEp); } + band_rotation(st->mode, P, -1); /* Get the pitch gains */ unquant_pitch(gains, st->mode->nbPBands, &dec); @@ -505,6 +511,8 @@ int celt_decode(CELTDecoder *st, char *data, int len, short *pcm) /* Decode fixed codebook and merge with pitch */ unquant_bands(st->mode, X, P, &dec); + band_rotation(st->mode, X, 1); + /* Synthesis */ denormalise_bands(st->mode, X, bandE); diff --git a/libcelt/modes.c b/libcelt/modes.c index 36c48de1..44b1d604 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -39,7 +39,7 @@ const int qbank1[NBANDS128+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52 const int qpulses1[NBANDS128] = {7, 5, 5, 5, 4, 5, 4, 5, 5, 4, -2, 0, 0, 0, 0}; const int qpulses2[NBANDS128] = {28,24,20,16,24,20, 18, 12, 10, 10,-7, -4, 0, 0, 0}; -const int qpulses2b[NBANDS128] = {32,28,24,20,28,24, 22, 18, 16, 15,-12, -12, 12, 12, 0}; +const int qpulses2s[NBANDS128] = {38,30,24,20,24,20, 18, 16, 14, 20,-20,-14, -8, -8, -5}; const int pbank1[PBANDS128+2] = {0, 4, 8, 12, 20, PITCH_END128, 128}; @@ -94,7 +94,7 @@ const CELTMode mode3 = { qpulses2 /**< nbPulses */ }; -/* Stereo mode (doesn't work yet) */ +/* Stereo mode around 120 kbps */ const CELTMode mode4 = { 256, /**< frameSize */ 128, /**< mdctSize */ @@ -107,7 +107,7 @@ const CELTMode mode4 = { qbank1, /**< eBands */ pbank1, /**< pBands*/ - qpulses1 /**< nbPulses */ + qpulses2s /**< nbPulses */ }; const CELTMode const *celt_mode1 = &mode1; diff --git a/libcelt/vq.c b/libcelt/vq.c index 8469e296..40735875 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -38,9 +38,9 @@ /* Improved algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch a combination of pulses such that its norm is still equal to 1. The only difference with the quantiser above is that the search is more complete. */ -void alg_quant(float *x, int N, int K, float *p, ec_enc *enc) +void alg_quant(float *x, int N, int K, float *p, float alpha, ec_enc *enc) { - int L = 5; + int L = 3; //float tata[200]; float y[L][N]; int iy[L][N]; @@ -55,7 +55,6 @@ void alg_quant(float *x, int N, int K, float *p, ec_enc *enc) float Rpp=0, Rxp=0; float gain[L]; int maxL = 1; - float alpha = .9; for (j=0;j