l最近在调speex接口参数,将speex算法的一些特性给添加进去,比如:降噪,静音检测,白噪声添加,增益等等。下面我们就先简单介绍一些spexx算
法。speex语音算法主要是针对VOIP应用的一个开源算法,他集合了多种功能,除了如上所述的,还增加了回声消除(ACE)等功能,能够在多种平台
进行应用。下面我主要介绍一下speex在android平台上的应用。
首先我们来介绍一下speex算法的模块划分。在介绍之前,我们最好去speex官网 http://www.speex.org/downloads/ 去下载他的相关文档以及源码。其
中有一个包speex-api-reference.tar.gz 就有speex模块的相关介绍。其API介绍在1.2为止,speex总共分为以下9大模块:
--Speex encoder and decoder。——编码和解码模块。
--SpeexBits:Bit-stream mainpulations。——比特流操作模块,也就是数据的读写模块。
--Various definitions for Speex callbacks supported by the decoder。——解码回调模块。
--SpeexEchoState:Acoustic echo caceller。——回声消除模块。
--SpeexHeader:Makes it easy to writ/parse an Ogg/Speex header。——ogg格式相关的处理模块。
--JitterBuffer:Adaptive jitter buffer。——语音抖动缓冲模块。
--SpeexJitter:Adaptive jitter buffer specifically for Speex。——针对speex算法特点优化的语言抖动处理模块。
--SpeexPreprocessState:The Speex preprocessor。——Speex其他相关特点的处理模块,如:降噪,静音检测等。
--SpeexStereoState:Handing Speex stereo files。——立体声处理的相关模块。
.以上就是Speex算法的主要模块,每个模块都有相关功能的函数接口,具体我们可以去查看其api的相关介绍。
好了现在我们来介绍其在android平台的使用。由于其使用的是C实现的,所以要想在android进行调用其相关方法就必须通过JNI的方法进行调用,所以
我们首先就必须获得speex算法的一个.so文件,因此我们先使用cygwin编译获取.so文件。
一、将speex相关源码复制进项目
下载speex源码,在项目中新建文件夹,命名为jni。将speex源码下的include,libspeex两个文件的源码复制进jni文件夹中。将include文件夹下的
speex_config_types.h.in文件改为speex_config_types.h文件,并且将其中的内容改为以下内容:
#ifndef _SPEEX_CONFIG_TYPES_H
#define _SPEEX_CONFIG_TYPES_H
typedef signed short spx_int16_t;
typedef unsigned short spx_uint16_t;
typedef signed int spx_int32_t;
typedef unsigned int spx_uint32_t;
#endif /* _SPEEX_CONFIG_TYPES_H */
二、编写Android.mk以及Application.mk相关文件。
Android.mk文件内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libspeex
LOCAL_CFLAGS = -DFIXED_POINT -DUSE_KISS_FFT -DEXPORT="" -UHAVE_CONFIG_H
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := speex_jni.cpp \
./libspeex/bits.c \
./libspeex/buffer.c \
./libspeex/cb_search.c