ref: 69921c4cde12bc06dbe34eae168600707288829d
parent: 0be05b0335818d5dd7251fce0ae08fdbc76d4abb
author: Jean-Marc Valin <[email protected]>
date: Fri Jul 16 11:25:30 EDT 2010
Considering the end band in more places in the code
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -48,15 +48,15 @@
#ifdef FIXED_POINT
/* Compute the amplitude (sqrt energy) in each of the bands */
-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C, int M)
+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int end, int _C, int M)
{
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
for (c=0;c<C;c++)
{
- for (i=0;i<m->nbEBands;i++)
+ for (i=0;i<end;i++)
{
int j;
celt_word32 maxval=0;
@@ -87,12 +87,12 @@
}
/* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C, int M)
+void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int end, int _C, int M)
{
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
for (c=0;c<C;c++)
{
i=0; do {
@@ -105,21 +105,21 @@
j=M*eBands[i]; do {
X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g);
} while (++j<M*eBands[i+1]);
- } while (++i<m->nbEBands);
+ } while (++i<end);
}
}
#else /* FIXED_POINT */
/* Compute the amplitude (sqrt energy) in each of the bands */
-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int _C, int M)
+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bank, int end, int _C, int M)
{
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
for (c=0;c<C;c++)
{
- for (i=0;i<m->nbEBands;i++)
+ for (i=0;i<end;i++)
{
int j;
celt_word32 sum = 1e-10;
@@ -133,15 +133,15 @@
}
/* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int _C, int M)
+void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bank, int end, int _C, int M)
{
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
for (c=0;c<C;c++)
{
- for (i=0;i<m->nbEBands;i++)
+ for (i=0;i<end;i++)
{
int j;
celt_word16 g = 1.f/(1e-10f+bank[i+c*m->nbEBands]);
@@ -153,7 +153,7 @@
#endif /* FIXED_POINT */
-void renormalise_bands(const CELTMode *m, celt_norm * restrict X, int _C, int M)
+void renormalise_bands(const CELTMode *m, celt_norm * restrict X, int end, int _C, int M)
{
int i, c;
const celt_int16 *eBands = m->eBands;
@@ -161,18 +161,18 @@
for (c=0;c<C;c++)
{
i=0; do {
- renormalise_vector(X+M*eBands[i]+c*M*eBands[m->nbEBands+1], Q15ONE, M*eBands[i+1]-M*eBands[i], 1);
- } while (++i<m->nbEBands);
+ renormalise_vector(X+M*eBands[i]+c*M*m->shortMdctSize, Q15ONE, M*eBands[i+1]-M*eBands[i], 1);
+ } while (++i<end);
}
}
/* De-normalise the energy to produce the synthesis from the unit-energy bands */
-void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bank, int _C, int M)
+void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bank, int end, int _C, int M)
{
int i, c, N;
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
if (C>2)
celt_fatal("denormalise_bands() not implemented for >2 channels");
for (c=0;c<C;c++)
@@ -181,18 +181,18 @@
const celt_norm * restrict x;
f = freq+c*N;
x = X+c*N;
- for (i=0;i<m->nbEBands;i++)
+ for (i=0;i<end;i++)
{
- int j, end;
+ int j, band_end;
celt_word32 g = SHR32(bank[i+c*m->nbEBands],1);
j=M*eBands[i];
- end = M*eBands[i+1];
+ band_end = M*eBands[i+1];
do {
*f++ = SHL32(MULT16_32_Q15(*x, g),2);
x++;
- } while (++j<end);
+ } while (++j<band_end);
}
- for (i=M*eBands[m->nbEBands];i<M*eBands[m->nbEBands+1];i++)
+ for (i=M*eBands[m->nbEBands];i<N;i++)
*f++ = 0;
}
}
@@ -205,7 +205,7 @@
const int C = CHANNELS(_C);
celt_word32 Sxy=0, Sxx=0, Syy=0;
int len = M*m->pitchEnd;
- int N = M*m->eBands[m->nbEBands+1];
+ int N = M*m->shortMdctSize;
#ifdef FIXED_POINT
int shift = 0;
celt_word32 maxabs=0;
@@ -298,7 +298,7 @@
const int C = CHANNELS(_C);
int len = M*m->pitchEnd;
- N = M*m->eBands[m->nbEBands+1];
+ N = M*m->shortMdctSize;
gain = ADD16(QCONST16(.5f,14), MULT16_16_16(QCONST16(.05f,14),gain_id));
delta = PDIV32_16(gain, len);
if (pred)
@@ -349,7 +349,7 @@
}
-int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int _C, int M)
+int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int end, int _C, int M)
{
int i, c, N0;
int NR=0;
@@ -357,11 +357,11 @@
const int C = CHANNELS(_C);
const celt_int16 * restrict eBands = m->eBands;
- N0 = M*m->eBands[m->nbEBands+1];
+ N0 = M*m->shortMdctSize;
for (c=0;c<C;c++)
{
- for (i=0;i<m->nbEBands;i++)
+ for (i=0;i<end;i++)
{
int j, N;
int max_i=0;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -45,7 +45,7 @@
* @param X Spectrum
* @param bands Square root of the energy for each band (returned)
*/
-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bands, int _C, int M);
+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bands, int end, int _C, int M);
/*void compute_noise_energies(const CELTMode *m, const celt_sig *X, const celt_word16 *tonality, celt_ener *bank);*/
@@ -55,9 +55,9 @@
* @param X Spectrum (returned normalised)
* @param bands Square root of the energy for each band
*/
-void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bands, int _C, int M);
+void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_norm * restrict X, const celt_ener *bands, int end, int _C, int M);
-void renormalise_bands(const CELTMode *m, celt_norm * restrict X, int _C, int M);
+void renormalise_bands(const CELTMode *m, celt_norm * restrict X, int end, int _C, int M);
/** Denormalise each band of X to restore full amplitude
* @param m Mode data
@@ -64,7 +64,7 @@
* @param X Spectrum (returned de-normalised)
* @param bands Square root of the energy for each band
*/
-void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bands, int _C, int M);
+void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bands, int end, int _C, int M);
/** Compute the pitch predictor gain for each pitch band
* @param m Mode data
@@ -77,7 +77,7 @@
void apply_pitch(const CELTMode *m, celt_sig *X, const celt_sig *P, int gain_id, int pred, int _C, int M);
-int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int _C, int M);
+int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int end, int _C, int M);
/** Quantisation/encoding of the residual spectrum
* @param m Mode data
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -519,7 +519,7 @@
static void mdct_shape(const CELTMode *mode, celt_norm *X, int start,
int end, int N,
- int mdct_weight_shift, int _C, int renorm, int M)
+ int mdct_weight_shift, int end_band, int _C, int renorm, int M)
{
int m, i, c;
const int C = CHANNELS(_C);
@@ -532,7 +532,7 @@
X[i] = (1.f/(1<<mdct_weight_shift))*X[i];
#endif
if (renorm)
- renormalise_bands(mode, X, C, M);
+ renormalise_bands(mode, X, end_band, C, M);
}
static signed char tf_select_table[4][8] = {
@@ -856,23 +856,23 @@
if (has_pitch)
apply_pitch(st->mode, freq, pitch_freq, gain_id, 1, C, M);
- compute_band_energies(st->mode, freq, bandE, C, M);
- for (i=0;i<st->mode->nbEBands*C;i++)
+ compute_band_energies(st->mode, freq, bandE, st->end, C, M);
+ for (i=0;i<st->end*C;i++)
bandLogE[i] = amp2Log(bandE[i]);
/* Band normalisation */
- normalise_bands(st->mode, freq, X, bandE, C, M);
- if (!shortBlocks && !folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, C, M))
+ normalise_bands(st->mode, freq, X, bandE, st->end, C, M);
+ if (!shortBlocks && !folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, st->end, C, M))
has_fold = 0;
/* Don't use intra energy when we're operating at low bit-rate */
- intra_ener = st->force_intra || (!has_pitch && st->delayedIntra && nbAvailableBytes > st->mode->nbEBands);
- if (shortBlocks || intra_decision(bandLogE, st->oldBandE, st->mode->nbEBands))
+ intra_ener = st->force_intra || (!has_pitch && st->delayedIntra && nbAvailableBytes > st->end);
+ if (shortBlocks || intra_decision(bandLogE, st->oldBandE, st->end))
st->delayedIntra = 1;
else
st->delayedIntra = 0;
- NN = M*st->mode->eBands[st->mode->nbEBands];
+ NN = M*st->mode->eBands[st->end];
if (shortBlocks && !transient_shift)
{
celt_word32 sum[8]={1,1,1,1,1,1,1,1};
@@ -916,7 +916,7 @@
} while (m<M-1);
#endif
if (mdct_weight_shift)
- mdct_shape(st->mode, X, mdct_weight_pos+1, M, N, mdct_weight_shift, C, 0, M);
+ mdct_shape(st->mode, X, mdct_weight_pos+1, M, N, mdct_weight_shift, st->end, C, 0, M);
}
@@ -958,7 +958,7 @@
}
ALLOC(tf_res, st->mode->nbEBands, int);
- tf_select = tf_analysis(bandLogE, st->oldBandE, st->mode->nbEBands, C, isTransient, tf_res, nbAvailableBytes);
+ tf_select = tf_analysis(bandLogE, st->oldBandE, st->end, C, isTransient, tf_res, nbAvailableBytes);
/* Bit allocation */
ALLOC(error, C*st->mode->nbEBands, celt_word16);
@@ -1057,11 +1057,11 @@
if (mdct_weight_shift)
{
- mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, mdct_weight_shift, C, 1, M);
+ mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, mdct_weight_shift, st->end, C, 1, M);
}
/* Synthesis */
- denormalise_bands(st->mode, X, freq, bandE, C, M);
+ denormalise_bands(st->mode, X, freq, bandE, st->end, C, M);
CELT_MOVE(st->out_mem, st->out_mem+C*N, C*(MAX_PERIOD+st->overlap-N));
@@ -1804,11 +1804,11 @@
if (mdct_weight_shift)
{
- mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, mdct_weight_shift, C, 1, M);
+ mdct_shape(st->mode, X, 0, mdct_weight_pos+1, N, mdct_weight_shift, st->end, C, 1, M);
}
/* Synthesis */
- denormalise_bands(st->mode, X, freq, bandE, C, M);
+ denormalise_bands(st->mode, X, freq, bandE, st->end, C, M);
CELT_MOVE(st->decode_mem, st->decode_mem+C*N, C*(DECODE_BUFFER_SIZE+st->overlap-N));
--- a/libcelt/pitch.c
+++ b/libcelt/pitch.c
@@ -152,7 +152,7 @@
{
int i, j;
const int lag = MAX_PERIOD;
- const int N = M*m->eBands[m->nbEBands+1];
+ const int N = M*m->shortMdctSize;
int best_pitch[2]={0};
VARDECL(celt_word16, x_lp4);
VARDECL(celt_word16, y_lp4);
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -128,6 +128,7 @@
in = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
out = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16));
+
while (!feof(fin))
{
err = fread(in, sizeof(short), frame_size*channels, fin);