日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenSL ES

發布時間:2025/3/18 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenSL ES 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? OpenSL ES 是無授權費、跨平臺、針對嵌入式系統精心優化的硬件音頻加速API。該庫都允許使用C或C ++來實現高性能,低延遲的音頻操作。
? Android的OpenSL ES庫同樣位于NDK的platforms文件夾內。關于OpenSL ES的使用可以進入ndk-sample查看native-audio工程:https://github.com/googlesamples/android-ndk/blob/master/native-audio/app/src/main/cpp/native-audio-jni.c
OpenSL ES的開發流程主要有如下7個步驟:
? 1、創建接口對象
? 2、設置混音器
? 3、創建播放器
? 4、設置播放回調函數
? 5、設置播放狀態
? 6、啟動回調函數
? 7、釋放
1、創建引擎與接口
SLresult result;
// 創建引擎 SLObjectItf engineObject
result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
if (SL_RESULT_SUCCESS != result) {
return;
}
// 初始化引擎
result = (engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != result) {
return;
}
// 獲取引擎接口SLEngineItf engineInterface
result = (engineObject)->GetInterface(engineObject, SL_IID_ENGINE,
&engineInterface);
if (SL_RESULT_SUCCESS != result) {
return;
}

2、設置混音器
// 創建混音器SLObjectItf outputMixObject
result = (engineInterface)->CreateOutputMix(engineInterface, &outputMixObject, 0,
0, 0);
if (SL_RESULT_SUCCESS != result) {
return;
}
// 初始化混音器outputMixObject
result = (outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != result) {
return;
}

//不啟用混響可以不用獲取接口 // 獲得混音器接口 //result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,// &outputMixEnvironmentalReverb); //if (SL_RESULT_SUCCESS == result) {//設置混響 : 默認。//SL_I3DL2_ENVIRONMENT_PRESET_ROOM: 室內//SL_I3DL2_ENVIRONMENT_PRESET_AUDITORIUM : 禮堂 等//const SLEnvironmentalReverbSettings settings = SL_I3DL2_ENVIRONMENT_PRESET_DEFAULT;//(*outputMixEnvironmentalReverb)->SetEnvironmentalReverbProperties(// outputMixEnvironmentalReverb, &settings); //}

3、創建播放器
/**

  • 配置輸入聲音信息
    */
    //創建buffer緩沖類型的隊列 2個隊列
    SLDataLocator_AndroidSimpleBufferQueue android_queue = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,2};
    //pcm數據格式
    SLDataFormat_PCM pcm = {SL_DATAFORMAT_PCM, 2, SL_SAMPLINGRATE_44_1, SL_PCMSAMPLEFORMAT_FIXED_16,
    SL_PCMSAMPLEFORMAT_FIXED_16,
    SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT,
    SL_BYTEORDER_LITTLEENDIAN};

    //數據源 將上述配置信息放到這個數據源中
    SLDataSource slDataSource = {&android_queue, &pcm};

    //設置混音器
    SLDataLocator_OutputMix outputMix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
    SLDataSink audioSnk = {&outputMix, NULL};
    //需要的接口
    const SLInterfaceID ids[1] = {SL_IID_BUFFERQUEUE};
    const SLboolean req[1] = {SL_BOOLEAN_TRUE};
    //創建播放器
    (engineInterface)->CreateAudioPlayer(engineInterface, &bqPlayerObject, &slDataSource,
    &audioSnk, 1,
    ids, req);
    //初始化播放器
    (bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);

// 得到接口后調用 獲取Player接口
(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerInterface);

4、設置播放回調
//獲取播放器隊列接口
(bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE,
&bqPlayerBufferQueue);
//設置回調
(bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, this);

5、設置播放狀態
// 設置播放狀態
(*bqPlayerInterface)->SetPlayState(bqPlayerInterface, SL_PLAYSTATE_PLAYING);

6、啟動回調函數
bqPlayerCallback(bqPlayerBufferQueue, this);

7、釋放
//設置停止狀態
if (bqPlayerInterface) {
(bqPlayerInterface)->SetPlayState(bqPlayerInterface, SL_PLAYSTATE_STOPPED);
bqPlayerInterface = 0;
}
//銷毀播放器
if (bqPlayerObject) {
(bqPlayerObject)->Destroy(bqPlayerObject);
bqPlayerObject = 0;
bqPlayerBufferQueue = 0;
}
//銷毀混音器
if (outputMixObject) {
(outputMixObject)->Destroy(outputMixObject);
outputMixObject = 0;
}
//銷毀引擎
if (engineObject) {
(engineObject)->Destroy(engineObject);
engineObject = 0;
engineInterface = 0;
}

轉載于:https://blog.51cto.com/14138284/2333670

總結

以上是生活随笔為你收集整理的OpenSL ES的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。