fixed-point: added a celt_ener_t type for band energy.

This commit is contained in:
Jean-Marc Valin 2008-02-26 14:46:26 +11:00
parent e046c18acf
commit e901fe35b8
6 changed files with 33 additions and 30 deletions

View file

@ -53,6 +53,7 @@ typedef celt_int32_t celt_word32_t;
typedef celt_word32_t celt_sig_t; typedef celt_word32_t celt_sig_t;
typedef celt_word16_t celt_norm_t; typedef celt_word16_t celt_norm_t;
typedef float celt_ener_t;
#define Q15ONE 32767 #define Q15ONE 32767
@ -102,6 +103,7 @@ typedef float celt_word32_t;
typedef float celt_sig_t; typedef float celt_sig_t;
typedef float celt_norm_t; typedef float celt_norm_t;
typedef float celt_ener_t;
#define Q15ONE 1.0f #define Q15ONE 1.0f
#define LPC_SCALING 1.f #define LPC_SCALING 1.f

View file

@ -70,7 +70,7 @@ static void exp_rotation(celt_norm_t *X, int len, float theta, int dir, int stri
} }
/* Compute the amplitude (sqrt energy) in each of the bands */ /* Compute the amplitude (sqrt energy) in each of the bands */
void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bank) void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bank)
{ {
int i, c, B, C; int i, c, B, C;
const int *eBands = m->eBands; const int *eBands = m->eBands;
@ -92,7 +92,7 @@ void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bank)
} }
/* Normalise each band such that the energy is one. */ /* Normalise each band such that the energy is one. */
void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float *bank) void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bank)
{ {
int i, c, B, C; int i, c, B, C;
const int *eBands = m->eBands; const int *eBands = m->eBands;
@ -114,15 +114,15 @@ void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float
void renormalise_bands(const CELTMode *m, celt_norm_t *X) void renormalise_bands(const CELTMode *m, celt_norm_t *X)
{ {
VARDECL(float *tmpE); VARDECL(celt_ener_t *tmpE);
ALLOC(tmpE, m->nbEBands*m->nbChannels, float); ALLOC(tmpE, m->nbEBands*m->nbChannels, celt_ener_t);
compute_band_energies(m, X, tmpE); compute_band_energies(m, X, tmpE);
/* FIXME: This isn't right */ /* FIXME: This isn't right */
normalise_bands(m, X, X, tmpE); normalise_bands(m, X, X, tmpE);
} }
/* De-normalise the energy to produce the synthesis from the unit-energy bands */ /* 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, float *bank) void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bank)
{ {
int i, c, B, C; int i, c, B, C;
const int *eBands = m->eBands; const int *eBands = m->eBands;
@ -144,7 +144,7 @@ void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, floa
/* Compute the best gain for each "pitch band" */ /* Compute the best gain for each "pitch band" */
void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, float *bank) void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, celt_ener_t *bank)
{ {
int i, B; int i, B;
const int *eBands = m->eBands; const int *eBands = m->eBands;
@ -331,7 +331,7 @@ void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_
X[i] = 0; X[i] = 0;
} }
void stereo_mix(const CELTMode *m, celt_norm_t *X, float *bank, int dir) void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir)
{ {
int i, B, C; int i, B, C;
const int *eBands = m->eBands; const int *eBands = m->eBands;

View file

@ -43,7 +43,7 @@
* @param X Spectrum * @param X Spectrum
* @param bands Square root of the energy for each band (returned) * @param bands Square root of the energy for each band (returned)
*/ */
void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bands); void compute_band_energies(const CELTMode *m, celt_sig_t *X, celt_ener_t *bands);
/** Normalise each band of X such that the energy in each band is /** Normalise each band of X such that the energy in each band is
equal to 1 equal to 1
@ -51,7 +51,7 @@ void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bands);
* @param X Spectrum (returned normalised) * @param X Spectrum (returned normalised)
* @param bands Square root of the energy for each band * @param bands Square root of the energy for each band
*/ */
void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float *bands); void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bands);
void renormalise_bands(const CELTMode *m, celt_norm_t *X); void renormalise_bands(const CELTMode *m, celt_norm_t *X);
@ -60,7 +60,7 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X);
* @param X Spectrum (returned de-normalised) * @param X Spectrum (returned de-normalised)
* @param bands Square root of the energy for each band * @param bands Square root of the energy for each band
*/ */
void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, float *bands); void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, celt_ener_t *bands);
/** Compute the pitch predictor gain for each pitch band /** Compute the pitch predictor gain for each pitch band
* @param m Mode data * @param m Mode data
@ -69,7 +69,7 @@ void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, floa
* @param gains Gain computed for each pitch band (returned) * @param gains Gain computed for each pitch band (returned)
* @param bank Square root of the energy for each band * @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, float *gains, float *bank); void compute_pitch_gain(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains, celt_ener_t *bank);
void pitch_quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains); void pitch_quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *gains);
@ -92,6 +92,6 @@ void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, float *W, in
*/ */
void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec); 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, float *bank, int dir); void stereo_mix(const CELTMode *m, celt_norm_t *X, celt_ener_t *bank, int dir);
#endif /* BANDS_H */ #endif /* BANDS_H */

View file

