diff --git a/libcelt/celt.c b/libcelt/celt.c index 55d1c42d..3d106bb8 100644 --- 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 @@ struct CELTEncoder { 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 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode) 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 @@ void celt_encoder_destroy(CELTEncoder *st) 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 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i 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 */ diff --git a/libcelt/modes.c b/libcelt/modes.c index f5d13d49..5b781f49 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -288,6 +288,7 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo #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 @@ void celt_mode_destroy(CELTMode *mode) } celt_free((int**)mode->bits); mdct_clear(&mode->mdct); + psydecay_clear(&mode->psy); #ifndef STATIC_MODES if (check_mode(mode) != CELT_OK) return; diff --git a/libcelt/modes.h b/libcelt/modes.h index 62b98366..fdb48507 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -36,6 +36,9 @@ #include "celt.h" #include "arch.h" #include "mdct.h" +#include "psy.h" + +#define MAX_PERIOD 1024 /** Mode definition (opaque) @brief Mode definition @@ -67,6 +70,8 @@ struct CELTMode { const celt_word16_t *window; + struct PsyDecay psy; + celt_uint32_t marker_end; }; diff --git a/libcelt/pitch.c b/libcelt/pitch.c index 88b564ed..01f6db8f 100644 --- a/libcelt/pitch.c +++ b/libcelt/pitch.c @@ -101,7 +101,7 @@ static void normalise16(celt_word16_t *x, int len, celt_word16_t val) #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; diff --git a/libcelt/pitch.h b/libcelt/pitch.h index 062f1262..9ce0ce7f 100644 --- a/libcelt/pitch.h +++ b/libcelt/pitch.h @@ -47,6 +47,6 @@ void pitch_state_free(kiss_fftr_cfg st); /** 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 diff --git a/libcelt/psy.c b/libcelt/psy.c index 6955a36f..2ae547f7 100644 --- a/libcelt/psy.c +++ b/libcelt/psy.c @@ -76,7 +76,7 @@ void psydecay_clear(struct PsyDecay *decay) /*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 @@ static void spreading_func(struct PsyDecay *d, celt_word32_t *psd, celt_mask_t * } /* 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 @@ void compute_masking(struct PsyDecay *decay, celt_word16_t *X, celt_mask_t *mask } #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); diff --git a/libcelt/psy.h b/libcelt/psy.h index c37b844c..2a0ba3ea 100644 --- a/libcelt/psy.h +++ b/libcelt/psy.h @@ -45,9 +45,9 @@ void psydecay_init(struct PsyDecay *decay, int len, celt_int32_t Fs); 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 */