ref: c6ca49923e36f7e35b20bb22134d556ddf74619b
parent: 13294b54c02134dd13a1ae4ce08f75dac297248d
author: Jean-Marc Valin <[email protected]>
date: Sun Jun 1 19:19:16 EDT 2008
Infrastructure work for a psy model
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -73,6 +73,10 @@
celt_sig_t *out_mem;
celt_word16_t *oldBandE;
+#ifdef EXP_PSY
+ celt_word16_t *psy_mem;
+ struct PsyDecay psy;
+#endif
};
CELTEncoder EXPORT *celt_encoder_create(const CELTMode *mode)
@@ -103,6 +107,11 @@
st->preemph_memE = (celt_word16_t*)celt_alloc(C*sizeof(celt_word16_t));;
st->preemph_memD = (celt_sig_t*)celt_alloc(C*sizeof(celt_sig_t));;
+#ifdef EXP_PSY
+ st->psy_mem = celt_alloc(MAX_PERIOD*sizeof(celt_word16_t));
+ psydecay_init(&st->psy, MAX_PERIOD/2, st->mode->Fs);
+#endif
+
return st;
}
@@ -126,6 +135,11 @@
celt_free(st->preemph_memE);
celt_free(st->preemph_memD);
+#ifdef EXP_PSY
+ celt_free (st->psy_mem);
+ psydecay_clear(&st->psy);
+#endif
+
celt_free(st);
}
@@ -224,6 +238,9 @@
VARDECL(celt_ener_t, bandE);
VARDECL(celt_pgain_t, gains);
VARDECL(int, stereo_mode);
+#ifdef EXP_PSY
+ VARDECL(celt_word32_t, mask);
+#endif
const int C = CHANNELS(st->mode);
SAVE_STACK;
@@ -260,13 +277,21 @@
/* Compute MDCTs */
compute_mdcts(st->mode, st->mode->window, in, freq);
-#if 0 /* Mask disabled until it can be made to do something useful */
- compute_mdct_masking(X, mask, B*C*N, st->Fs);
+#ifdef EXP_PSY
+ CELT_MOVE(st->psy_mem, st->out_mem+N, MAX_PERIOD+st->overlap-N);
+ for (i=0;i<N;i++)
+ st->psy_mem[MAX_PERIOD+st->overlap-N+i] = in[C*(st->overlap+i)];
+ for (c=1;c<C;c++)
+ for (i=0;i<N;i++)
+ st->psy_mem[MAX_PERIOD+st->overlap-N+i] += in[C*(st->overlap+i)+c];
+ ALLOC(mask, N, celt_sig_t);
+ compute_mdct_masking(&st->psy, freq, st->psy_mem, mask, C*N);
+
/* Invert and stretch the mask to length of X
For some reason, I get better results by using the sqrt instead,
although there's no valid reason to. Must investigate further */
- for (i=0;i<B*C*N;i++)
+ for (i=0;i<C*N;i++)
mask[i] = 1/(.1+mask[i]);
#endif
--- a/libcelt/psy.c
+++ b/libcelt/psy.c
@@ -143,8 +143,8 @@
spreading_func(decay, mask, N);
}
-#if 0 /* Not needed for now, but will be useful in the future */
-void compute_mdct_masking(const struct PsyDecay *decay, celt_word32_t *X, celt_mask_t *mask, int len)
+#ifdef EXP_PSY /* Not needed for now, but will be useful in the future */
+void compute_mdct_masking(const struct PsyDecay *decay, celt_word32_t *X, celt_word16_t *long_window, celt_mask_t *mask, int len)
{
int i;
VARDECL(float, psd);
--- a/libcelt/psy.h
+++ b/libcelt/psy.h
@@ -48,6 +48,6 @@
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(const 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_word16_t *long_window, celt_mask_t *mask, int len);
#endif /* PSY_H */