Android 单独抽取 WebRtc-NS/NSX 模块,封装好JNI层,并且ndk-build出so库。

项目地址:https://github.com/wangzhengcheng1994/android-webrtc-ns
(欢迎star,谢谢)

先看下效果图:

NS前:

Android 单独抽取 WebRtc-NS/NSX(音频降噪) 模块_第1张图片

NS后:

Android 单独抽取 WebRtc-NS/NSX(音频降噪) 模块_第2张图片

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

更多相关文章

  1. Android视音频录制实现步骤(Android学习随笔八)
  2. 【Android】源码分析 - Handler消息机制再梳理
  3. Android中AsyncTask详解,源码剖析(API 23)
  4. Android 5.1.1 源码目录结构
  5. 【幻灯片分享】Android音频口数据通信开发 | 爱图腾 李鹏军 | An
  6. 基于android的远程视频监控系统(已开放源码)
  7. Android 闹钟源码
  8. 编译cubieboard android 源码过程详解之(六):pack
  9. Android中使用Gallery_tabhost来实现标签效果图源码

随机推荐

  1. Android自定义数字键盘解析
  2. ✿Android(安卓)3.1 --- 久违的 USB、mtp
  3. Android(安卓)Studio 出现“Emulator: Pr
  4. Android图形---OpenGL
  5. android studio IDE 下,设置ACTIVITY全屏
  6. qemu: could not open disk image
  7. 为Android2.3添加下拉通知栏的快捷开关
  8. android中对程序进行数字证书签名的方法
  9. Android(安卓)for S3C2440
  10. Android四大组件安全问题