applying the pitch windowing directly in find_spectral_pitch()
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Mon, 3 Mar 2008 03:44:42 +0000 (14:44 +1100)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Mon, 3 Mar 2008 03:44:42 +0000 (14:44 +1100)
libcelt/celt.c
libcelt/pitch.c
libcelt/pitch.h

index 4a91523..2a502ec 100644 (file)
@@ -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;c<C;c++)
+   /*for (c=0;c<C;c++)
    {
       for (i=0;i<st->overlap;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 */
index 4e64a5a..f67fd17 100644 (file)
@@ -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;c<C;c++)
    {
-      for (i=0;i<len/2;i++)
+      for (i=0;i<L2;i++)
       {
          X[2*fft->substate->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;i<overlap/2;i++)
+   {
+      X[2*fft->substate->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;c<C;c++)
    {
-      for (i=0;i<lag/2;i++)
+      for (i=0;i<n2;i++)
       {
          Y[2*fft->substate->bitrev[i]] += SHR32(y[C*(2*i)+c],1);
          Y[2*fft->substate->bitrev[i]+1] += SHR32(y[C*(2*i+1)+c],1);
index 45fe1a7..ba3b629 100644 (file)
@@ -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