NDK开发入门

本文以在Android APP使用speexdsp中的回音消除为例来说明NDK开发流程;

编译native lib

  1. download speexdsp
  2. 编写cmake

此部分的流程可以参见上一篇blog《CMake交叉编译》

写好Java Class

// EchoCanceller.java
package com.icatchtek.smarthome.echo;

public class EchoCanceller {
    public native int echoInit( int frameSize, int filterLength );
    public native void echoCancellation( byte[] input, byte[] echo, byte[] output );
    public native void echoDestroy();
}

使用javacjavah生成JNI header file

  1. 在以上的java source file目录下使用javac来生成class文件
// -d class -> 指定目录,class文件生成在`class`目录下
javac -d class EchoCanceller.java
  1. 使用javah来生成JNI header file
cd class
javah -classpath . com.icatchtek.smarthome.echo.EchoCanceller

执行上述操作后,在class目录下会生成com_icatchtek_smarthome_echo_EchoCanceller.h

编写对应的JNI实现

有了header file以后,进行对应的功能实现com_icatchtek_smarthome_echo_EchoCanceller.cpp,对JNI编写不熟悉的可以参见《Pro Android C++ with the NDK》

添加JNI file到native lib编译

有了对应的功能实现以后,需要把com_icatchtek_smarthome_echo_EchoCanceller.cpp加入native lib再次编译

编写Java测试程序

进行完上述步骤以后,native & JNI的准备就已经好了;我们把编译好的android lib放入对应架构的APP lib目录下;
然后在刚才的EchoCanceller.java中添加进lib的load,就可以在APP中使用EchoCanceller测试功能了

package com.icatchtek.smarthome.echo;

public class EchoCanceller {
    public native int echoInit( int frameSize, int filterLength );
    public native void echoCancellation( byte[] input, byte[] echo, byte[] output );
    public native void echoDestroy();

    static {
        System.loadLibrary( "speexdsp" );
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值