我在程序中使用 libresample。一段时间后(大约 50 分钟),它在一个工作站的 lib 函数 lrsFilterUD() 中崩溃。
float lrsFilterUD(float Imp[], /* impulse response */
float ImpD[], /* impulse response deltas */
UWORD Nwing, /* len of one wing of filter */
BOOL Interp, /* Interpolate coefs using deltas? */
float *Xp, /* Current sample */
double Ph, /* Phase */
int Inc, /* increment (1 for right wing or -1 for left) */
double dhb)
{
float a;
float *Hp, *Hdp, *End;
float v, t;
double Ho;
v = 0.0; /* The output value */
Ho = Ph*dhb;
End = &Imp[Nwing];
if (Inc == 1) /* If doing right wing... */
{ /* ...drop extra coeff, so when Ph is */
End--; /* 0.5, we don't do too many mult's */
if (Ph == 0) /* If the phase is zero... */
Ho += dhb; /* ...then we've already skipped the */
} /* first sample, so we must also */
/* skip ahead in Imp[] and ImpD[] */
if (Interp)
while ((Hp = &Imp[(int)Ho]) < End) {
t = *Hp; /* Get IR sample */
Hdp = &ImpD[(int)Ho]; /* get interp bits from diff table*/
a = Ho - floor(Ho); /* a is logically between 0 and 1 */
t += (*Hdp)*a; /* t is now interp'd filter coeff */
t *= *Xp; /* Mult coeff by input sample */
v += t; /* The filter output */
Ho += dhb; /* IR step */
Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */
}
else
while ((Hp = &Imp[(int)Ho]) < End) {
dprintf("while begin: Hp = %p, *Hp = %a, (int)Ho = %d, Imp[(int)Ho] = %a, &Imp[(int)Ho] = %p", Hp, *Hp, (int)Ho, Imp[(int)Ho], &Imp[(int)Ho]);
t = *Hp; /* Get IR sample */
dprintf("before t = %a, *Xp = %a, Xp = %p", t, *Xp, Xp);
t *= *Xp; /* Mult coeff by input sample */
dprintf("after2 t = %a, v = %a", t, v);
v += t; /* The filter output */
dprintf("v = %a", v);
Ho += dhb; /* IR step */
Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */
}
return v;
}
我在乘法之前和之后记录了 t、*Xp、Xp 的值:
while begin: Hp = 0xaf5daa8, *Hp = -0.009034, (int)Ho = 16384, Imp[(int)Ho] = -0.009034, &Imp[(int)Ho] = 0xaf5daa8
before multiplication t = -0.009034, *Xp = 0.000000, Xp = 0xaebe9b8
after multiplication t = nan
此代码运行多次,崩溃前有相同的 t 和 Xp 值:
before multiplication t = -0.009034, *Xp = 0.000000, Xp = 0xaebe9c8
after multiplication t = -0.000000, v = 282.423676
或另一种情况:
before addition t = -460.799988, v = 0.000000
after addition v = nan
什么可能导致nan?这是在 Linux 上使用 gcc 4.1.2 编译的。
更新:将变量打印为 %a。结果:
//t = 0x1.2806bap+2
//Hp = 0xb3bb870
t = *Hp;
//t = nan
更新 2:如果代码由 icpc 编译,则不存在此类问题。那么有编译器特定的问题吗?