ref: 4834c92e2b9ee315d55f001fd63df2cc6caa1cea
parent: 095c1782c5925b5b37c433b18e438b833fe3f9e7
author: Jean-Marc Valin <[email protected]>
date: Mon Sep 28 15:17:34 EDT 2009
More simplifications from denorm pitch
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -222,7 +222,7 @@
celt_word16_t g;
const int C = CHANNELS(m);
celt_word32_t Sxy=0, Sxx=0, Syy=0;
- int len = 20*C;
+ int len = m->pitchEnd*C;
#ifdef FIXED_POINT
int shift = 0;
celt_word32_t maxabs=0;
@@ -291,7 +291,7 @@
int j;
celt_word16_t gain;
const int C = CHANNELS(m);
- int len = 20*C;
+ int len = m->pitchEnd*C;
gain = ADD16(QCONST16(.5,14), MULT16_16_16(QCONST16(.05,14),gain_id));
if (pred)
gain = -gain;
@@ -415,7 +415,7 @@
floor_ener -= MULT16_16(x[max_i-2], x[max_i-2]);
floor_ener = MAX32(floor_ener, EPSILON);
#endif
- if (N>7 && eBands[i] >= m->pitchEnd)
+ if (N>7)
{
celt_word16_t r;
celt_word16_t den = celt_sqrt(floor_ener);
@@ -439,7 +439,7 @@
}
/* Quantisation of the residual */
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
{
int i, j, remaining_bits, balance;
const celt_int16_t * restrict eBands = m->eBands;
@@ -490,7 +490,7 @@
if (q > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc);
} else {
intra_fold(m, X+eBands[i], eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
@@ -503,7 +503,7 @@
#ifndef DISABLE_STEREO
-void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
+void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
{
int i, j, remaining_bits, balance;
const celt_int16_t * restrict eBands = m->eBands;
@@ -510,7 +510,6 @@
celt_norm_t * restrict norm;
VARDECL(celt_norm_t, _norm);
const int C = CHANNELS(m);
- int pband=-1;
int B;
celt_word16_t mid, side;
SAVE_STACK;
@@ -625,7 +624,7 @@
if (q1 > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_quant(v, N, q1, spread, enc);
} else {
v[0] = QCONST16(1.f, 14);
@@ -689,13 +688,13 @@
}
deinterleave(X+C*eBands[i], C*N);
if (q1 > 0) {
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_quant(X+C*eBands[i], N, q1, spread, enc);
} else
for (j=C*eBands[i];j<C*eBands[i]+N;j++)
X[j] = P[j];
if (q2 > 0) {
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_quant(X+C*eBands[i]+N, N, q2, spread, enc);
} else
for (j=C*eBands[i]+N;j<C*eBands[i+1];j++)
@@ -732,7 +731,7 @@
#endif /* DISABLE_STEREO */
/* Decoding of the residual */
-void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
{
int i, j, remaining_bits, balance;
const celt_int16_t * restrict eBands = m->eBands;
@@ -783,7 +782,7 @@
if (q > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, dec);
} else {
intra_fold(m, X+eBands[i], eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
@@ -796,7 +795,7 @@
#ifndef DISABLE_STEREO
-void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
+void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_dec *dec)
{
int i, j, remaining_bits, balance;
const celt_int16_t * restrict eBands = m->eBands;
@@ -803,7 +802,6 @@
celt_norm_t * restrict norm;
VARDECL(celt_norm_t, _norm);
const int C = CHANNELS(m);
- int pband=-1;
int B;
celt_word16_t mid, side;
SAVE_STACK;
@@ -907,7 +905,7 @@
if (q1 > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_unquant(v, N, q1, spread, dec);
} else {
v[0] = QCONST16(1.f, 14);
@@ -967,7 +965,7 @@
deinterleave(X+C*eBands[i], C*N);
if (q1 > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_unquant(X+C*eBands[i], N, q1, spread, dec);
} else
for (j=C*eBands[i];j<C*eBands[i]+N;j++)
@@ -974,7 +972,7 @@
X[j] = P[j];
if (q2 > 0)
{
- int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0;
+ int spread = fold ? B : 0;
alg_unquant(X+C*eBands[i]+N, N, q2, spread, dec);
} else
for (j=C*eBands[i]+N;j<C*eBands[i+1];j++)
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -87,9 +87,9 @@
* @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
* @param enc Entropy encoder
*/
-void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
-void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
+void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
/** Decoding of the residual spectrum
* @param m Mode data
@@ -98,9 +98,9 @@
* @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
* @param dec Entropy decoder
*/
-void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
-void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int pitch_used, celt_pgain_t *pgains, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
+void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_dec *dec);
void stereo_decision(const CELTMode *m, celt_norm_t * restrict X, int *stereo_mode, int len);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -509,7 +509,6 @@
VARDECL(celt_norm_t, P);
VARDECL(celt_ener_t, bandE);
VARDECL(celt_word16_t, bandLogE);
- VARDECL(celt_pgain_t, gains);
VARDECL(int, fine_quant);
VARDECL(celt_word16_t, error);
VARDECL(int, pulses);
@@ -676,7 +675,6 @@
the peak memory usage */
ALLOC(X, C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
ALLOC(P, C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
- ALLOC(gains,st->mode->nbPBands, celt_pgain_t);
ALLOC(pitch_freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
if (has_pitch)
@@ -712,8 +710,6 @@
ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4));
ec_enc_uint(&enc, gain_id, 16);
} else {
- for (i=0;i<st->mode->nbPBands;i++)
- gains[i] = 0;
for (i=0;i<C*N;i++)
P[i] = 0;
}
@@ -773,10 +769,10 @@
/* Residual quantisation */
if (C==1)
- quant_bands(st->mode, X, P, NULL, 0, gains, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
#ifndef DISABLE_STEREO
else
- quant_bands_stereo(st->mode, X, P, NULL, 0, gains, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
#endif
quant_energy_finalise(st->mode, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(&enc, 0), &enc);
@@ -1211,7 +1207,6 @@
VARDECL(celt_norm_t, X);
VARDECL(celt_norm_t, P);
VARDECL(celt_ener_t, bandE);
- VARDECL(celt_pgain_t, gains);
VARDECL(int, fine_quant);
VARDECL(int, pulses);
VARDECL(int, offsets);
@@ -1243,7 +1238,6 @@
ALLOC(X, C*N, celt_norm_t); /**< Interleaved normalised MDCTs */
ALLOC(P, C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/
ALLOC(bandE, st->mode->nbEBands*C, celt_ener_t);
- ALLOC(gains, st->mode->nbPBands, celt_pgain_t);
if (data == NULL)
{
@@ -1286,8 +1280,6 @@
gain_id = ec_dec_uint(&dec, 16);
} else {
pitch_index = 0;
- for (i=0;i<st->mode->nbPBands;i++)
- gains[i] = 0;
}
ALLOC(fine_quant, st->mode->nbEBands, int);
@@ -1317,10 +1309,10 @@
/* Decode fixed codebook and merge with pitch */
if (C==1)
- unquant_bands(st->mode, X, P, 0, gains, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
+ unquant_bands(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
#ifndef DISABLE_STEREO
else
- unquant_bands_stereo(st->mode, X, P, 0, gains, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
+ unquant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
#endif
unquant_energy_finalise(st->mode, bandE, st->oldBandE, fine_quant, fine_priority, len*8-ec_dec_tell(&dec, 0), &dec);
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -73,16 +73,6 @@
fprintf(file, "\n");
- fprintf(file, "#ifndef DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
- fprintf(file, "#define DEF_PBANDS%d_%d\n", mode->Fs, mode->mdctSize);
- fprintf (file, "static const celt_int16_t pBands%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbPBands+2);
- for (j=0;j<mode->nbPBands+2;j++)
- fprintf (file, "%d, ", mode->pBands[j]);
- fprintf (file, "};\n");
- fprintf(file, "#endif\n");
- fprintf(file, "\n");
-
-
fprintf(file, "#ifndef DEF_WINDOW%d\n", mode->overlap);
fprintf(file, "#define DEF_WINDOW%d\n", mode->overlap);
fprintf (file, "static const celt_word16_t window%d[%d] = {\n", mode->overlap, mode->overlap);
@@ -148,10 +138,8 @@
fprintf(file, "%d,\t/* mdctSize */\n", mode->mdctSize);
fprintf(file, "%d,\t/* nbChannels */\n", mode->nbChannels);
fprintf(file, "%d,\t/* nbEBands */\n", mode->nbEBands);
- fprintf(file, "%d,\t/* nbPBands */\n", mode->nbPBands);
fprintf(file, "%d,\t/* pitchEnd */\n", mode->pitchEnd);
fprintf(file, "eBands%d_%d,\t/* eBands */\n", mode->Fs, mode->mdctSize);
- fprintf(file, "pBands%d_%d,\t/* pBands */\n", mode->Fs, mode->mdctSize);
fprintf(file, WORD16 ",\t/* ePredCoef */\n", mode->ePredCoef);
fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors);
fprintf(file, "allocVectors%d_%d_%d,\t/* allocVectors */\n", mode->Fs, mode->mdctSize, mode->nbChannels);
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -82,8 +82,6 @@
#ifndef STATIC_MODES
-#define PBANDS 8
-
/* Defining 25 critical bands for the full 0-20 kHz audio bandwidth
Taken from http://ccrma.stanford.edu/~jos/bbt/Bark_Frequency_Scale.html */
#define BARK_BANDS 25
@@ -95,8 +93,6 @@
6400, 7700, 9500, 12000, 15500,
20000};
-static const celt_int16_t pitch_freq[PBANDS+1] ={0, 345, 689, 1034, 1378, 2067, 3273, 5340, 6374};
-
/* This allocation table is per critical band. When creating a mode, the bits get added together
into the codec bands, which are sometimes larger than one critical band at low frequency */
@@ -179,40 +175,6 @@
return eBands;
}
-static void compute_pbands(CELTMode *mode, int res)
-{
- int i;
- celt_int16_t *pBands;
- pBands=celt_alloc(sizeof(celt_int16_t)*(PBANDS+2));
- mode->pBands = pBands;
- if (pBands==NULL)
- return;
- mode->nbPBands = PBANDS;
- for (i=0;i<PBANDS+1;i++)
- {
- pBands[i] = (pitch_freq[i]+res/2)/res;
- if (pBands[i] < mode->eBands[i])
- pBands[i] = mode->eBands[i];
- }
- pBands[PBANDS+1] = mode->eBands[mode->nbEBands+1];
- for (i=1;i<mode->nbPBands+1;i++)
- {
- int j;
- for (j=0;j<mode->nbEBands;j++)
- if (mode->eBands[j] <= pBands[i] && mode->eBands[j+1] > pBands[i])
- break;
- if (mode->eBands[j] != pBands[i])
- {
- if (pBands[i]-mode->eBands[j] < mode->eBands[j+1]-pBands[i] &&
- mode->eBands[j] != pBands[i-1])
- pBands[i] = mode->eBands[j];
- else
- pBands[i] = mode->eBands[j+1];
- }
- }
- mode->pitchEnd = pBands[PBANDS];
-}
-
static void compute_allocation_table(CELTMode *mode, int res)
{
int i, j, nBark;
@@ -382,10 +344,9 @@
mode->eBands = compute_ebands(Fs, frame_size, mode->nbShortMdcts, &mode->nbEBands);
if (mode->eBands==NULL)
goto failure;
- compute_pbands(mode, res);
- if (mode->pBands==NULL)
- goto failure;
+ mode->pitchEnd = 3000*(celt_int32_t)frame_size/Fs;
+
/* Overlap must be divisible by 4 */
if (mode->nbShortMdcts > 1)
mode->overlap = ((frame_size/mode->nbShortMdcts)>>2)<<2;
@@ -494,7 +455,6 @@
}
celt_free((int**)mode->bits);
celt_free((int*)mode->eBands);
- celt_free((int*)mode->pBands);
celt_free((int*)mode->allocVectors);
celt_free((celt_word16_t*)mode->window);
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -76,11 +76,9 @@
int nbChannels;
int nbEBands;
- int nbPBands;
int pitchEnd;
const celt_int16_t *eBands; /**< Definition for each "pseudo-critical band" */
- const celt_int16_t *pBands; /**< Definition of the bands used for the pitch */
celt_word16_t ePredCoef;/**< Prediction coefficient for the energy encoding */