Folding code moved to quant_band() to prevent duplication.
This commit is contained in:
parent
c4711e4e11
commit
3295b5d56b
2 changed files with 37 additions and 59 deletions
|
@ -486,6 +486,10 @@ static int compute_qn(int N, int b, int offset, int stereo)
|
||||||
return qn;
|
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
|
/* 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
|
the mono and stereo case. Even in the mono case, it can split the band
|
||||||
|
@ -821,11 +825,37 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_
|
||||||
*remaining_bits -= curr_bits;
|
*remaining_bits -= curr_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (q!=0)
|
||||||
|
{
|
||||||
|
int K = get_pulses(q);
|
||||||
|
|
||||||
/* Finally do the actual quantization */
|
/* Finally do the actual quantization */
|
||||||
if (encode)
|
if (encode)
|
||||||
alg_quant(X, N, q, spread, B, lowband, resynth, (ec_enc*)ec, seed, gain);
|
alg_quant(X, N, K, spread, B, lowband, resynth, (ec_enc*)ec, seed, gain);
|
||||||
else
|
else
|
||||||
alg_unquant(X, N, q, spread, B, lowband, (ec_dec*)ec, seed, gain);
|
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 */
|
/* This code is used by the decoder and by the resynthesis-enabled encoder */
|
||||||
|
|
56
libcelt/vq.c
56
libcelt/vq.c
|
@ -45,11 +45,6 @@
|
||||||
#define M_PI 3.141592653
|
#define M_PI 3.141592653
|
||||||
#endif
|
#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)
|
static void exp_rotation1(celt_norm *X, int len, int stride, celt_word16 c, celt_word16 s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -175,31 +170,7 @@ void alg_quant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband
|
||||||
celt_word16 yy;
|
celt_word16 yy;
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
|
|
||||||
/* When there's no pulse, fill with noise or folded spectrum */
|
celt_assert2(K!=0, "alg_quant() needs at least one pulse");
|
||||||
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);
|
|
||||||
|
|
||||||
ALLOC(y, N, celt_norm);
|
ALLOC(y, N, celt_norm);
|
||||||
ALLOC(iy, N, int);
|
ALLOC(iy, N, int);
|
||||||
|
@ -354,30 +325,7 @@ void alg_unquant(celt_norm *X, int N, int K, int spread, int B,
|
||||||
VARDECL(int, iy);
|
VARDECL(int, iy);
|
||||||
SAVE_STACK;
|
SAVE_STACK;
|
||||||
|
|
||||||
if (K==0)
|
celt_assert2(K!=0, "alg_unquant() needs at least one pulse");
|
||||||
{
|
|
||||||
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);
|
|
||||||
ALLOC(iy, N, int);
|
ALLOC(iy, N, int);
|
||||||
decode_pulses(iy, N, K, dec);
|
decode_pulses(iy, N, K, dec);
|
||||||
Ryy = 0;
|
Ryy = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue