Moves log2Amp inside denormalise_bands() and get rid of bandE[]

Also get rid of the MSE measurement code which is outdated and no longer useful
This commit is contained in:
Jean-Marc Valin 2013-06-16 20:24:52 -04:00
parent 3afc6ffff0
commit ee2506b2c7
6 changed files with 17 additions and 92 deletions

View file

@ -40,6 +40,7 @@
#include "os_support.h" #include "os_support.h"
#include "mathops.h" #include "mathops.h"
#include "rate.h" #include "rate.h"
#include "quant_bands.h"
int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev) int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev)
{ {
@ -188,7 +189,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel
/* 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, const celt_norm * OPUS_RESTRICT X, void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
celt_sig * OPUS_RESTRICT freq, const celt_ener *bandE, int start, int end, int C, int M) celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, int end, int C, int M)
{ {
int i, c, N; int i, c, N;
const opus_int16 *eBands = m->eBands; const opus_int16 *eBands = m->eBands;
@ -204,7 +205,12 @@ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
for (i=start;i<end;i++) for (i=start;i<end;i++)
{ {
int j, band_end; int j, band_end;
opus_val32 g = SHR32(bandE[i+c*m->nbEBands],1); celt_ener bandE;
opus_val32 g;
opus_val16 lg;
lg = ADD16(bandLogE[i+c*m->nbEBands], SHL16((opus_val16)eMeans[i],6));
bandE = PSHR32(celt_exp2(lg),4);
g = SHR32(bandE,1);
j=M*eBands[i]; j=M*eBands[i];
band_end = M*eBands[i+1]; band_end = M*eBands[i+1];
do { do {
@ -502,50 +508,6 @@ int spreading_decision(const CELTMode *m, celt_norm *X, int *average,
return decision; return decision;
} }
#ifdef MEASURE_NORM_MSE
float MSE[30] = {0};
int nbMSEBands = 0;
int MSECount[30] = {0};
void dump_norm_mse(void)
{
int i;
for (i=0;i<nbMSEBands;i++)
{
printf ("%g ", MSE[i]/MSECount[i]);
}
printf ("\n");
}
void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C)
{
static int init = 0;
int i;
if (!init)
{
atexit(dump_norm_mse);
init = 1;
}
for (i=0;i<m->nbEBands;i++)
{
int j;
int c;
float g;
if (bandE0[i]<10 || (C==2 && bandE0[i+m->nbEBands]<1))
continue;
c=0; do {
g = bandE[i+c*m->nbEBands]/(1e-15+bandE0[i+c*m->nbEBands]);
for (j=M*m->eBands[i];j<M*m->eBands[i+1];j++)
MSE[i] += (g*X[j+c*N]-X0[j+c*N])*(g*X[j+c*N]-X0[j+c*N]);
} while (++c<C);
MSECount[i]+=C;
}
nbMSEBands = m->nbEBands;
}
#endif
/* Indexing table for converting from natural Hadamard to ordery Hadamard /* Indexing table for converting from natural Hadamard to ordery Hadamard
This is essentially a bit-reversed Gray, on top of which we've added This is essentially a bit-reversed Gray, on top of which we've added
an inversion of the order because we want the DC at the end rather than an inversion of the order because we want the DC at the end rather than

View file

@ -59,7 +59,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel
* @param bandE Square root of the energy for each band * @param bandE Square root of the energy for each band
*/ */
void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
celt_sig * OPUS_RESTRICT freq, const celt_ener *bandE, int start, int end, int C, int M); celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start, int end, int C, int M);
#define SPREAD_NONE (0) #define SPREAD_NONE (0)
#define SPREAD_LIGHT (1) #define SPREAD_LIGHT (1)

View file

