本文主要记录android端音频使用NDK开发
Android Studio 2.2 提供了CMake 来开发NDK , 只能说更加方便了,没有升级的赶紧去升级吧
相关guides : https://developer.android.com/ndk/guides/audio/index.html
如果Android使用c++还不会的同学转中文api : https://developer.android.com/studio/projects/add-native-code.html#download-ndk
open sl 文档 https://www.khronos.org/registry/sles/specs/OpenSL_ES_Specification_1.0.1.pdf
老外的一篇文章可以参考 https://audioprograming.wordpress.com/2012/03/03/android-audio-streaming-with-opensl-es-and-the-ndk/
google给了两个例子 audio-echo 和 native-audio 先拿例子练手
参考老外的写的测试代码:https://github.com/CL-window/audio_openSL
opensl_io.h 用到的主要的四个函数
分别是 打开/关闭android 音频设备 写入音频数据和读取音频数据
看c 代码之前,关于指针的几个小知识点需要先温习一下下
/** needs know
* -> 是在引用结构体中的变量
* 结构体实例可以通过使用 ‘.’ 符号访问变量。对于结构体实例的指针,我们可以通过 ‘->’ 符号访问变量
* * 当用在声明一个变量时,*表示这里声明了一个指针。其它情况用到*表示指针的取值
* & 地址操作符,用来引用一个内存地址
*/
/*
Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size
in frames. Returns a handle to the OpenSL stream
*/
OPENSL_STREAM* android_OpenAudioDevice(int sr, int inchannels, int outchannels, int bufferframes);
/*
Close the audio device
*/
void android_Close