Commit e26f1a17 authored by jm's avatar jm
Browse files

removed a bunch of overflow cases, most of which were in wideband


git-svn-id: http://svn.xiph.org/trunk/speex@11408 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 034e6403
......@@ -70,7 +70,7 @@ static void compute_weighted_codebook(const signed char *shape_cb, const spx_wor
for (k=0;k<=j;k++)
resj = MAC16_16(resj,shape[k],r[j-k]);
#ifdef FIXED_POINT
res16 = EXTRACT16(SHR32(resj, 11));
res16 = EXTRACT16(SHR32(resj, 13));
#else
res16 = 0.03125f*resj;
#endif
......@@ -89,7 +89,7 @@ static inline void target_update(spx_word16_t *t, spx_word16_t g, spx_word16_t *
{
int n;
for (n=0;n<len;n++)
t[n] = SUB32(t[n],MULT16_16_Q11_32(g,r[n]));
t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));
}
#endif
......@@ -154,7 +154,7 @@ int update_target
/* FIXME: make that adaptive? */
for (i=0;i<nsf;i++)
t[i]=EXTRACT16(PSHR32(target[i],6));
t[i]=EXTRACT16(PSHR32(target[i],8));
compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);
......@@ -349,7 +349,7 @@ int update_target
/* FIXME: make that adaptive? */
for (i=0;i<nsf;i++)
t[i]=EXTRACT16(PSHR32(target[i],6));
t[i]=EXTRACT16(PSHR32(target[i],8));
for (j=0;j<N;j++)
speex_move(&ot[j][0], t, nsf*sizeof(spx_word16_t));
......
......@@ -85,9 +85,9 @@ void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
scale_1 = EXTRACT16(PDIV32_16(SHL32(EXTEND32(SIG_SCALING),7),scale));
for (i=0;i<len;i++)
{
y[i] = SHR32(MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT))),7);
y[i] = PSHR32(MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT))),7);
}
} else {
} else if (scale > SHR32(EXTEND32(SIG_SCALING), 2)) {
spx_word16_t scale_1;
scale = PSHR32(scale, SIG_SHIFT-5);
scale_1 = DIV32_16(SHL32(EXTEND32(SIG_SCALING),3),scale);
......@@ -95,6 +95,16 @@ void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
{
y[i] = MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT-2)));
}
} else {
spx_word16_t scale_1;
scale = PSHR32(scale, SIG_SHIFT-7);
if (scale < 5)
scale = 5;
scale_1 = DIV32_16(SHL32(EXTEND32(SIG_SCALING),3),scale);
for (i=0;i<len;i++)
{
y[i] = SHL32(MULT16_16(scale_1, EXTRACT16(SHR32(x[i],SIG_SHIFT-2))),2);
}
}
}
......@@ -526,14 +536,13 @@ void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, cons
i++;
for (;i<N;i++)
y[i] = VERY_SMALL;
for (i=0;i<ord;i++)
mem1[i] = mem2[i] = 0;
for (i=0;i<N;i++)
{
y1 = ADD16(y[i], EXTRACT16(PSHR32(mem1[0],LPC_SHIFT)));
ny1i = NEG16(y1);
y[i] = ADD16(SHL16(y1,1), EXTRACT16(PSHR32(mem2[0],LPC_SHIFT)));
y[i] = PSHR32(ADD32(SHL32(EXTEND32(y1),LPC_SHIFT+1),mem2[0]),LPC_SHIFT);
ny2i = NEG16(y[i]);
for (j=0;j<ord-1;j++)
{
......
......@@ -170,7 +170,7 @@ static inline short ADD16(int a, int b)
}
res = a+b;
if (!VERIFY_SHORT(res))
fprintf (stderr, "ADD16: output is not short: %d\n", res);
fprintf (stderr, "ADD16: output is not short: %d+%d=%d\n", a,b,res);
spx_mips++;
return res;
}
......@@ -197,7 +197,9 @@ static inline int ADD32(long long a, long long b)
}
res = a+b;
if (!VERIFY_INT(res))
{
fprintf (stderr, "ADD32: output is not int: %d\n", (int)res);
}
spx_mips++;
return res;
}
......@@ -440,7 +442,7 @@ static inline int DIV32(long long a, long long b)
spx_mips+=36;
return res;
}
#define PDIV32(a,b) DIV32(ADD32((a),(b)>>1),b)
#define PDIV32_16(a,b) DIV32_16(ADD32((a),(b)>>1),b)
#endif
......@@ -94,7 +94,7 @@ int p
for (j = 0; j < i; j++)
rr = SUB32(rr,MULT16_16(lpc[j],ac[i - j]));
#ifdef FIXED_POINT
r = DIV32_16(rr+PSHR32(error,1),ADD16(error,4));
r = DIV32_16(rr+PSHR32(error,1),ADD16(error,8));
#else
r = rr/(error+.003*ac[0]);
#endif
......
......@@ -493,8 +493,8 @@ static const SpeexSBMode sb_wb_mode = {
#else
0.9, 0.6, /* gamma1, gamma2 */
#endif
.001, /*lag_factor*/
QCONST16(.0001,15), /*lpc_floor*/
.012, /*lag_factor*/
QCONST16(.0002,15), /*lpc_floor*/
0.9,
{NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL},
3,
......@@ -539,8 +539,8 @@ static const SpeexSBMode sb_uwb_mode = {
#else
0.9, 0.6, /* gamma1, gamma2 */
#endif
.002, /*lag_factor*/
QCONST16(.0001,15), /*lpc_floor*/
.012, /*lag_factor*/
QCONST16(.0002,15), /*lpc_floor*/
0.7,
{NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL},
1,
......
......@@ -724,7 +724,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits)
if (st->subframeSize==80)
gc *= 1.4142;
scale = SHL(MULT16_16(PDIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4);
scale = SHL32(MULT16_16(PDIV32_16(SHL32(EXTEND32(gc),SIG_SHIFT-6),filter_ratio),(1+el)),6);
compute_impulse_response(st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
......@@ -1191,7 +1191,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout)
if (st->subframeSize==80)
gc *= 1.4142;
scale = SHL(MULT16_16(PDIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4);
scale = SHL(MULT16_16(PDIV32_16(SHL(gc,SIG_SHIFT-6),filter_ratio),(1+el)),6);
SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,
bits, stack);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment