From 46014ca49a91e345cd4d3a9d70a67a1cbe73c2ac Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 14 Dec 2007 13:47:04 +1100 Subject: [PATCH] Propagating perceptual weighting around (not used yet). --- libcelt/bands.c | 6 +++--- libcelt/bands.h | 2 +- libcelt/celt.c | 11 ++++++++++- libcelt/testcelt.c | 4 ++-- libcelt/vq.c | 6 +++--- libcelt/vq.h | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index b1a75803..f6b460e2 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -214,7 +214,7 @@ void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains) P[i] = 0; } -void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc) +void quant_bands(const CELTMode *m, float *X, float *P, float *W, ec_enc *enc) { int i, j, B; const int *eBands = m->eBands; @@ -227,14 +227,14 @@ 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], 0.7, enc); + alg_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, enc); for (j=B*eBands[i];jframe_size = B*N; st->block_size = N; st->nb_blocks = B; + st->Fs = 44100; ec_byte_writeinit(&st->buf); ec_enc_init(&st->enc,&st->buf); @@ -207,6 +210,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 gains[st->mode->nbPBands]; int pitch_index; @@ -228,6 +232,11 @@ int celt_encode(CELTEncoder *st, short *pcm) /* Compute MDCTs */ compute_mdcts(&st->mdct_lookup, st->window, in, X, N, B, C); + compute_masking(X, mask, B*C*N, st->Fs); + /* Invert and stretch the mask to length of X */ + for (i=B*C*N-1;i>=0;i--) + mask[i] = 1/(1+mask[i>>1]); + /* Pitch analysis */ for (c=0;cmode, X, P, &st->enc); + quant_bands(st->mode, X, P, mask, &st->enc); if (0) {//This is just for debugging ec_enc_done(&st->enc); diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index a4f50ec8..943c7e5b 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -52,8 +52,8 @@ int main(int argc, char *argv[]) outFile = argv[2]; fout = fopen(outFile, "wb+"); - enc = celt_encoder_new(celt_mode2); - dec = celt_decoder_new(celt_mode2); + enc = celt_encoder_new(celt_mode1); + dec = celt_decoder_new(celt_mode1); while (!feof(fin)) { diff --git a/libcelt/vq.c b/libcelt/vq.c index 40735875..46899c02 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -38,7 +38,7 @@ /* 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, float alpha, ec_enc *enc) +void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *enc) { int L = 3; //float tata[200]; @@ -223,7 +223,7 @@ void alg_quant(float *x, int N, int K, float *p, float alpha, ec_enc *enc) static const float pg[5] = {1.f, .6f, .45f, 0.35f, 0.25f}; /* Finds the right offset into Y and copy it */ -void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc) +void copy_quant(float *x, float *W, int N, int K, float *Y, int B, int N0, ec_enc *enc) { int i,j; int best=0; @@ -287,7 +287,7 @@ void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc) E = .8/sqrt(E); for (j=0;j