这是一个开源项目,核心来自webrtc项目。

据网友测试:大多数手机上比较完美,没啥回声,但在小米上比较明显噪音。

将实现各个平台上能快速使用的音频处理库。
核心算法包括: 
NS(Noise Suppression 噪声抑制) 
VAD(Voice Activity Detection 静音检测)
  AECM(Acoustic Echo Canceller for Mobile 声学回声消除)
  AGC(Auto Gain Control 自动增益控制) 现在只有一个Android Demo 。
核心代码如下:

package net.iwebrtc.audioprocess.sdk;import android.util.Log;public class AudioProcess {private static final String TAG = "AudioProcess";static {String[] LIBS = new String[] { "audio_process" };for (int i = 0; i < LIBS.length; i++) {try {System.loadLibrary(LIBS[i]);} catch (UnsatisfiedLinkError e) {Log.e(TAG, "Couldn't load lib: " + LIBS[i] + " - " + e.getMessage());}}}private long nativeAudioProcess;public AudioProcess() {nativeAudioProcess = create();}private native long create();public native boolean init(int sample_rate, int number_bytes_per_sample, int channels);public int calculateBufferSize(int sample_rate, int number_bytes_per_sample, int channels) {return sample_rate * channels * number_bytes_per_sample / 100;}public native boolean processStream10msData(byte[] data, int length, byte[] out);public native boolean AnalyzeReverseStream10msData(byte[] data, int length);public native boolean destroy();}

地址:https://github.com/xiaomo/AudioProcess

演示Demo:http://download.csdn.net/detail/moming_2013/8209547

刚刚开始做,肯定还有不少bug,会不断完善。


音频处理模块(APM)使用翻译:


 The Audio Processing Module (APM) provides a collection of voice processing components designed for real-time communications software. 
音频处理模块(APM)提供了一个音频处理组件的集合,这些组件为实时通讯软件而设计。

APM operates on two audio streams on a frame-by-frame basis.
APM操作两个一帧接一帧的音频流。一个主流,一个逆向流。

Frames of the primary stream, on which all processing is applied, are passed to |ProcessStream()|. 
所有的处理都将被应用到主流的帧  ,这些帧通过ProcessStream函数传递过去。

Frames of the reverse direction stream, which are used for analysis by some components, are passed to |AnalyzeReverseStream()|.
逆向流的帧被一些组件拿去分析,逆向流的帧通过AnalyzeReverseStream函数传递过去。

On the client-side, this will typically be the near-end (capture) and far-end (render) streams, respectively.
在客户端,这是典型的相互独立的近端流和远端流。

APM should be placed in the signal chain as close to the audio hardware abstraction layer (HAL) as possible.
APM在信号链中应该尽快能被放置在接近硬件抽象层的地方。

On the server-side, the reverse stream will normally not be used, with processing occurring on each incoming stream.
在服务端,逆向流通常不被使用。

Component interfaces follow a similar pattern and are accessed through corresponding getters in APM.
组件接口遵循类似的模式设计,通过APM中相应的getter函数访问。

All components are disabled at create-time, with default settings that are recommended for most situations. 
所有的组件在创建时都是不可用的,在大多数情况下,推荐这种默认的设置。

New settings can be applied without enabling a component.
使一个组件可用,新的设置将会被应用到APM。
Enabling a component triggers memory allocation and initialization to allow it to start processing the streams.
使一个组件可用会触发内存分配和初始化,以允许这个组件开始处理音频流。

Thread safety is provided with the following assumptions to reduce locking overhead:
基于下面的假设,提供了线程安全,用以减少锁的开销:
   1. The stream getters and setters are called from the same thread as ProcessStream(). More precisely, stream functions are never called  concurrently with ProcessStream(). 
     在ProcessStream的时候,流的getter和setters方法应该在同一个线程被调用。更确切的说,流的方法绝对不能在ProcessStream的同时被调用。
   2. Parameter getters are never called concurrently with the corresponding setter.
    参数的getter和setter绝不能同时条用。

APM accepts only 16-bit linear PCM audio data in frames of 10 ms. Multiple channels should be interleaved.
APM只接受10 ms帧的16位线性PCM音频数据。多声道应该是交错。


Usage example, omitting error checking:
使用示例,省略了错误检查:
AudioProcessing* apm = AudioProcessing::Create(0);
1 创建一个APM
apm->set_sample_rate_hz(32000); // Super-wideband processing.
2 设置采样率
 // Mono capture and stereo render.
录音单声道,播放多声道。
apm->set_num_channels(1, 1);
3 设置主流处理的输入和输出声道数 
apm->set_num_reverse_channels(2);
4 设置逆向流的声道数

apm->high_pass_filter()->Enable(true);
5 让快速通过过滤组件可用

 apm->echo_cancellation()->enable_drift_compensation(false);
 apm->echo_cancellation()->Enable(true);
6 设置ACE组件

 apm->noise_reduction()->set_level(kHighSuppression);
 apm->noise_reduction()->Enable(true);
7 设置噪音消除组件

 apm->gain_control()->set_analog_level_limits(0, 255);
 apm->gain_control()->set_mode(kAdaptiveAnalog);
 apm->gain_control()->Enable(true);
8 设置自动增益组件

apm->voice_detection()->Enable(true);
9 设置静音检测组件
 // Start a voice call...
 // ... Render frame arrives bound for the audio HAL ... 
apm->AnalyzeReverseStream(render_frame);
10 开始语音通话,让设备播放收到了的帧,把帧通过逆向流传给APM

 // ... Capture frame arrives from the audio HAL ...
 // Call required set_stream_ functions.
 apm->set_stream_delay_ms(delay_ms);
 apm->gain_control()->set_stream_analog_level(analog_level);

 apm->ProcessStream(capture_frame);
11 从设备采集帧,然后必须调用设置流的方法set_stream_delay_ms和set_stream_analog_level,然后处理采集的帧。

 // Call required stream_ functions.
 analog_level = apm->gain_control()->stream_analog_level();
 has_voice = apm->stream_has_voice();
12 然后调动流的方法stream_analog_level和stream_has_voice是有必要的

 // Repeate render and capture processing for the duration of the call...
 // Start a new call...
 apm->Initialize();
13 开始一个新的会话,然后调用Initialize。

 // Close the application...
 delete apm;
14 结束app,删除amp


更多相关文章

  1. Gradle设置代码混淆
  2. 设置android软键盘,默认不弹出的方法
  3. android使用webview加载H5页面
  4. Android设置字母大小写
  5. 玩转Android---组件篇---数据存储之File
  6. Android提高第十篇之AudioRecord实现"助听器"
  7. Android的警示对话框AlertDialog简单使用实例(附Demo)
  8. Android中两种设置全屏或者无标题的方法
  9. Android沉浸式状态栏小结

随机推荐

  1. Android使用FtpServer开启FTP服务端
  2. Android中传递对象的三种方法的实现
  3. 分析Activity的View绑定过程
  4. Android中优雅的退出程序
  5. 【Android】获得系统语言和地区
  6. Android轻松实现多语言的方法示例
  7. Android(安卓)1.5 在eclipse中出现 Inter
  8. Android(安卓)— 使用 SharedPreferences
  9. 【Android】json格式详解
  10. Android——ImageView.ScaleType设置图解