ref: d5e5436e075312bd3f281fc6556c4e1767c22ced
parent: 7013db7ca4678e4745a68460f5a7bd71902c8b23
author: Jean-Marc Valin <[email protected]>
date: Wed Sep 30 16:50:41 EDT 2009
Fix for folding_decision() in stereo mode and more cleaning up of the code now that we no longer do normalized pitch
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -377,10 +377,13 @@
int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int *last_decision)
{
- int i;
+ int i, c;
int NR=0;
celt_word32_t ratio = EPSILON;
+ const int C = CHANNELS(m);
const celt_int16_t * restrict eBands = m->eBands;
+ for (c=0;c<C;c++)
+ {
for (i=0;i<m->nbEBands;i++)
{
int j, N;
@@ -387,13 +390,13 @@
int max_i=0;
celt_word16_t max_val=EPSILON;
celt_word32_t floor_ener=EPSILON;
- celt_norm_t * restrict x = X+eBands[i];
+ celt_norm_t * restrict x = X+C*eBands[i]+c;
N = eBands[i+1]-eBands[i];
for (j=0;j<N;j++)
{
- if (ABS16(x[j])>max_val)
+ if (ABS16(x[C*j])>max_val)
{
- max_val = ABS16(x[j]);
+ max_val = ABS16(x[C*j]);
max_i = j;
}
}
@@ -406,13 +409,13 @@
#else
floor_ener = QCONST32(1.,28)-MULT16_16(max_val,max_val);
if (max_i < N-1)
- floor_ener -= MULT16_16(x[max_i+1], x[max_i+1]);
+ floor_ener -= MULT16_16(x[C*(max_i+1)], x[C*(max_i+1)]);
if (max_i < N-2)
- floor_ener -= MULT16_16(x[max_i+2], x[max_i+2]);
+ floor_ener -= MULT16_16(x[C*(max_i+2)], x[C*(max_i+2)]);
if (max_i > 0)
- floor_ener -= MULT16_16(x[max_i-1], x[max_i-1]);
+ floor_ener -= MULT16_16(x[C*(max_i-1)], x[C*(max_i-1)]);
if (max_i > 1)
- floor_ener -= MULT16_16(x[max_i-2], x[max_i-2]);
+ floor_ener -= MULT16_16(x[C*(max_i-2)], x[C*(max_i-2)]);
floor_ener = MAX32(floor_ener, EPSILON);
#endif
if (N>7)
@@ -425,6 +428,7 @@
NR++;
}
}
+ }
if (NR>0)
ratio = DIV32_16(ratio, NR);
ratio = ADD32(HALF32(ratio), HALF32(*average));
@@ -439,7 +443,7 @@
}
/* Quantisation of the residual */
-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)
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, 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;
@@ -493,7 +497,7 @@
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);
+ intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
}
for (j=eBands[i];j<eBands[i+1];j++)
norm[j] = MULT16_16_Q15(n,X[j]);
@@ -503,7 +507,7 @@
#ifndef DISABLE_STEREO
-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)
+void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, 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;
@@ -515,7 +519,7 @@
SAVE_STACK;
B = shortBlocks ? m->nbShortMdcts : 1;
- ALLOC(_norm, C*eBands[m->nbEBands+1], celt_norm_t);
+ ALLOC(_norm, eBands[m->nbEBands+1], celt_norm_t);
norm = _norm;
balance = 0;
@@ -680,19 +684,13 @@
remaining_bits -= curr_bits;
}
- /* If pitch isn't available, use intra-frame prediction */
- if (q1==0)
- {
- intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B);
- deinterleave(P+C*eBands[i], C*N);
- }
deinterleave(X+C*eBands[i], C*N);
if (q1 > 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];
+ } else {
+ intra_fold(m, eBands[i+1]-eBands[i], norm, X+C*eBands[i], eBands[i], B);
+ }
if (q2 > 0) {
int spread = fold ? B : 0;
alg_quant(X+C*eBands[i]+N, N, q2, spread, enc);
@@ -710,9 +708,8 @@
mid = (1./32768)*imid;
side = (1./32768)*iside;
#endif
- for (c=0;c<C;c++)
- for (j=0;j<N;j++)
- norm[C*(eBands[i]+j)+c] = MULT16_16_Q15(n,X[C*eBands[i]+c*N+j]);
+ for (j=0;j<N;j++)
+ norm[eBands[i]+j] = MULT16_16_Q15(n,X[C*eBands[i]+j]);
for (j=0;j<N;j++)
X[C*eBands[i]+j] = MULT16_16_Q15(X[C*eBands[i]+j], mid);
@@ -731,7 +728,7 @@
#endif /* DISABLE_STEREO */
/* Decoding of the residual */
-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)
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, 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;
@@ -785,7 +782,7 @@
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);
+ intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
}
for (j=eBands[i];j<eBands[i+1];j++)
norm[j] = MULT16_16_Q15(n,X[j]);
@@ -795,7 +792,7 @@
#ifndef DISABLE_STEREO
-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)
+void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, 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;
@@ -807,7 +804,7 @@
SAVE_STACK;
B = shortBlocks ? m->nbShortMdcts : 1;
- ALLOC(_norm, C*eBands[m->nbEBands+1], celt_norm_t);
+ ALLOC(_norm, eBands[m->nbEBands+1], celt_norm_t);
norm = _norm;
balance = 0;
@@ -953,15 +950,7 @@
}
remaining_bits -= curr_bits;
}
-
-
- /* If pitch isn't available, use intra-frame prediction */
- if (q1==0)
- {
- intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B);
- deinterleave(P+C*eBands[i], C*N);
- }
deinterleave(X+C*eBands[i], C*N);
if (q1 > 0)
{
@@ -968,8 +957,7 @@
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++)
- X[j] = P[j];
+ intra_fold(m, eBands[i+1]-eBands[i], norm, X+C*eBands[i], eBands[i], B);
if (q2 > 0)
{
int spread = fold ? B : 0;
@@ -988,9 +976,8 @@
mid = (1./32768)*imid;
side = (1./32768)*iside;
#endif
- for (c=0;c<C;c++)
- for (j=0;j<N;j++)
- norm[C*(eBands[i]+j)+c] = MULT16_16_Q15(n,X[C*eBands[i]+c*N+j]);
+ for (j=0;j<N;j++)
+ norm[eBands[i]+j] = MULT16_16_Q15(n,X[C*eBands[i]+j]);
for (j=0;j<N;j++)
X[C*eBands[i]+j] = MULT16_16_Q15(X[C*eBands[i]+j], mid);
--- 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, 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, 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);
+void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, 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, 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, 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 unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, 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
@@ -506,7 +506,6 @@
VARDECL(celt_sig_t, freq);
VARDECL(celt_sig_t, pitch_freq);
VARDECL(celt_norm_t, X);
- VARDECL(celt_norm_t, P);
VARDECL(celt_ener_t, bandE);
VARDECL(celt_word16_t, bandLogE);
VARDECL(int, fine_quant);
@@ -674,7 +673,6 @@
/* Deferred allocation after find_spectral_pitch() to reduce
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(pitch_freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
if (has_pitch)
@@ -709,9 +707,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<C*N;i++)
- P[i] = 0;
}
if (shortBlocks)
{
@@ -769,10 +764,10 @@
/* Residual quantisation */
if (C==1)
- quant_bands(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
#ifndef DISABLE_STEREO
else
- quant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands_stereo(st->mode, X, 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);
@@ -1205,7 +1200,6 @@
VARDECL(celt_sig_t, freq);
VARDECL(celt_sig_t, pitch_freq);
VARDECL(celt_norm_t, X);
- VARDECL(celt_norm_t, P);
VARDECL(celt_ener_t, bandE);
VARDECL(int, fine_quant);
VARDECL(int, pulses);
@@ -1236,7 +1230,6 @@
ALLOC(freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */
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);
if (data == NULL)
@@ -1309,10 +1302,10 @@
/* Decode fixed codebook and merge with pitch */
if (C==1)
- unquant_bands(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
+ unquant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
#ifndef DISABLE_STEREO
else
- unquant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
+ unquant_bands_stereo(st->mode, X, 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/modes.c
+++ b/libcelt/modes.c
@@ -124,8 +124,8 @@
celt_int16_t *eBands;
int i, res, min_width, lin, low, high, nBark;
- //if (min_bins < nbShortMdcts)
- // min_bins = nbShortMdcts;
+ /*if (min_bins < nbShortMdcts)
+ min_bins = nbShortMdcts;*/
res = (Fs+frame_size)/(2*frame_size);
min_width = min_bins*res;
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -40,6 +40,10 @@
#include "os_support.h"
#include "rate.h"
+#ifndef M_PI
+#define M_PI 3.141592653
+#endif
+
static void exp_rotation(celt_norm_t *X, int len, int dir, int stride, int K)
{
int i, k, iter;
@@ -339,11 +343,10 @@
return rE;
}
-static void fold(const CELTMode *m, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B)
+static void fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B)
{
int j;
- const int C = CHANNELS(m);
- int id = (N0*C) % (C*B);
+ int id = N0 % B;
/* Here, we assume that id will never be greater than N0, i.e. that
no band is wider than N0. In the unlikely case it happens, we set
everything to zero */
@@ -357,23 +360,17 @@
//printf ("%d\n", offset);
id += offset;
}*/
- if (id+C*N>N0*C)
- for (j=0;j<C*N;j++)
+ if (id+N>N0)
+ for (j=0;j<N;j++)
P[j] = 0;
else
- for (j=0;j<C*N;j++)
+ for (j=0;j<N;j++)
P[j] = Y[id++];
}
-void intra_fold(const CELTMode *m, celt_norm_t * restrict x, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B)
+void intra_fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B)
{
- int c;
- const int C = CHANNELS(m);
-
fold(m, N, Y, P, N0, B);
- c=0;
- do {
- renormalise_vector(P+c, Q15ONE, N, C);
- } while (++c < C);
+ renormalise_vector(P, Q15ONE, N, 1);
}
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -74,6 +74,6 @@
* @param B Stride (number of channels multiplied by the number of MDCTs per frame)
* @param N0 Number of valid offsets
*/
-void intra_fold(const CELTMode *m, celt_norm_t * restrict x, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B);
+void intra_fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B);
#endif /* VQ_H */