Speex

来源:互联网 发布:最好的优化软件 编辑:程序博客网 时间:2024/05/17 06:48

目录(?)[-]

  1. Current Unstable Release recommended
    1. rc1
    2. beta3
    3. beta2
  2. Current Stable Release old not recommended
  3. DirectShow Filters
Speex: a free codec for free speech
Downloads

Speex是一套主要针对语音的开源免费,无专利保护的音频压缩格式。Speex工程着力于通过提供一个可以替代高性能语音编解码来降低语音应用输入门槛 。另外,相对于其它编解码器,Speex也很适合网络应用,在网络应用上有着自己独特的优势。同时,Speex还是GNU工程的一部分,在改版的BSD协议中得到了很好的支持。




The latest development version of Speex is always available through Git by at http://git.xiph.org/speex.git. Note that packaging information for Debian can be found on the packages page. In addition, RareWares maintains useful Windows utilities such as SpeexDrop.

Current Unstable Release (recommended)

1.2rc1

This release adds support for acoustic echo cancellation with multiple microphones and multiple loudspeakers. It also adds an API to decorrelate loudspeaker signals to improve multi-channel performance. In the bugfix department, there are fixes for a few bugs in the echo canceller, jitter buffer and preprocessor. At this point, the API for 1.2 should be stable and only a few very minor additions are planned.

Downloads:
  • Source Code

1.2beta3

The most obvious change in this release is that all the non-codec components (preprocessor, echo cancellation, jitter buffer) have been moved to a new libspeexdsp library. Other changes include a new jitter buffer algorithm and resampler improvements/fixes. This is also the first release where libspeex can be built without any floating point support. To do this, the float compatibility API must be disabled (--disable-float-api or DISABLE_FLOAT_API) and the VBR feature must be disabled (--disable-vbr or DISABLE_VBR).

Downloads:
  • Source Code
  • Windows binaries

1.2beta2

Again, this new releases brings many improvements. The RAM requirement for wideband has gone down drastically (i.e. more than 2x). A new resampler module has been added, providing arbitrary sampling rate conversion -- fast. The echo canceller has also been improved. A bug in 1.2beta1 that made the echo canceller unstable has been fixed. The echo canceller should now converge faster, be robust and tolerant of incorrect capture-playback synchronisation. The preprocessor has also been greatly improved. Not only should the quality be better, but it is now fully converted to fixed-point. At last, early TriMedia support (incomplete) has been merged.

Downloads:
  • Source Code
  • i386 RPM
  • i386 Development RPM
  • Source RPM
  • No Windows binaries -- looking for a maintainer

Current Stable Release (old, not recommended)

1.0.5

The main change with this release is that it includes API additions from the 1.1.x branch (while being backward compatible), so that transition from 1.0.x to 1.1.x can be made easier.

  • Source Code
  • i386 RPM
  • i386 Development RPM
  • Source RPM
  • Windows binaries (1.0.4)

DirectShow Filters

If you just want to listen to Speex files in Windows Media Player, get Xiph.Org's DirectShow Filters for Speex.




http://blog.csdn.net/chenfeng0104/article/details/7088138

在Android开发中,需要录音并发送到对方设备上。这时问题来了,手机常会是GPRS、3G等方式上网,所以节省流量是非常关键的,使用Speex来压缩音频文件,可以将音频压文件小数倍。

1.去Speex官网下载最新Speex源码。

2.创建一个新的应用(我创建的应用名为Audio),并创建一个jni目录($project/jni)。

3.把speex源码目录下的libspeex和include目录及其子目录文件全部拷贝到$project/jni目录下($project/jni/libspeex and $project/jni/include)。

4.在jni目录下新增Android.mk文件,编辑内容如下

