shithub: opus

Download patch

ref: e6b74650876a904bfef14c952fe9411773b2c289
parent: 276de7211d5d954c2b81f699e7c9f05b84cb2cbc
author: Jean-Marc Valin <[email protected]>
date: Wed Feb 20 13:01:08 EST 2008

Some sampling rate cleanup (now in the mode)

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -63,7 +63,6 @@
    int nb_blocks;
    int overlap;
    int channels;
-   int Fs;
    
    ec_byte_buffer buf;
    ec_enc         enc;
@@ -100,7 +99,6 @@
    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 @@
 
    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));
--- a/libcelt/kiss_fft.h
+++ b/libcelt/kiss_fft.h
@@ -48,7 +48,7 @@
 
 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 @@
 
 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 @@
 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.
 */
--- a/libcelt/laplace.h
+++ b/libcelt/laplace.h
@@ -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);
--- a/libcelt/mdct.h
+++ b/libcelt/mdct.h
@@ -53,6 +53,10 @@
 
 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);
 
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -243,6 +243,7 @@
    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;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -39,6 +39,7 @@
  @brief Mode definition 
  */
 struct CELTMode {
+   int          Fs;
    int          overlap;
    int          mdctSize;
    int          nbMdctBlocks;
--- a/libcelt/pitch.h
+++ b/libcelt/pitch.h
@@ -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
--- a/libcelt/psy.h
+++ b/libcelt/psy.h
@@ -36,12 +36,16 @@
    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 */