shithub: opus

Download patch

ref: 29f52990b900af8f8014f4295925e538724d2be0
parent: defa3575259b1a81a977befe8874797e783a6c53
author: Jean-Marc Valin <[email protected]>
date: Mon Mar 10 09:34:52 EDT 2008

Moved the psycoacoustics data to the mode struct

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -49,8 +49,6 @@
 #include "psy.h"
 #include "rate.h"
 
-#define MAX_PERIOD 1024
-
 static const celt_word16_t preemph = QCONST16(0.8f,15);
 
 
@@ -72,7 +70,6 @@
    celt_sig_t *preemph_memD;
 
    kiss_fftr_cfg fft;
-   struct PsyDecay psy;
 
    celt_sig_t *in_mem;
    celt_sig_t *mdct_overlap;
@@ -104,7 +101,6 @@
    ec_enc_init(&st->enc,&st->buf);
 
    st->fft = pitch_state_alloc(MAX_PERIOD);
-   psydecay_init(&st->psy, MAX_PERIOD/2, st->mode->Fs);
    
    st->in_mem = celt_alloc(N*C*sizeof(celt_sig_t));
    st->mdct_overlap = celt_alloc(N*C*sizeof(celt_sig_t));
@@ -131,7 +127,6 @@
    ec_byte_writeclear(&st->buf);
 
    pitch_state_free(st->fft);
-   psydecay_clear(&st->psy);
 
    celt_free(st->in_mem);
    celt_free(st->mdct_overlap);
@@ -274,7 +269,7 @@
          st->in_mem[C*i+c] = in[C*(N*(B+1)-2*N4-st->overlap+i)+c];
    }
    /* Pitch analysis: we do it early to save on the peak stack space */
-   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);
+   find_spectral_pitch(st->fft, &st->mode->psy, in, st->out_mem, st->mode->window, st->overlap, MAX_PERIOD, (B+1)*N-2*N4, C, &pitch_index);
 
    ALLOC(freq, B*C*N, celt_sig_t); /**< Interleaved signal MDCTs */
    
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -288,6 +288,7 @@
 #endif
    mdct_init(&mode->mdct, 2*mode->mdctSize);
    compute_alloc_cache(mode);
+   psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs);
 
    return mode;
 }
@@ -306,6 +307,7 @@
    }
    celt_free((int**)mode->bits);
    mdct_clear(&mode->mdct);
+   psydecay_clear(&mode->psy);
 #ifndef STATIC_MODES
    if (check_mode(mode) != CELT_OK)
       return;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -36,7 +36,10 @@
 #include "celt.h"
 #include "arch.h"
 #include "mdct.h"
+#include "psy.h"
 
+#define MAX_PERIOD 1024
+
 /** Mode definition (opaque)
  @brief Mode definition 
  */
@@ -66,6 +69,8 @@
    mdct_lookup mdct;
    
    const celt_word16_t *window;
+
+   struct PsyDecay psy;
 
    celt_uint32_t marker_end;
 };
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -101,7 +101,7 @@
 
 #define INPUT_SHIFT 15
 
-void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, const celt_sig_t *x, const celt_sig_t *y, const celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch)
+void find_spectral_pitch(kiss_fftr_cfg fft, const struct PsyDecay *decay, const celt_sig_t *x, const celt_sig_t *y, const celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch)
 {
    int c, i;
    celt_word32_t max_corr;
--- a/libcelt/pitch.h
+++ b/libcelt/pitch.h
@@ -47,6 +47,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, const celt_sig_t *x, const celt_sig_t *y, const celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch);
+void find_spectral_pitch(kiss_fftr_cfg fft, const struct PsyDecay *decay, const celt_sig_t *x, const celt_sig_t *y, const celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch);
 
 #endif
--- a/libcelt/psy.c
+++ b/libcelt/psy.c
@@ -76,7 +76,7 @@
    /*celt_free(decay->decayL);*/
 }
 
-static void spreading_func(struct PsyDecay *d, celt_word32_t *psd, celt_mask_t *mask, int len)
+static void spreading_func(const struct PsyDecay *d, celt_word32_t *psd, celt_mask_t *mask, int len)
 {
    int i;
    celt_word32_t mem;
@@ -129,7 +129,7 @@
 }
 
 /* Compute a marking threshold from the spectrum X. */
-void compute_masking(struct PsyDecay *decay, celt_word16_t *X, celt_mask_t *mask, int len)
+void compute_masking(const struct PsyDecay *decay, celt_word16_t *X, celt_mask_t *mask, int len)
 {
    int i;
    int N;
@@ -143,7 +143,7 @@
 }
 
 #if 0 /* Not needed for now, but will be useful in the future */
-void compute_mdct_masking(struct PsyDecay *decay, celt_word32_t *X, celt_mask_t *mask, int len)
+void compute_mdct_masking(const struct PsyDecay *decay, celt_word32_t *X, celt_mask_t *mask, int len)
 {
    int i;
    VARDECL(float *psd);
--- a/libcelt/psy.h
+++ b/libcelt/psy.h
@@ -45,9 +45,9 @@
 void psydecay_clear(struct PsyDecay *decay);
 
 /** Compute the masking curve for an input (DFT) spectrum X */
-void compute_masking(struct PsyDecay *decay, celt_word16_t *X, celt_mask_t *mask, int len);
+void compute_masking(const struct PsyDecay *decay, celt_word16_t *X, celt_mask_t *mask, int len);
 
 /** Compute the masking curve for an input (MDCT) spectrum X */
-void compute_mdct_masking(struct PsyDecay *decay, celt_word32_t *X, celt_mask_t *mask, int len);
+void compute_mdct_masking(const struct PsyDecay *decay, celt_word32_t *X, celt_mask_t *mask, int len);
 
 #endif /* PSY_H */