[plain] view plaincopy
  1. LOCAL_PATH := $(call my-dir)  
  2.   
  3.   
  4. include $(CLEAR_VARS)  
  5.    
  6. LOCAL_MODULE    := libspeex  
  7. LOCAL_CFLAGS = -DFIXED_POINT -DUSE_KISS_FFT -DEXPORT="" -UHAVE_CONFIG_H  
  8. LOCAL_C_INCLUDES := $(LOCAL_PATH)/include  
  9.    
  10. LOCAL_SRC_FILES :=  \  
  11. ./speex_jni.cpp \  
  12. ./libspeex/bits.c \  
  13. ./libspeex/buffer.c \  
  14. ./libspeex/cb_search.c \  
  15. ./libspeex/exc_10_16_table.c \  
  16. ./libspeex/exc_10_32_table.c \  
  17. ./libspeex/exc_20_32_table.c \  
  18. ./libspeex/exc_5_256_table.c \  
  19. ./libspeex/exc_5_64_table.c \  
  20. ./libspeex/exc_8_128_table.c \  
  21. ./libspeex/fftwrap.c \  
  22. ./libspeex/filterbank.c \  
  23. ./libspeex/filters.c \  
  24. ./libspeex/gain_table.c \  
  25. ./libspeex/gain_table_lbr.c \  
  26. ./libspeex/hexc_10_32_table.c \  
  27. ./libspeex/hexc_table.c \  
  28. ./libspeex/high_lsp_tables.c \  
  29. ./libspeex/jitter.c \  
  30. ./libspeex/kiss_fft.c \  
  31. ./libspeex/kiss_fftr.c \  
  32. ./libspeex/lpc.c \  
  33. ./libspeex/lsp.c \  
  34. ./libspeex/lsp_tables_nb.c \  
  35. ./libspeex/ltp.c \  
  36. ./libspeex/mdf.c \  
  37. ./libspeex/modes.c \  
  38. ./libspeex/modes_wb.c \  
  39. ./libspeex/nb_celp.c \  
  40. ./libspeex/preprocess.c \  
  41. ./libspeex/quant_lsp.c \  
  42. ./libspeex/resample.c \  
  43. ./libspeex/sb_celp.c \  
  44. ./libspeex/scal.c \  
  45. ./libspeex/smallft.c \  
  46. ./libspeex/speex.c \  
  47. ./libspeex/speex_callbacks.c \  
  48. ./libspeex/speex_header.c \  
  49. ./libspeex/stereo.c \  
  50. ./libspeex/vbr.c \  
  51. ./libspeex/vq.c \  
  52. ./libspeex/window.c  
  53.    
  54. include $(BUILD_SHARED_LIBRARY)  

5.在jni目录下新增Application.mk文件,编辑内容如下

[plain] view plaincopy
  1. APP_ABI := armeabi armeabi-v7a  

6.在$project/jni/include/speex/目录下新增speex_config_types.h文件,编辑内容如下

[cpp] view plaincopy
  1. #ifndef __SPEEX_TYPES_H__  
  2. #define __SPEEX_TYPES_H__  
  3. typedef short spx_int16_t;  
  4. typedef unsigned short spx_uint16_t;  
  5. typedef int spx_int32_t;  
  6. typedef unsigned int spx_uint32_t;  
  7. #endif  

7.创建JNI包装类speex_jni.cpp,用来调用Speex中的C代码函数,编辑内容如下