@ -375,8 +375,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
/* Noise-based PLC/CNG */ /* Noise-based PLC/CNG */
celt_sig *freq; celt_sig *freq;
VARDECL(celt_norm, X); VARDECL(celt_norm, X);
VARDECL(celt_ener, bandE);
opus_uint32 seed; opus_uint32 seed;
opus_val16 *plcLogE;
int end; int end;
int effEnd; int effEnd;
@ -387,10 +387,9 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
deemphasis scratch buffer. */ deemphasis scratch buffer. */
freq = scratch; freq = scratch;
ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
ALLOC(bandE, nbEBands*C, celt_ener);
if (loss_count >= 5) if (loss_count >= 5)
log2Amp(mode, start, end, bandE, backgroundLogE, C); plcLogE = backgroundLogE;
else { else {
/* Energy decay */ /* Energy decay */
opus_val16 decay = loss_count==0 ? opus_val16 decay = loss_count==0 ?
@ -400,7 +399,7 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
for (i=start;i<end;i++) for (i=start;i<end;i++)
oldBandE[c*nbEBands+i] -= decay; oldBandE[c*nbEBands+i] -= decay;
} while (++c<C); } while (++c<C);
log2Amp(mode, start, end, bandE, oldBandE, C); plcLogE = oldBandE;
} }
seed = st->rng; seed = st->rng;
for (c=0;c<C;c++) for (c=0;c<C;c++)
@ -422,7 +421,7 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
} }
st->rng = seed; st->rng = seed;
denormalise_bands(mode, X, freq, bandE, start, effEnd, C, 1<<LM); denormalise_bands(mode, X, freq, plcLogE, start, effEnd, C, 1<<LM);
c=0; do { c=0; do {
int bound = eBands[effEnd]<<LM; int bound = eBands[effEnd]<<LM;
@ -659,7 +658,6 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
ec_dec _dec; ec_dec _dec;
VARDECL(celt_sig, freq); VARDECL(celt_sig, freq);
VARDECL(celt_norm, X); VARDECL(celt_norm, X);
VARDECL(celt_ener, bandE);
VARDECL(int, fine_quant); VARDECL(int, fine_quant);
VARDECL(int, pulses); VARDECL(int, pulses);
VARDECL(int, cap); VARDECL(int, cap);
@ -913,9 +911,6 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
anti_collapse(mode, X, collapse_masks, LM, C, N, anti_collapse(mode, X, collapse_masks, LM, C, N,
st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
ALLOC(bandE, nbEBands*C, celt_ener);
log2Amp(mode, st->start, st->end, bandE, oldBandE, C);
ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */ ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */
if (silence) if (silence)
@ -926,7 +921,7 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
freq[i] = 0; freq[i] = 0;
} else { } else {
/* Synthesis */ /* Synthesis */
denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M); denormalise_bands(mode, X, freq, oldBandE, st->start, effEnd, C, M);
} }
c=0; do { c=0; do {
OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2); OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);

View file

@ -1849,17 +1849,6 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
quant_fine_energy(mode, st->start, st->end, oldBandE, error, fine_quant, enc, C); quant_fine_energy(mode, st->start, st->end, oldBandE, error, fine_quant, enc, C);
#ifdef MEASURE_NORM_MSE
float X0[3000];
float bandE0[60];
c=0; do
for (i=0;i<N;i++)
X0[i+c*N] = X[i+c*N];
while (++c<C);
for (i=0;i<C*nbEBands;i++)
bandE0[i] = bandE[i];
#endif
/* Residual quantisation */ /* Residual quantisation */
ALLOC(collapse_masks, C*nbEBands, unsigned char); ALLOC(collapse_masks, C*nbEBands, unsigned char);
quant_all_bands(1, mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks, quant_all_bands(1, mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
@ -1893,17 +1882,13 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng);
} }
log2Amp(mode, st->start, st->end, bandE, oldBandE, C);
if (silence) if (silence)
{ {
for (i=0;i<C*N;i++) for (i=0;i<C*N;i++)
freq[i] = 0; freq[i] = 0;
} else { } else {
#ifdef MEASURE_NORM_MSE
measure_norm_mse(mode, X, X0, bandE, bandE0, M, N, C);
#endif
/* Synthesis */ /* Synthesis */
denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M); denormalise_bands(mode, X, freq, oldBandE, st->start, effEnd, C, M);
} }
c=0; do { c=0; do {

View file

@ -536,25 +536,6 @@ void unquant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *
} }
} }
void log2Amp(const CELTMode *m, int start, int end,
celt_ener *eBands, const opus_val16 *oldEBands, int C)
{
int c, i;
c=0;
do {
for (i=0;i<start;i++)
eBands[i+c*m->nbEBands] = 0;
for (;i<end;i++)
{
opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands],
SHL16((opus_val16)eMeans[i],6));
eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4);
}
for (;i<m->nbEBands;i++)
eBands[i+c*m->nbEBands] = 0;
} while (++c < C);
}
void amp2Log2(const CELTMode *m, int effEnd, int end, void amp2Log2(const CELTMode *m, int effEnd, int end,
celt_ener *bandE, opus_val16 *bandLogE, int C) celt_ener *bandE, opus_val16 *bandLogE, int C)
{ {

View file

@ -41,6 +41,8 @@
#include "entdec.c" #include "entdec.c"
#include "entcode.c" #include "entcode.c"
#include "bands.c" #include "bands.c"
#include "quant_bands.c"
#include "laplace.c"
#include "vq.c" #include "vq.c"
#include "cwrs.c" #include "cwrs.c"
#include <stdio.h> #include <stdio.h>