ref: 312132780efde133fa797f8ac08a8011e50f10af
parent: 730c6e392d2ce8cd370f0bf42517c76f502354fe
author: Jean-Marc Valin <[email protected]>
date: Mon Mar 3 11:52:54 EST 2008
A bunch of const qualifyers and a few comments
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -70,7 +70,7 @@
}
/* Compute the amplitude (sqrt energy) in each of the bands */
-void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bank)
+void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
@@ -92,7 +92,7 @@
}
/* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bank)
+void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
@@ -140,7 +140,7 @@
#endif
/* De-normalise the energy to produce the synthesis from the unit-energy bands */
-void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bank)
+void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq, const celt_ener_t *bank)
{
int i, c, B, C;
const int *eBands = m->eBands;
@@ -162,7 +162,7 @@
/* Compute the best gain for each "pitch band" */
-void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_pgain_t *gains)
+void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains)
{
int i, B;
const int *pBands = m->pBands;
@@ -197,12 +197,10 @@
printf ("%f ", 1-sqrt(1-gains[i]*gains[i]));
printf ("\n");
}*/
- for (i=B*pBands[m->nbPBands];i<B*pBands[m->nbPBands+1];i++)
- P[i] = 0;
}
/* Apply the (quantised) gain to each "pitch band" */
-void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, celt_pgain_t *gains)
+void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *gains)
{
int i, B;
const int *pBands = m->pBands;
@@ -345,7 +343,7 @@
RESTORE_STACK;
}
-void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir)
+void stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int dir)
{
int i, B, C;
const int *eBands = m->eBands;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -48,7 +48,7 @@
* @param X Spectrum
* @param bands Square root of the energy for each band (returned)
*/
-void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bands);
+void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bands);
/** Normalise each band of X such that the energy in each band is
equal to 1
@@ -56,7 +56,7 @@
* @param X Spectrum (returned normalised)
* @param bands Square root of the energy for each band
*/
-void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bands);
+void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bands);
void renormalise_bands(const CELTMode *m, celt_norm_t *X);
@@ -65,7 +65,7 @@
* @param X Spectrum (returned de-normalised)
* @param bands Square root of the energy for each band
*/
-void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bands);
+void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq, const celt_ener_t *bands);
/** Compute the pitch predictor gain for each pitch band
* @param m Mode data
@@ -74,9 +74,9 @@
* @param gains Gain computed for each pitch band (returned)
* @param bank Square root of the energy for each band
*/
-void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_pgain_t *gains);
+void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains);
-void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, celt_pgain_t *gains);
+void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *gains);
/** Quantisation/encoding of the residual spectrum
* @param m Mode data
@@ -97,6 +97,6 @@
*/
void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec);
-void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir);
+void stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int dir);
#endif /* BANDS_H */
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -46,7 +46,7 @@
#include "_kiss_fft_guts.h"
#include "kiss_fftr.h"
-void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *x, celt_sig_t *y, celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch)
+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)
{
int c, i;
float max_corr;
@@ -55,6 +55,7 @@
VARDECL(celt_mask_t *curve);
int n2;
int L2;
+ const int *bitrev;
SAVE_STACK;
n2 = lag/2;
L2 = len/2;
@@ -61,14 +62,16 @@
ALLOC(X, lag, celt_word32_t);
ALLOC(curve, n2, celt_mask_t);
+ bitrev = fft->substate->bitrev;
for (i=0;i<lag;i++)
X[i] = 0;
+ /* Sum all channels of the current frame and copy into X in bit-reverse order */
for (c=0;c<C;c++)
{
for (i=0;i<L2;i++)
{
- X[2*fft->substate->bitrev[i]] += SHR32(x[C*(2*i)+c],1);
- X[2*fft->substate->bitrev[i]+1] += SHR32(x[C*(2*i+1)+c],1);
+ X[2*bitrev[i]] += SHR32(x[C*(2*i)+c],1);
+ X[2*bitrev[i]+1] += SHR32(x[C*(2*i+1)+c],1);
}
}
/* Applying the window in the bit-reverse domain. It's a bit weird, but it
@@ -75,12 +78,12 @@
can help save memory */
for (i=0;i<overlap/2;i++)
{
- X[2*fft->substate->bitrev[i]] = MULT16_32_Q15(window[2*i], X[2*fft->substate->bitrev[i]]);
- X[2*fft->substate->bitrev[i]+1] = MULT16_32_Q15(window[2*i+1], X[2*fft->substate->bitrev[i]+1]);
- X[2*fft->substate->bitrev[L2-i-1]] = MULT16_32_Q15(window[2*i+1], X[2*fft->substate->bitrev[L2-i-1]]);
- X[2*fft->substate->bitrev[L2-i-1]+1] = MULT16_32_Q15(window[2*i], X[2*fft->substate->bitrev[L2-i-1]+1]);
+ X[2*bitrev[i]] = MULT16_32_Q15(window[2*i], X[2*bitrev[i]]);
+ X[2*bitrev[i]+1] = MULT16_32_Q15(window[2*i+1], X[2*bitrev[i]+1]);
+ X[2*bitrev[L2-i-1]] = MULT16_32_Q15(window[2*i+1], X[2*bitrev[L2-i-1]]);
+ X[2*bitrev[L2-i-1]+1] = MULT16_32_Q15(window[2*i], X[2*bitrev[L2-i-1]+1]);
}
-
+ /* Forward real FFT (in-place) */
kf_work((kiss_fft_cpx*)X, NULL, 1,1, fft->substate->factors,fft->substate, 1, 1, 1);
kiss_fftr_twiddles(fft,X);
@@ -90,17 +93,20 @@
ALLOC(Y, lag, celt_word32_t);
for (i=0;i<lag;i++)
Y[i] = 0;
+ /* Sum all channels of the past audio and copy into Y in bit-reverse order */
for (c=0;c<C;c++)
{
for (i=0;i<n2;i++)
{
- Y[2*fft->substate->bitrev[i]] += SHR32(y[C*(2*i)+c],1);
- Y[2*fft->substate->bitrev[i]+1] += SHR32(y[C*(2*i+1)+c],1);
+ Y[2*bitrev[i]] += SHR32(y[C*(2*i)+c],1);
+ Y[2*bitrev[i]+1] += SHR32(y[C*(2*i+1)+c],1);
}
}
+ /* Forward real FFT (in-place) */
kf_work((kiss_fft_cpx*)Y, NULL, 1,1, fft->substate->factors,fft->substate, 1, 1, 1);
kiss_fftr_twiddles(fft,Y);
+ /* Compute cross-spectrum using the inverse masking curve as weighting */
for (i=1;i<n2;i++)
{
float n, tmp;
@@ -115,10 +121,12 @@
}
/*printf ("\n");*/
X[0] = X[1] = 0;
+ /* Inverse half-complex to real FFT gives us the correlation */
kiss_fftri(fft, X, Y);
/*for (i=0;i<C*lag;i++)
printf ("%d %d\n", X[i], xx[i]);*/
+ /* The peak in the correlation gives us the pitch */
max_corr=-1e10;
*pitch = 0;
for (i=0;i<lag-len;i++)
--- a/libcelt/pitch.h
+++ b/libcelt/pitch.h
@@ -44,6 +44,6 @@
/** 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, celt_sig_t *x, celt_sig_t *y, celt_word16_t *window, int overlap, int lag, int len, int C, int *pitch);
+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);
#endif
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -63,7 +63,7 @@
/** Takes the pitch vector and the decoded residual vector (non-compressed),
applies the compression in the pitch direction, computes the gain that will
give ||p+g*y||=1 and mixes the residual with the pitch. */
-static void mix_pitch_and_residual(int *iy, celt_norm_t *X, int N, int K, celt_norm_t *P, celt_word16_t alpha)
+static void mix_pitch_and_residual(int *iy, celt_norm_t *X, int N, int K, const celt_norm_t *P, celt_word16_t alpha)
{
int i;
celt_word32_t Ryp, Ryy, Rpp;
@@ -119,7 +119,7 @@
celt_word32_t yp;
};
-void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, celt_norm_t *P, celt_word16_t alpha, ec_enc *enc)
+void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *P, celt_word16_t alpha, ec_enc *enc)
{
int L = 3;
VARDECL(celt_norm_t *_y);
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -51,7 +51,7 @@
* @param alpha compression factor to apply in the pitch direction (magic!)
* @param enc Entropy encoder state
*/
-void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, celt_norm_t *P, celt_word16_t alpha, ec_enc *enc);
+void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *P, celt_word16_t alpha, ec_enc *enc);
/** Algebraic pulse decoder
* @param x Decoded normalised spectrum (returned)