From 4213a7254c6192788199da84aed67e2d36d1a02a Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca> Date: Thu, 1 Oct 2009 19:42:18 -0400 Subject: [PATCH] Demoved the divisions from the inner pitch prediction loops, bumped the version and bit-stream version --- configure.ac | 4 ++-- libcelt/bands.c | 49 ++++++++++++++++++++++++++++++++----------------- libcelt/bands.h | 11 +++-------- libcelt/celt.c | 8 ++++---- libcelt/modes.h | 2 +- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/configure.ac b/configure.ac index 10af6eea3..4f13d7e6a 100644 --- a/configure.ac +++ b/configure.ac @@ -5,8 +5,8 @@ AC_INIT(libcelt/arch.h) AM_CONFIG_HEADER([config.h]) CELT_MAJOR_VERSION=0 -CELT_MINOR_VERSION=6 -CELT_MICRO_VERSION=1 +CELT_MINOR_VERSION=7 +CELT_MICRO_VERSION=0 CELT_EXTRA_VERSION= CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION diff --git a/libcelt/bands.c b/libcelt/bands.c index 5314b0c54..0be62eb53 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -216,13 +216,14 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s } } -int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id) +int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id) { - int j ; + int j, c; celt_word16_t g; + celt_word16_t delta; const int C = CHANNELS(m); celt_word32_t Sxy=0, Sxx=0, Syy=0; - int len = m->pitchEnd*C; + int len = m->pitchEnd; #ifdef FIXED_POINT int shift = 0; celt_word32_t maxabs=0; @@ -235,15 +236,20 @@ int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t * if (shift<0) shift = 0; #endif - for (j=0;j<len;j++) + delta = PDIV32_16(Q15ONE, len); + for (c=0;c<C;c++) { - celt_word16_t gg = Q15ONE-DIV32_16(MULT16_16(Q15ONE,j),len); - celt_word16_t Xj, Pj; - Xj = EXTRACT16(SHR32(X[j], shift)); - Pj = MULT16_16_P15(gg,EXTRACT16(SHR32(P[j], shift))); - Sxy = MAC16_16(Sxy, Xj, Pj); - Sxx = MAC16_16(Sxx, Pj, Pj); - Syy = MAC16_16(Syy, Xj, Xj); + celt_word16_t gg = Q15ONE; + for (j=0;j<len;j++) + { + celt_word16_t Xj, Pj; + Xj = EXTRACT16(SHR32(X[C*j+c], shift)); + Pj = MULT16_16_P15(gg,EXTRACT16(SHR32(P[C*j+c], shift))); + Sxy = MAC16_16(Sxy, Xj, Pj); + Sxx = MAC16_16(Sxx, Pj, Pj); + Syy = MAC16_16(Syy, Xj, Xj); + gg = SUB16(gg, delta); + } } #ifdef FIXED_POINT { @@ -286,19 +292,28 @@ int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t * } } -void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred) +void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred) { - int j; + int j, c; celt_word16_t gain; + celt_word16_t delta; const int C = CHANNELS(m); - int len = m->pitchEnd*C; + int len = m->pitchEnd; + gain = ADD16(QCONST16(.5,14), MULT16_16_16(QCONST16(.05,14),gain_id)); + delta = PDIV32_16(gain, len); if (pred) gain = -gain; - for (j=0;j<len;j++) + else + delta = -delta; + for (c=0;c<C;c++) { - celt_word16_t gg = SUB16(gain, DIV32_16(MULT16_16(gain,j),len)); - X[j] += SHL(MULT16_32_Q15(gg,P[j]),1); + celt_word16_t gg = gain; + for (j=0;j<len;j++) + { + X[C*j+c] += SHL(MULT16_32_Q15(gg,P[C*j+c]),1); + gg = ADD16(gg, delta); + } } } diff --git a/libcelt/bands.h b/libcelt/bands.h index c888b07a2..ad4a5e0f5 100644 --- a/libcelt/bands.h +++ b/libcelt/bands.h @@ -64,10 +64,6 @@ void renormalise_bands(const CELTMode *m, celt_norm_t * restrict X); */ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_sig_t * restrict freq, const celt_ener_t *bands); -int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id); - -void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred); - /** Compute the pitch predictor gain for each pitch band * @param m Mode data * @param X Spectrum to predict @@ -75,15 +71,15 @@ void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int * @param gains Gain computed for each pitch band (returned) * @param bank Square root of the energy for each band */ -int compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains); +int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t *P, int norm_rate, int *gain_id); + +void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain_id, int pred); int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int *last_decision); /** Quantisation/encoding of the residual spectrum * @param m Mode data * @param X Residual (normalised) - * @param P Pitch vector (normalised) - * @param W Perceptual weighting * @param total_bits Total number of bits that can be used for the frame (including the ones already spent) * @param enc Entropy encoder */ @@ -94,7 +90,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, const celt_ /** Decoding of the residual spectrum * @param m Mode data * @param X Residual (normalised) - * @param P Pitch vector (normalised) * @param total_bits Total number of bits that can be used for the frame (including the ones already spent) * @param dec Entropy decoder */ diff --git a/libcelt/celt.c b/libcelt/celt.c index 1c5965444..2f36b27e8 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -679,11 +679,11 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si { compute_mdcts(st->mode, 0, st->out_mem+pitch_index*C, pitch_freq); - has_pitch = compute_new_pitch(st->mode, freq, pitch_freq, norm_rate, &gain_id); + has_pitch = compute_pitch_gain(st->mode, freq, pitch_freq, norm_rate, &gain_id); } if (has_pitch) - apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 1); + apply_pitch(st->mode, freq, pitch_freq, gain_id, 1); compute_band_energies(st->mode, freq, bandE); for (i=0;i<st->mode->nbEBands*C;i++) @@ -797,7 +797,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si #endif } if (has_pitch) - apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 0); + apply_pitch(st->mode, freq, pitch_freq, gain_id, 0); compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem); /* De-emphasis and put everything back at the right place @@ -1328,7 +1328,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int } if (has_pitch) - apply_new_pitch(st->mode, freq, pitch_freq, gain_id, 0); + apply_pitch(st->mode, freq, pitch_freq, gain_id, 0); /* Compute inverse MDCTs */ compute_inv_mdcts(st->mode, shortBlocks, freq, transient_time, transient_shift, st->out_mem); diff --git a/libcelt/modes.h b/libcelt/modes.h index b7ff76368..074e7cc7a 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -39,7 +39,7 @@ #include "psy.h" #include "pitch.h" -#define CELT_BITSTREAM_VERSION 0x80000009 +#define CELT_BITSTREAM_VERSION 0x8000000a #ifdef STATIC_MODES #include "static_modes.h" -- GitLab