[cpp] view plaincopy
  1. #include <jni.h>  
  2.   
  3. #include <string.h>  
  4. #include <unistd.h>  
  5.   
  6. #include <speex/speex.h>  
  7.   
  8. static int codec_open = 0;  
  9.   
  10. static int dec_frame_size;  
  11. static int enc_frame_size;  
  12.   
  13. static SpeexBits ebits, dbits;  
  14. void *enc_state;  
  15. void *dec_state;  
  16.   
  17. static JavaVM *gJavaVM;  
  18.   
  19. extern "C"  
  20. JNIEXPORT jint JNICALL Java_com_audio_Speex_open  
  21.   (JNIEnv *env, jobject obj, jint compression) {  
  22.     int tmp;  
  23.   
  24.     if (codec_open++ != 0)  
  25.         return (jint)0;  
  26.   
  27.     speex_bits_init(&ebits);  
  28.     speex_bits_init(&dbits);  
  29.   
  30.     enc_state = speex_encoder_init(&speex_nb_mode);  
  31.     dec_state = speex_decoder_init(&speex_nb_mode);  
  32.     tmp = compression;  
  33.     speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &tmp);  
  34.     speex_encoder_ctl(enc_state, SPEEX_GET_FRAME_SIZE, &enc_frame_size);  
  35.     speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &dec_frame_size);  
  36.   
  37.     return (jint)0;  
  38. }  
  39.   
  40. extern "C"  
  41. JNIEXPORT jint Java_com_audio_Speex_encode  
  42.     (JNIEnv *env, jobject obj, jshortArray lin, jint offset, jbyteArray encoded, jint size) {  
  43.   
  44.         jshort buffer[enc_frame_size];  
  45.         jbyte output_buffer[enc_frame_size];  
  46.     int nsamples = (size-1)/enc_frame_size + 1;  
  47.     int i, tot_bytes = 0;  
  48.   
  49.     if (!codec_open)  
  50.         return 0;  
  51.   
  52.     speex_bits_reset(&ebits);  
  53.   
  54.     for (i = 0; i < nsamples; i++) {  
  55.         env->GetShortArrayRegion(lin, offset + i*enc_frame_size, enc_frame_size, buffer);  
  56.         speex_encode_int(enc_state, buffer, &ebits);  
  57.     }  
  58.     //env->GetShortArrayRegion(lin, offset, enc_frame_size, buffer);  
  59.     //speex_encode_int(enc_state, buffer, &ebits);  
  60.   
  61.     tot_bytes = speex_bits_write(&ebits, (char *)output_buffer,  
  62.                      enc_frame_size);  
  63.     env->SetByteArrayRegion(encoded, 0, tot_bytes,  
  64.                 output_buffer);  
  65.   
  66.         return (jint)tot_bytes;  
  67. }  
  68.   
  69. extern "C"  
  70. JNIEXPORT jint JNICALL Java_com_audio_Speex_decode  
  71.     (JNIEnv *env, jobject obj, jbyteArray encoded, jshortArray lin, jint size) {  
  72.   
  73.         jbyte buffer[dec_frame_size];  
  74.         jshort output_buffer[dec_frame_size];  
  75.         jsize encoded_length = size;  
  76.   
  77.     if (!codec_open)  
  78.         return 0;  
  79.   
  80.     env->GetByteArrayRegion(encoded, 0, encoded_length, buffer);  
  81.     speex_bits_read_from(&dbits, (char *)buffer, encoded_length);  
  82.     speex_decode_int(dec_state, &dbits, output_buffer);  
  83.     env->SetShortArrayRegion(lin, 0, dec_frame_size,  
  84.                  output_buffer);  
  85.   
  86.     return (jint)dec_frame_size;  
  87. }  
  88.   
  89. extern "C"  
  90. JNIEXPORT jint JNICALL Java_com_audio_getFrameSize  
  91.     (JNIEnv *env, jobject obj) {  
  92.   
  93.     if (!codec_open)  
  94.         return 0;  
  95.     return (jint)enc_frame_size;  
  96.   
  97. }  
  98.   
  99. extern "C"  
  100. JNIEXPORT void JNICALL Java_com_audio_Speex_close  
  101.     (JNIEnv *env, jobject obj) {  
  102.   
  103.     if (--codec_open != 0)  
  104.         return;  
  105.   
  106.     speex_bits_destroy(&ebits);  
  107.     speex_bits_destroy(&dbits);  
  108.     speex_decoder_destroy(dec_state);  
  109.     speex_encoder_destroy(enc_state);  
  110. }  

8.在Java层创建Speex工具类,内容如下

[java] view plaincopy
  1. package com.audio;  
  2.   
  3. class Speex  {  
  4.   
  5.     /* quality 
  6.      * 1 : 4kbps (very noticeable artifacts, usually intelligible) 
  7.      * 2 : 6kbps (very noticeable artifacts, good intelligibility) 
  8.      * 4 : 8kbps (noticeable artifacts sometimes) 
  9.      * 6 : 11kpbs (artifacts usually only noticeable with headphones) 
  10.      * 8 : 15kbps (artifacts not usually noticeable) 
  11.      */  
  12.     private static final int DEFAULT_COMPRESSION = 8;  
  13.   
  14.     Speex() {  
  15.     }  
  16.   
  17.     public void init() {  
  18.         load();   
  19.         open(DEFAULT_COMPRESSION);  
  20.     }  
  21.       
  22.     private void load() {  
  23.         try {  
  24.             System.loadLibrary("speex");  
  25.         } catch (Throwable e) {  
  26.             e.printStackTrace();  
  27.         }  
  28.   
  29.     }  
  30.   
  31.     public native int open(int compression);  
  32.     public native int getFrameSize();  
  33.     public native int decode(byte encoded[], short lin[], int size);  
  34.     public native int encode(short lin[], int offset, byte encoded[], int size);  
  35.     public native void close();  
  36.       
  37. }  

9.打开cygwin工具,切换到项目目录(我项目是在F:\workspace\Audio),输入$NDK/ndk-build

cygwin工具的安装与配置,可以看这篇文章——使用NDK与环境搭建


会在项目中生成libs目录和libspeex.so文件,这就是Speex类中System.loadLibrary("speex");代码引用的,系统会根据操作系统由"speex"找到对应的动态库libspeex.so,Windows下是.dll文件,linux下是.so文件。

当前,我的项目结构如下图



可以从android-recorder下载代码作为参考

0 0
原创粉丝点击