@ -230,7 +230,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
VARDECL(celt_norm_t *X); VARDECL(celt_norm_t *X);
VARDECL(celt_norm_t *P); VARDECL(celt_norm_t *P);
VARDECL(float *mask); VARDECL(float *mask);
VARDECL(float *bandE); VARDECL(celt_ener_t *bandE);
VARDECL(float *gains); VARDECL(float *gains);
if (check_mode(st->mode) != CELT_OK) if (check_mode(st->mode) != CELT_OK)
@ -244,7 +244,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
ALLOC(X, B*C*N, celt_norm_t); /**< Interleaved normalised MDCTs */ ALLOC(X, B*C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
ALLOC(P, B*C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/ ALLOC(P, B*C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
ALLOC(mask, B*C*N, float); /**< Masking curve */ ALLOC(mask, B*C*N, float); /**< Masking curve */
ALLOC(bandE,st->mode->nbEBands*C, float); ALLOC(bandE,st->mode->nbEBands*C, celt_ener_t);
ALLOC(gains,st->mode->nbPBands, float); ALLOC(gains,st->mode->nbPBands, float);
N4 = (N-st->overlap)/2; N4 = (N-st->overlap)/2;
@ -322,8 +322,8 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
if (curr_power + 1e5f < 10.f*pitch_power) if (curr_power + 1e5f < 10.f*pitch_power)
{ {
/* Normalise the pitch vector as well (discard the energies) */ /* Normalise the pitch vector as well (discard the energies) */
VARDECL(float *bandEp); VARDECL(celt_ener_t *bandEp);
ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, float); ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, celt_ener_t);
compute_band_energies(st->mode, freq, bandEp); compute_band_energies(st->mode, freq, bandEp);
normalise_bands(st->mode, freq, P, bandEp); normalise_bands(st->mode, freq, P, bandEp);
@ -578,7 +578,7 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
VARDECL(celt_sig_t *freq); VARDECL(celt_sig_t *freq);
VARDECL(celt_norm_t *X); VARDECL(celt_norm_t *X);
VARDECL(celt_norm_t *P); VARDECL(celt_norm_t *P);
VARDECL(float *bandE); VARDECL(celt_ener_t *bandE);
VARDECL(float *gains); VARDECL(float *gains);
if (check_mode(st->mode) != CELT_OK) if (check_mode(st->mode) != CELT_OK)
@ -591,7 +591,7 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
ALLOC(freq, C*B*N, celt_sig_t); /**< Interleaved signal MDCTs */ ALLOC(freq, C*B*N, celt_sig_t); /**< Interleaved signal MDCTs */
ALLOC(X, C*B*N, celt_norm_t); /**< Interleaved normalised MDCTs */ ALLOC(X, C*B*N, celt_norm_t); /**< Interleaved normalised MDCTs */
ALLOC(P, C*B*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/ ALLOC(P, C*B*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
ALLOC(bandE, st->mode->nbEBands*C, float); ALLOC(bandE, st->mode->nbEBands*C, celt_ener_t);
ALLOC(gains, st->mode->nbPBands, float); ALLOC(gains, st->mode->nbPBands, float);
if (check_mode(st->mode) != CELT_OK) if (check_mode(st->mode) != CELT_OK)
@ -625,8 +625,8 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, freq, N, B, C); compute_mdcts(&st->mdct_lookup, st->window, st->out_mem+pitch_index*C, freq, N, B, C);
{ {
VARDECL(float *bandEp); VARDECL(celt_ener_t *bandEp);
ALLOC(bandEp, st->mode->nbEBands*C, float); ALLOC(bandEp, st->mode->nbEBands*C, celt_ener_t);
compute_band_energies(st->mode, freq, bandEp); compute_band_energies(st->mode, freq, bandEp);
normalise_bands(st->mode, freq, P, bandEp); normalise_bands(st->mode, freq, P, bandEp);
} }

View file

@ -44,7 +44,7 @@ const float eMeans[24] = {45.f, -8.f, -12.f, -2.5f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f
/*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/ /*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; const int frac[24] = {8, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc) static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc)
{ {
int i; int i;
int bits; int bits;
@ -114,7 +114,7 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
/*printf ("\n");*/ /*printf ("\n");*/
} }
static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec) static void unquant_energy_mono(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec)
{ {
int i; int i;
int bits; int bits;
@ -163,7 +163,7 @@ static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBan
void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc) void quant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc)
{ {
int C; int C;
@ -175,8 +175,8 @@ void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget
#if 1 #if 1
{ {
int c; int c;
VARDECL(float *E); VARDECL(celt_ener_t *E);
ALLOC(E, m->nbEBands, float); ALLOC(E, m->nbEBands, celt_ener_t);
for (c=0;c<C;c++) for (c=0;c<C;c++)
{ {
int i; int i;
@ -225,7 +225,7 @@ void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget
void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec) void unquant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec)
{ {
int C; int C;
C = m->nbChannels; C = m->nbChannels;
@ -234,8 +234,8 @@ void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budg
unquant_energy_mono(m, eBands, oldEBands, budget, dec); unquant_energy_mono(m, eBands, oldEBands, budget, dec);
else { else {
int c; int c;
VARDECL(float *E); VARDECL(celt_ener_t *E);
ALLOC(E, m->nbEBands, float); ALLOC(E, m->nbEBands, celt_ener_t);
for (c=0;c<C;c++) for (c=0;c<C;c++)
{ {
int i; int i;

View file

@ -32,12 +32,13 @@
#ifndef QUANT_BANDS #ifndef QUANT_BANDS
#define QUANT_BANDS #define QUANT_BANDS
#include "arch.h"
#include "modes.h" #include "modes.h"
#include "entenc.h" #include "entenc.h"
#include "entdec.h" #include "entdec.h"
void quant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_enc *enc); void quant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_enc *enc);
void unquant_energy(const CELTMode *m, float *eBands, float *oldEBands, int budget, ec_dec *dec); void unquant_energy(const CELTMode *m, celt_ener_t *eBands, float *oldEBands, int budget, ec_dec *dec);
#endif /* QUANT_BANDS */ #endif /* QUANT_BANDS */