ref: 6361ad8d415a637ac3581390423519bb9f6d254d
parent: df38f2bf013670903fa273153c1beabb5d27a6f9
author: Jean-Marc Valin <[email protected]>
date: Sun Jul 20 19:14:31 EDT 2008
Simplified the folding normalisation by creating renormalise_vector().
--- a/configure.ac
+++ b/configure.ac
@@ -5,8 +5,8 @@
AM_CONFIG_HEADER([config.h])
CELT_MAJOR_VERSION=0
-CELT_MINOR_VERSION=3
-CELT_MICRO_VERSION=2
+CELT_MINOR_VERSION=4
+CELT_MICRO_VERSION=0
CELT_EXTRA_VERSION=
CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -565,8 +565,8 @@
}
}
#endif
- if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 7)
- celt_warning_int ("many unused bits: ", nbCompressedBytes*8-ec_enc_tell(&st->enc, 0));
+ /*if (ec_enc_tell(&st->enc, 0) < nbCompressedBytes*8 - 7)
+ celt_warning_int ("many unused bits: ", nbCompressedBytes*8-ec_enc_tell(&st->enc, 0));*/
/*printf ("%d\n", ec_enc_tell(&st->enc, 0)-8*nbCompressedBytes);*/
/* Finishing the stream with a 0101... pattern so that the decoder can check is everything's right */
{
--- a/libcelt/match-test.sh
+++ b/libcelt/match-test.sh
@@ -9,7 +9,7 @@
if [ -f mono_test_file.sw ]; then
echo -n "mono test... "
- ./testcelt 44100 1 256 128 32 mono_test_file.sw $outfile
+ ./testcelt 44100 1 256 32 mono_test_file.sw $outfile
if [ $? != 0 ]; then
exit 1
fi
@@ -19,7 +19,7 @@
if [ -f stereo_test_file.sw ]; then
echo -n "stereo test... "
- ./testcelt 44100 2 256 128 92 stereo_test_file.sw $outfile
+ ./testcelt 44100 2 256 92 stereo_test_file.sw $outfile
if [ $? != 0 ]; then
exit 1
fi
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -259,21 +259,36 @@
RESTORE_STACK;
}
-static celt_word32_t fold(const CELTMode *m, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B)
+void renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int stride)
{
+ int i;
+ celt_word32_t E = EPSILON;
+ celt_word16_t g;
+ celt_norm_t *xptr = X;
+ for (i=0;i<N;i++)
+ {
+ E = MAC16_16(E, *xptr, *xptr);
+ xptr += stride;
+ }
+
+ g = MULT16_16_Q15(value,celt_rcp(SHL32(celt_sqrt(E),9)));
+ xptr = X;
+ for (i=0;i<N;i++)
+ {
+ *xptr = PSHR32(MULT16_16(g, *xptr),8);
+ xptr += stride;
+ }
+}
+
+static void fold(const CELTMode *m, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B)
+{
int j;
- celt_word32_t E;
const int C = CHANNELS(m);
int id = N0 % (C*B);
/* Here, we assume that id will never be greater than N0, i.e. that
no band is wider than N0. */
- E = EPSILON;
for (j=0;j<C*N;j++)
- {
P[j] = Y[id++];
- E = MAC16_16(E, P[j],P[j]);
- }
- return E;
}
#define KGAIN 6
@@ -283,15 +298,14 @@
int j;
celt_word16_t s = 1;
int sign;
- celt_word32_t E;
celt_word16_t pred_gain;
celt_word32_t xy=0;
const int C = CHANNELS(m);
-
+
pred_gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,N),(celt_word32_t)(N+KGAIN*K));
-
- E = fold(m, N, Y, P, N0, B);
-
+
+ fold(m, N, Y, P, N0, B);
+
for (j=0;j<C*N;j++)
xy = MAC16_16(xy, P[j], x[j]);
if (xy<0)
@@ -304,17 +318,12 @@
}
ec_enc_bits(enc,sign,1);
- /*pred_gain = pred_gain/sqrt(E);*/
- pred_gain = s*MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9)));
- for (j=0;j<C*N;j++)
- P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8);
+ renormalise_vector(P, s*pred_gain, C*N, 1);
}
void intra_unquant(const CELTMode *m, celt_norm_t *x, int N, int K, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B, ec_dec *dec)
{
- int j;
celt_word16_t s;
- celt_word32_t E;
celt_word16_t pred_gain;
const int C = CHANNELS(m);
@@ -325,25 +334,17 @@
pred_gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,N),(celt_word32_t)(N+KGAIN*K));
- E = fold(m, N, Y, P, N0, B);
+ fold(m, N, Y, P, N0, B);
- /*pred_gain = pred_gain/sqrt(E);*/
- pred_gain = s*MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9)));
- for (j=0;j<C*N;j++)
- P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8);
+ renormalise_vector(P, s*pred_gain, C*N, 1);
}
void intra_fold(const CELTMode *m, celt_norm_t *x, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B)
{
- int j;
- celt_word32_t E;
- celt_word16_t g;
const int C = CHANNELS(m);
- E = fold(m, N, Y, P, N0, B);
+ fold(m, N, Y, P, N0, B);
- g = celt_rcp(SHL32(celt_sqrt(E),9));
- for (j=0;j<C*N;j++)
- P[j] = PSHR32(MULT16_16(g, P[j]),8);
+ renormalise_vector(P, Q15ONE, C*N, 1);
}