在项目中使用Speex对实时采集到的音频流进行去噪,发现运行一段时间后程序就会崩溃。
然后再让程序跑起来等着,出错后得到如下信息:
#0 0xb6e46390 in raise () from /lib/libpthread.so.0
#1 0xb6259ee4 in __aeabi_ldiv0 () at ../../../../gcc~linaro-4.8-2013.12/libgcc/config/arm/lib1funcs.S:1331
#2 0xb634e91c in ?? () from /yaffs2/app/lib/libAudioProcessModule.so
据此查看源码后确定是DIV32_16_Q15调用的DIV32_16引起的,故修改fixed_generic.h的最后几行:
200 #if 0
201 #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
202 #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b))
203 #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
204 #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b))
205 #else
206 //modify by sunxiaopeng
207 #define DIV32_16(a,b) (0==(b)?0:(((spx_word32_t)(a))/(spx_word16_t)(b)))
208 #define PDIV32_16(a,b) (0==(b)?0:(((spx_word32_t)(a))/(spx_word16_t)(b)))
209 #define DIV32(a,b) (0==(b)?0:(((spx_word32_t)(a))/(spx_word32_t)(b)))
210 #define PDIV32(a,b) (0==(b)?0:(((spx_word32_t)(a))/(spx_word32_t)(b)))
211 #endif
搞定收工!
注: 这里我用的编译选项是FIXED_POINT,因为如果用FLOATING_POINT很多Android手机跑不动。
另外还有个编译选项是FIXED_POINT_DEBUG,开启后也可以避免除0错误,但是它内部的判断较多,估计会慢一些。