目录
一、概述
二、实例
1、源码下载和编译
https://github.com/xiph/speex/tree/master,这个是codec库,用于编解码的
https://github.com/xiph/speexdsp,现在只是测试一下speex的去噪部分,speex dsp库
选择对应的tag 版本,下载
./autogen.sh;./configure ;make;sudo make install;sudo ldconfig
然后可以看到在/usr/local/include/speex;/usr/local/lib/,里的头文件和库
2、去噪测试程序
makefile
all:speex-denoise
CC := gcc
CFLAGS :=
GCC_C_INCLUDES +=
GCC_LD_FLAGS +=
GCC_SHARED_LIBRARIES := -lspeexdsp -lm
speex-denoise : *.o
$(CC) -o $@ $^ $(GCC_LD_FLAGS) $(GCC_SHARED_LIBRARIES)
*.o : *.c
$(CC) $(GCC_C_INCLUDES) $(CFLAGS) -o $@ -c $<
clean:
rm *.o speex-denoise
程序
#include
#include
#include
#include
#define NN 1024 * 2
int main(int argc, char **argv) {
short in[NN];
int i;
SpeexPreprocessState *st = NULL;
int count = 0;
float f;
FILE *fin = NULL;
FILE *fout = NULL;
if (argc != 3) {
printf("usage: ./out input.pcm output.pcm.\n");
return -1;
}
st = speex_preprocess_state_init(NN, 44100);
if (st == NULL) {
fprintf(stderr, "failed to speex_preprocess_state_init.\n");
return -1;
}
i = 1;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &i);
i = 20;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &i);
i = 0;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i);
f = 0.0;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
f = 0.0;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
fin = fopen(argv[1], "rb");
if (fin == NULL) {
fprintf(stderr, "failed to fopen %s.\n", argv[1]);
return -1;
}
fout = fopen(argv[2], "wb+");
if (fout == NULL) {
fprintf(stderr, "failed to fopen %s.\n", argv[2]);
return -1;
}
int vad;
while (!feof(fin)) {
fread(in, sizeof(short), NN, fin);
if (feof(fin)) {
break;
}
vad = speex_preprocess_run(st, in);
fwrite(in, sizeof(short), NN, fout);
}
speex_preprocess_state_destroy(st);
fclose(fin);
fclose(fout);
return 0;
}
[16:23:01]In file included from /usr/local/include/speex/speexdsp_types.h:122:0,
[16:23:01] from test-denoise.c:3:
[16:23:01]/usr/local/include/speex/speexdsp_config_types.h:12:9: error: unknown type name ‘int16_t’
[16:23:01] typedef int16_t spx_int16_t;
[16:23:01] ^
[16:23:01]/usr/local/include/speex/speexdsp_config_types.h:13:9: error: unknown type name ‘uint16_t’
[16:23:01] typedef uint16_t spx_uint16_t;
[16:23:01] ^
[16:23:01]/usr/local/include/speex/speexdsp_config_types.h:14:9: error: unknown type name ‘int32_t’
[16:23:01] typedef int32_t spx_int32_t;
[16:23:01] ^
[16:23:01]/usr/local/include/speex/speexdsp_config_types.h:15:9: error: unknown type name ‘uint32_t’
[16:23:01] typedef uint32_t spx_uint32_t;
[16:23:01] ^
[16:23:01]Makefile:15: recipe for target '*.o' failed
[16:23:01]make: *** [*.o] Error 1
出现上面的编译错误,把头文件stdint.h加入
运行:./speex-denoise input_0.pcm output.pcm
波形图:上面为输出,下面为输入
频谱分析图:上面为输出,下面为输入
看起来还是有效果的
3、androids上集成
Extern中已经有speex的源码,但是编译的是静态库,修改android.mk,改成编译成动态库
然后在推流端的audio source端加入处理,结果测试还有有效的
三、总结
只是简单的测试一下,后面还会用webrtc里的audio process模块来测试。只是简单的调库调参