1、下載speex源代碼
http://download.csdn.net/detail/codeheng/9523856
2、配置makefile
./configure --host=arm-linux CC=arm-linux-gcc --enable-static --disable-shared
3、make
4、xx\speexdsp-1.2rc3\libspeexdsp\.libs路徑下會生成靜態庫文件
5、xx\speexdsp-1.2rc3\libspeexdsp 會有一些demo供參考
6、編譯鏈接的時候加上 -lm
//speex不是線程安全的,如多線程調用必須加鎖
static SpeexPreprocessState* init()
{
SpeexPreprocessState* SPstat = speex_preprocess_state_init(160, 8000); // 8000: 採樣率;160:20ms的採樣點(8000/1000*20)
int value = 1;
speex_preprocess_ctl(SPstat, SPEEX_PREPROCESS_SET_DENOISE, &value);
value = -50;
speex_preprocess_ctl(SPstat, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &value);//降噪強度
return SPstat;
}
static int audio_speex_denoise(SpeexPreprocessState* SPstat, unsigned char* buf, int size)
{
int samples = 160; // 20ms 的採樣點
int frame_size = samples*2; // 每個採樣點2bytes
int remain_size = size;
unsigned char* begin = buf;
while (remain_size >= frame_size)
{
speex_preprocess_run(SPstat, (short*)begin);// 每調一次處理20ms個採樣點(與speex_preprocess_state_init一致)
//如果不是frame_size的整數倍,則想辦法弄成整數倍,否則會有部分數據得不到降噪處理
begin += frame_size;
remain_size -= frame_size;
}
return 0;
}