ref: 3295b5d56b46f46c92ef1aeeffe83c330a082916
parent: c4711e4e11b0672e2b6466ae5df2209938d7aca3
author: Jean-Marc Valin <[email protected]>
date: Fri Oct 15 19:43:45 EDT 2010
Folding code moved to quant_band() to prevent duplication.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -486,6 +486,10 @@
return qn;
}
+static celt_uint32 lcg_rand(celt_uint32 seed)
+{
+ return 1664525 * seed + 1013904223;
+}
/* This function is responsible for encoding and decoding a band for both
the mono and stereo case. Even in the mono case, it can split the band
@@ -821,11 +825,37 @@
*remaining_bits -= curr_bits;
}
- /* Finally do the actual quantization */
- if (encode)
- alg_quant(X, N, q, spread, B, lowband, resynth, (ec_enc*)ec, seed, gain);
- else
- alg_unquant(X, N, q, spread, B, lowband, (ec_dec*)ec, seed, gain);
+ if (q!=0)
+ {
+ int K = get_pulses(q);
+
+ /* Finally do the actual quantization */
+ if (encode)
+ alg_quant(X, N, K, spread, B, lowband, resynth, (ec_enc*)ec, seed, gain);
+ else
+ alg_unquant(X, N, K, spread, B, lowband, (ec_dec*)ec, seed, gain);
+ } else {
+ int j;
+ if (lowband != NULL && resynth)
+ {
+ if (spread==2 && B<=1)
+ {
+ for (j=0;j<N;j++)
+ {
+ *seed = lcg_rand(*seed);
+ X[j] = (int)(*seed)>>20;
+ }
+ } else {
+ for (j=0;j<N;j++)
+ X[j] = lowband[j];
+ }
+ renormalise_vector(X, N, gain);
+ } else {
+ /* This is important for encoding the side in stereo mode */
+ for (j=0;j<N;j++)
+ X[j] = 0;
+ }
+ }
}
/* This code is used by the decoder and by the resynthesis-enabled encoder */
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -45,11 +45,6 @@
#define M_PI 3.141592653
#endif
-static celt_uint32 lcg_rand(celt_uint32 seed)
-{
- return 1664525 * seed + 1013904223;
-}
-
static void exp_rotation1(celt_norm *X, int len, int stride, celt_word16 c, celt_word16 s)
{
int i;
@@ -175,31 +170,7 @@
celt_word16 yy;
SAVE_STACK;
- /* When there's no pulse, fill with noise or folded spectrum */
- if (K==0)
- {
- if (lowband != NULL && resynth)
- {
- if (spread==2 && B<=1)
- {
- for (j=0;j<N;j++)
- {
- *seed = lcg_rand(*seed);
- X[j] = (int)(*seed)>>20;
- }
- } else {
- for (j=0;j<N;j++)
- X[j] = lowband[j];
- }
- renormalise_vector(X, N, gain);
- } else {
- /* This is important for encoding the side in stereo mode */
- for (j=0;j<N;j++)
- X[j] = 0;
- }
- return;
- }
- K = get_pulses(K);
+ celt_assert2(K!=0, "alg_quant() needs at least one pulse");
ALLOC(y, N, celt_norm);
ALLOC(iy, N, int);
@@ -354,30 +325,7 @@
VARDECL(int, iy);
SAVE_STACK;
- if (K==0)
- {
- if (lowband != NULL)
- {
- if (spread==2 && B<=1)
- {
- for (i=0;i<N;i++)
- {
- *seed = lcg_rand(*seed);
- X[i] = (int)(*seed)>>20;
- }
- } else {
- for (i=0;i<N;i++)
- X[i] = lowband[i];
- }
- renormalise_vector(X, N, gain);
- } else {
- /* This is important for encoding the side in stereo mode */
- for (i=0;i<N;i++)
- X[i] = 0;
- }
- return;
- }
- K = get_pulses(K);
+ celt_assert2(K!=0, "alg_unquant() needs at least one pulse");
ALLOC(iy, N, int);
decode_pulses(iy, N, K, dec);
Ryy = 0;