Moved the psycoacoustics data to the mode struct
This commit is contained in:
parent
defa357525
commit
29f52990b9
7 changed files with 15 additions and 13 deletions
|
@ -49,8 +49,6 @@
|
||||||
#include "psy.h"
|
#include "psy.h"
|
||||||
#include "rate.h"
|
#include "rate.h"
|
||||||
|
|
||||||
#define MAX_PERIOD 1024
|
|
||||||
|
|
||||||
static const celt_word16_t preemph = QCONST16(0.8f,15);
|
static const celt_word16_t preemph = QCONST16(0.8f,15);
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +70,6 @@ struct CELTEncoder {
|
||||||
celt_sig_t *preemph_memD;
|
celt_sig_t *preemph_memD;
|
||||||
|
|
||||||
kiss_fftr_cfg fft;
|
kiss_fftr_cfg fft;
|
||||||
struct PsyDecay psy;
|
|
||||||
|
|
||||||
celt_sig_t *in_mem;
|
celt_sig_t *in_mem;
|
||||||
celt_sig_t *mdct_overlap;
|
celt_sig_t *mdct_overlap;
|
||||||
|
@ -104,7 +101,6 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode)
|
||||||
ec_enc_init(&st->enc,&st->buf);
|
ec_enc_init(&st->enc,&st->buf);
|
||||||
|
|
||||||
st->fft = pitch_state_alloc(MAX_PERIOD);
|
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->in_mem = celt_alloc(N*C*sizeof(celt_sig_t));
|
||||||
st->mdct_overlap = 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);
|
ec_byte_writeclear(&st->buf);
|
||||||
|
|
||||||
pitch_state_free(st->fft);
|
pitch_state_free(st->fft);
|
||||||
psydecay_clear(&st->psy);
|
|
||||||
|
|
||||||
celt_free(st->in_mem);
|
celt_free(st->in_mem);
|
||||||
celt_free(st->mdct_overlap);
|
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];
|
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 */
|
/* 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 */
|
ALLOC(freq, B*C*N, celt_sig_t); /**< Interleaved signal MDCTs */
|
||||||
|
|
||||||
|
|
|
@ -288,6 +288,7 @@ CELTMode *celt_mode_create(celt_int32_t Fs, int channels, int frame_size, int lo
|
||||||
#endif
|
#endif
|
||||||
mdct_init(&mode->mdct, 2*mode->mdctSize);
|
mdct_init(&mode->mdct, 2*mode->mdctSize);
|
||||||
compute_alloc_cache(mode);
|
compute_alloc_cache(mode);
|
||||||
|
psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs);
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +307,7 @@ void celt_mode_destroy(CELTMode *mode)
|
||||||
}
|
}
|
||||||
celt_free((int**)mode->bits);
|
celt_free((int**)mode->bits);
|
||||||
mdct_clear(&mode->mdct);
|
mdct_clear(&mode->mdct);
|
||||||
|
psydecay_clear(&mode->psy);
|
||||||
#ifndef STATIC_MODES
|
#ifndef STATIC_MODES
|
||||||
if (check_mode(mode) != CELT_OK)
|
if (check_mode(mode) != CELT_OK)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include "celt.h"
|
#include "celt.h"
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "mdct.h"
|
#include "mdct.h"
|
||||||
|
#include "psy.h"
|
||||||
|
|
||||||
|
#define MAX_PERIOD 1024
|
||||||
|
|
||||||
/** Mode definition (opaque)
|
/** Mode definition (opaque)
|
||||||
@brief Mode definition
|
@brief Mode definition
|
||||||
|
@ -67,6 +70,8 @@ struct CELTMode {
|
||||||
|
|
||||||
const celt_word16_t *window;
|
const celt_word16_t *window;
|
||||||
|
|
||||||
|
struct PsyDecay psy;
|
||||||
|
|
||||||
celt_uint32_t marker_end;
|
celt_uint32_t marker_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ static void normalise16(celt_word16_t *x, int len, celt_word16_t val)
|
||||||
|
|
||||||
#define INPUT_SHIFT 15
|
#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;
|
int c, i;
|
||||||
celt_word32_t max_corr;
|
celt_word32_t max_corr;
|
||||||
|
|
|
@ -47,6 +47,6 @@ void pitch_state_free(kiss_fftr_cfg st);
|
||||||
/** Find the optimal delay for the pitch prediction. Computation is
|
/** Find the optimal delay for the pitch prediction. Computation is
|
||||||
done in the frequency domain, both to save time and to make it
|
done in the frequency domain, both to save time and to make it
|
||||||
easier to apply psychoacoustic weighting */
|
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
|
#endif
|
||||||
|
|
|
@ -76,7 +76,7 @@ void psydecay_clear(struct PsyDecay *decay)
|
||||||
/*celt_free(decay->decayL);*/
|
/*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;
|
int i;
|
||||||
celt_word32_t mem;
|
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. */
|
/* 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 i;
|
||||||
int N;
|
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 */
|
#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;
|
int i;
|
||||||
VARDECL(float *psd);
|
VARDECL(float *psd);
|
||||||
|
|
|
@ -45,9 +45,9 @@ void psydecay_init(struct PsyDecay *decay, int len, celt_int32_t Fs);
|
||||||
void psydecay_clear(struct PsyDecay *decay);
|
void psydecay_clear(struct PsyDecay *decay);
|
||||||
|
|
||||||
/** Compute the masking curve for an input (DFT) spectrum X */
|
/** 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 */
|
/** 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 */
|
#endif /* PSY_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue