mirror of
https://github.com/xiph/opus.git
synced 2025-06-02 00:27:43 +00:00
fixed-point: fixing two overflows that didn't really affect quality
This commit is contained in:
parent
7c422653f3
commit
cd29b02773
3 changed files with 16 additions and 6 deletions
|
@ -233,6 +233,8 @@ int compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_
|
||||||
Sxy = MAC16_16(Sxy, X[j], P[j]);
|
Sxy = MAC16_16(Sxy, X[j], P[j]);
|
||||||
Sxx = MAC16_16(Sxx, X[j], X[j]);
|
Sxx = MAC16_16(Sxx, X[j], X[j]);
|
||||||
}
|
}
|
||||||
|
Sxy = SHR32(Sxy,2);
|
||||||
|
Sxx = SHR32(Sxx,2);
|
||||||
/* No negative gain allowed */
|
/* No negative gain allowed */
|
||||||
if (Sxy < 0)
|
if (Sxy < 0)
|
||||||
Sxy = 0;
|
Sxy = 0;
|
||||||
|
|
|
@ -427,18 +427,20 @@ static inline short MULT16_16_Q14(int a, int b)
|
||||||
celt_mips+=3;
|
celt_mips+=3;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
static inline short MULT16_16_Q15(int a, int b)
|
|
||||||
|
#define MULT16_16_Q15(a, b) _MULT16_16_Q15(a, b, __FILE__, __LINE__)
|
||||||
|
static inline short _MULT16_16_Q15(int a, int b, char *file, int line)
|
||||||
{
|
{
|
||||||
long long res;
|
long long res;
|
||||||
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
|
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
|
||||||
{
|
{
|
||||||
fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d\n", a, b);
|
fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
|
||||||
}
|
}
|
||||||
res = ((long long)a)*b;
|
res = ((long long)a)*b;
|
||||||
res >>= 15;
|
res >>= 15;
|
||||||
if (!VERIFY_SHORT(res))
|
if (!VERIFY_SHORT(res))
|
||||||
{
|
{
|
||||||
fprintf (stderr, "MULT16_16_Q15: output is not short: %d\n", (int)res);
|
fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line);
|
||||||
}
|
}
|
||||||
celt_mips+=1;
|
celt_mips+=1;
|
||||||
return res;
|
return res;
|
||||||
|
@ -547,6 +549,6 @@ static inline int _DIV32(long long a, long long b, char *file, int line)
|
||||||
#define PDIV32_16(a,b) DIV32_16(ADD32((a),(b)>>1),b)
|
#define PDIV32_16(a,b) DIV32_16(ADD32((a),(b)>>1),b)
|
||||||
|
|
||||||
#undef PRINT_MIPS
|
#undef PRINT_MIPS
|
||||||
#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %d MIPS\n", celt_mips);} while (0);
|
#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", celt_mips);} while (0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
10
libcelt/vq.c
10
libcelt/vq.c
|
@ -335,7 +335,14 @@ celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int
|
||||||
}
|
}
|
||||||
|
|
||||||
rE = celt_sqrt(E);
|
rE = celt_sqrt(E);
|
||||||
g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9)));
|
/*if (celt_rcp(SHL32(rE,9))>32767)
|
||||||
|
fprintf (stderr, "celt_rcp: %d %d\n",rE, E); */
|
||||||
|
#ifdef FIXED_POINT
|
||||||
|
if (rE <= 128)
|
||||||
|
g = Q15ONE;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
g = MULT16_16_Q15(value,celt_rcp(SHL32(rE,9)));
|
||||||
xptr = X;
|
xptr = X;
|
||||||
for (i=0;i<N;i++)
|
for (i=0;i<N;i++)
|
||||||
{
|
{
|
||||||
|
@ -374,7 +381,6 @@ void intra_fold(const CELTMode *m, celt_norm_t * restrict x, int N, int K, celt_
|
||||||
pred_gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,N),(celt_word32_t)(N+KGAIN*K));
|
pred_gain = celt_div((celt_word32_t)MULT16_16(Q15_ONE,N),(celt_word32_t)(N+KGAIN*K));
|
||||||
|
|
||||||
fold(m, N, Y, P, N0, B);
|
fold(m, N, Y, P, N0, B);
|
||||||
|
|
||||||
renormalise_vector(P, pred_gain, C*N, 1);
|
renormalise_vector(P, pred_gain, C*N, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue