Android 单独抽取 WebRtc-NS/NSX(音频降噪) 模块
16lz
2021-01-23
Android 单独抽取 WebRtc-NS/NSX 模块,封装好JNI层,并且ndk-build出so库。
项目地址:https://github.com/wangzhengcheng1994/android-webrtc-ns
(欢迎star,谢谢)
先看下效果图:
NS前:
NS后:
Android层调用(部分代码):
try{ NsUtils nsUtils = new NsUtils(); int createStatus = nsUtils.nsCreate(); int initStatus = nsUtils.nsInit(createStatus,8000); int setStatus = nsUtils.nsSetPolicy(createStatus,2); Log.e(TAG,"createStatus = " + createStatus + "initStatus = " + initStatus + "setStatus = " + setStatus); FileInputStream fInt = new FileInputStream(INPUT_FILE_PATH); FileOutputStream fOut = new FileOutputStream(OUT_FILE_PATH); byte[] buffer = new byte[160]; int bytes ; while(fInt.read(buffer) != -1){ short[] inputData = new short[80]; short[] outData = new short[80]; ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(inputData); int ret = nsUtils.nsProcess(createStatus,inputData,null,outData,null); Log.e(TAG,"ret = " + ret); fOut.write(shortArrayToByteArry(outData)); } fInt.close(); fOut.close(); }catch (Exception e){ e.printStackTrace(); }
nsUtils是native方法的一个封装类,核心方法nsProcess(int nsHandler,short[] sample,short[] sample_H,short[] outData, short[] outData_H),源码中头文件说明如下:
/* * This functions does Noise Suppression for the inserted speech frame. The * input and output signals should always be 10ms (80 or 160 samples). * * Input * - NS_inst : Noise suppression instance. * - spframe : Pointer to speech frame buffer for L band * - spframe_H : Pointer to speech frame buffer for H band * - fs : sampling frequency * * Output: * - NS_inst : Updated NS instance * - outframe : Pointer to output frame for L band * - outframe_H : Pointer to output frame for H band * * Return value : 0 - OK * -1 - Error */int WebRtcNs_Process(NsHandle* NS_inst, short* spframe, short* spframe_H, short* outframe, short* outframe_H);
WebRtc源码中的NS模块位于 src\modules\audio_processing\ns,其中包含NS和NSX,这两种前者是定点数运算,后者是浮点数运算,从处理结果来看,好像没什么区别,没有深究。
WebRtc的NS模块还是比较简单的,希望对大家有所帮助。有需要看JNI层实现和完整demo的,请加我V:15092216090
原创:VampireHunter
更多相关文章
- Android视音频录制实现步骤(Android学习随笔八)
- 【Android】源码分析 - Handler消息机制再梳理
- Android中AsyncTask详解,源码剖析(API 23)
- Android 5.1.1 源码目录结构
- 【幻灯片分享】Android音频口数据通信开发 | 爱图腾 李鹏军 | An
- 基于android的远程视频监控系统(已开放源码)
- Android 闹钟源码
- 编译cubieboard android 源码过程详解之(六):pack
- Android中使用Gallery_tabhost来实现标签效果图源码