From 137ec8e9b83c46d1d0491f7e15ba0ec0426246a2 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 3 Mar 2008 14:44:42 +1100 Subject: [PATCH] applying the pitch windowing directly in find_spectral_pitch() --- libcelt/celt.c | 6 +++--- libcelt/pitch.c | 16 +++++++++++++--- libcelt/pitch.h | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 4a91523c..2a502ecb 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -291,15 +291,15 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i mask[i] = 1/(.1+mask[i]); #endif /* Pitch analysis */ - for (c=0;coverlap;i++) { in[C*i+c] = MULT16_32_Q15(st->mode->window[i], in[C*i+c]); in[C*(B*N+N-i-2*N4-1)+c] = MULT16_32_Q15(st->mode->window[i], in[C*(B*N+N-i-2*N4-1)+c]); } - } - find_spectral_pitch(st->fft, &st->psy, in, st->out_mem, MAX_PERIOD, (B+1)*N-2*N4, C, &pitch_index); + }*/ + find_spectral_pitch(st->fft, &st->psy, in, st->out_mem, st->mode->window, st->overlap, MAX_PERIOD, (B+1)*N-2*N4, C, &pitch_index); /* Deferred allocation after find_spectral_pitch() to reduce the peak memory usage */ ALLOC(X, B*C*N, celt_norm_t); /**< Interleaved normalised MDCTs */ diff --git a/libcelt/pitch.c b/libcelt/pitch.c index 4e64a5a4..f67fd174 100644 --- a/libcelt/pitch.c +++ b/libcelt/pitch.c @@ -46,7 +46,7 @@ #include "_kiss_fft_guts.h" #include "kiss_fftr.h" -void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *x, celt_sig_t *y, int lag, int len, int C, int *pitch) +void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *x, celt_sig_t *y, celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch) { int c, i; float max_corr; @@ -54,8 +54,10 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t * VARDECL(celt_word32_t *Y); VARDECL(celt_mask_t *curve); int n2; + int L2; SAVE_STACK; n2 = lag/2; + L2 = len/2; ALLOC(X, lag, celt_word32_t); ALLOC(curve, n2, celt_mask_t); @@ -63,12 +65,20 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t * X[i] = 0; for (c=0;csubstate->bitrev[i]] += SHR32(x[C*(2*i)+c],1); X[2*fft->substate->bitrev[i]+1] += SHR32(x[C*(2*i+1)+c],1); } } + for (i=0;isubstate->bitrev[i]] = MULT16_32_Q15(window[2*i], X[2*fft->substate->bitrev[i]]); + X[2*fft->substate->bitrev[i]+1] = MULT16_32_Q15(window[2*i+1], X[2*fft->substate->bitrev[i]+1]); + X[2*fft->substate->bitrev[len-i-1]] = MULT16_32_Q15(window[2*i], X[2*fft->substate->bitrev[len-i-1]]); + X[2*fft->substate->bitrev[len-i-1]+1] = MULT16_32_Q15(window[2*i+1], X[2*fft->substate->bitrev[len-i-1]+1]); + } + kf_work((kiss_fft_cpx*)X, NULL, 1,1, fft->substate->factors,fft->substate, 1, 1, 1); kiss_fftr_twiddles(fft,X); @@ -80,7 +90,7 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t * Y[i] = 0; for (c=0;csubstate->bitrev[i]] += SHR32(y[C*(2*i)+c],1); Y[2*fft->substate->bitrev[i]+1] += SHR32(y[C*(2*i+1)+c],1); diff --git a/libcelt/pitch.h b/libcelt/pitch.h index 45fe1a7d..ba3b629f 100644 --- a/libcelt/pitch.h +++ b/libcelt/pitch.h @@ -44,6 +44,6 @@ /** Find the optimal delay for the pitch prediction. Computation is done in the frequency domain, both to save time and to make it easier to apply psychoacoustic weighting */ -void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *x, celt_sig_t *y, int lag, int len, int C, int *pitch); +void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *x, celt_sig_t *y, celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch); #endif