Commit e6b74650 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Some sampling rate cleanup (now in the mode)

parent 276de721
......@@ -63,7 +63,6 @@ struct CELTEncoder {
int nb_blocks;
int overlap;
int channels;
int Fs;
ec_byte_buffer buf;
ec_enc enc;
......@@ -100,7 +99,6 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode)
st->block_size = N;
st->nb_blocks = B;
st->overlap = mode->overlap;
st->Fs = 44100;
N4 = (N-st->overlap)/2;
ec_byte_writeinit(&st->buf);
......@@ -108,7 +106,7 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode)
mdct_init(&st->mdct_lookup, 2*N);
st->fft = kiss_fftr_alloc(MAX_PERIOD*C, 0, 0);
psydecay_init(&st->psy, MAX_PERIOD*C/2, st->Fs);
psydecay_init(&st->psy, MAX_PERIOD*C/2, st->mode->Fs);
st->window = celt_alloc(2*N*sizeof(float));
st->in_mem = celt_alloc(N*C*sizeof(float));
......
......@@ -48,7 +48,7 @@ typedef struct {
typedef struct kiss_fft_state* kiss_fft_cfg;
/*
/**
* kiss_fft_alloc
*
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
......@@ -73,7 +73,7 @@ typedef struct kiss_fft_state* kiss_fft_cfg;
kiss_fft_cfg kiss_fft_alloc(int nfft,void * mem,size_t * lenmem);
/*
/**
* kiss_fft(cfg,in_out_buf)
*
* Perform an FFT on a complex input buffer.
......@@ -86,17 +86,17 @@ kiss_fft_cfg kiss_fft_alloc(int nfft,void * mem,size_t * lenmem);
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
void kiss_ifft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
/*
/**
A more generic version of the above function. It reads its input from every Nth sample.
* */
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
void kiss_ifft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
/** If kiss_fft_alloc allocated a buffer, it is one contiguous
buffer and can be simply free()d when no longer needed*/
#define kiss_fft_free celt_free
/*
/**
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
your compiler output to call this before you exit.
*/
......
......@@ -32,6 +32,18 @@
#include "entenc.h"
#include "entdec.h"
/** Encode a value that is assumed to be the realisation of a
Laplace-distributed random process
@param enc Entropy encoder state
@param value Value to encode
@param decay Probability of the value +/- 1, multiplied by 16384
*/
void ec_laplace_encode(ec_enc *enc, int value, int decay);
/** Decode a value that is assumed to be the realisation of a
Laplace-distributed random process
@param dec Entropy decoder state
@param decay Probability of the value +/- 1, multiplied by 16384
@return Value decoded
*/
int ec_laplace_decode(ec_dec *dec, int decay);
......@@ -53,6 +53,10 @@ typedef struct {
void mdct_init(mdct_lookup *l,int N);
void mdct_clear(mdct_lookup *l);
/** Compute a forward MDCT and scale by 2/N */
void mdct_forward(mdct_lookup *l, float *in, float *out);
/** Compute a backward MDCT (no scaling) */
void mdct_backward(mdct_lookup *l, float *in, float *out);
......@@ -243,6 +243,7 @@ CELTMode *celt_mode_create(int Fs, int channels, int frame_size, int lookahead,
res = (Fs+frame_size)/(2*frame_size);
mode = celt_alloc(sizeof(CELTMode));
mode->Fs = Fs;
mode->overlap = lookahead;
mode->mdctSize = frame_size;
mode->nbMdctBlocks = 1;
......
......@@ -39,6 +39,7 @@
@brief Mode definition
*/
struct CELTMode {
int Fs;
int overlap;
int mdctSize;
int nbMdctBlocks;
......
......@@ -41,6 +41,9 @@
#include "kiss_fftr.h"
#include "psy.h"
/** 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, float *x, float *y, int lag, int len, int C, int *pitch);
#endif
......@@ -36,12 +36,16 @@ struct PsyDecay {
float *decayR;
};
/** Pre-compute the decay of the psycho-acoustic spreading function */
void psydecay_init(struct PsyDecay *decay, int len, int Fs);
/** Free the memory allocated for the spreading function */
void psydecay_clear(struct PsyDecay *decay);
/** Compute the masking curve for an input (DFT) spectrum X */
void compute_masking(struct PsyDecay *decay, float *X, float *mask, int len, int Fs);
/** Compute the masking curve for an input (MDCT) spectrum X */
void compute_mdct_masking(struct PsyDecay *decay, float *X, float *mask, int len, int Fs);
#endif /* PSY_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment