You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
@@ -29,57 +29,50 @@
|
||||
#include "audio_driver_opensl.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MAX_NUMBER_INTERFACES 3
|
||||
#define MAX_NUMBER_OUTPUT_DEVICES 6
|
||||
|
||||
/* Structure for passing information to callback function */
|
||||
|
||||
|
||||
void AudioDriverOpenSL::_buffer_callback(
|
||||
SLAndroidSimpleBufferQueueItf queueItf
|
||||
/* SLuint32 eventFlags,
|
||||
SLAndroidSimpleBufferQueueItf queueItf
|
||||
/* SLuint32 eventFlags,
|
||||
const void * pBuffer,
|
||||
SLuint32 bufferSize,
|
||||
SLuint32 dataUsed*/) {
|
||||
|
||||
bool mix=true;
|
||||
bool mix = true;
|
||||
|
||||
if (pause) {
|
||||
mix=false;
|
||||
mix = false;
|
||||
} else if (mutex) {
|
||||
mix = mutex->try_lock()==OK;
|
||||
mix = mutex->try_lock() == OK;
|
||||
}
|
||||
|
||||
if (mix) {
|
||||
audio_server_process(buffer_size,mixdown_buffer);
|
||||
audio_server_process(buffer_size, mixdown_buffer);
|
||||
} else {
|
||||
|
||||
int32_t* src_buff=mixdown_buffer;
|
||||
for(int i=0;i<buffer_size*2;i++) {
|
||||
src_buff[i]=0;
|
||||
int32_t *src_buff = mixdown_buffer;
|
||||
for (int i = 0; i < buffer_size * 2; i++) {
|
||||
src_buff[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mutex && mix)
|
||||
mutex->unlock();
|
||||
|
||||
const int32_t *src_buff = mixdown_buffer;
|
||||
|
||||
const int32_t* src_buff=mixdown_buffer;
|
||||
int16_t *ptr = (int16_t *)buffers[last_free];
|
||||
last_free = (last_free + 1) % BUFFER_COUNT;
|
||||
|
||||
int16_t *ptr = (int16_t*)buffers[last_free];
|
||||
last_free=(last_free+1)%BUFFER_COUNT;
|
||||
for (int i = 0; i < buffer_size * 2; i++) {
|
||||
|
||||
for(int i=0;i<buffer_size*2;i++) {
|
||||
|
||||
ptr[i]=src_buff[i]>>16;
|
||||
ptr[i] = src_buff[i] >> 16;
|
||||
}
|
||||
|
||||
(*queueItf)->Enqueue(queueItf, ptr, 4 * buffer_size);
|
||||
|
||||
(*queueItf)->Enqueue(queueItf, ptr, 4 * buffer_size);
|
||||
|
||||
#if 0
|
||||
SLresult res;
|
||||
@@ -98,25 +91,22 @@ void AudioDriverOpenSL::_buffer_callback(
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::_buffer_callbacks(
|
||||
SLAndroidSimpleBufferQueueItf queueItf,
|
||||
/*SLuint32 eventFlags,
|
||||
SLAndroidSimpleBufferQueueItf queueItf,
|
||||
/*SLuint32 eventFlags,
|
||||
const void * pBuffer,
|
||||
SLuint32 bufferSize,
|
||||
SLuint32 dataUsed,*/
|
||||
void *pContext) {
|
||||
void *pContext) {
|
||||
|
||||
AudioDriverOpenSL *ad = (AudioDriverOpenSL *)pContext;
|
||||
|
||||
AudioDriverOpenSL *ad = (AudioDriverOpenSL*)pContext;
|
||||
|
||||
// ad->_buffer_callback(queueItf,eventFlags,pBuffer,bufferSize,dataUsed);
|
||||
// ad->_buffer_callback(queueItf,eventFlags,pBuffer,bufferSize,dataUsed);
|
||||
ad->_buffer_callback(queueItf);
|
||||
|
||||
}
|
||||
|
||||
AudioDriverOpenSL *AudioDriverOpenSL::s_ad = NULL;
|
||||
|
||||
AudioDriverOpenSL* AudioDriverOpenSL::s_ad=NULL;
|
||||
|
||||
const char* AudioDriverOpenSL::get_name() const {
|
||||
const char *AudioDriverOpenSL::get_name() const {
|
||||
|
||||
return "Android";
|
||||
}
|
||||
@@ -180,23 +170,23 @@ int AudioDriverOpenSL::thread_func(SceSize args, void *argp) {
|
||||
}
|
||||
|
||||
#endif
|
||||
Error AudioDriverOpenSL::init(){
|
||||
Error AudioDriverOpenSL::init() {
|
||||
|
||||
SLresult
|
||||
res;
|
||||
res;
|
||||
SLEngineOption EngineOption[] = {
|
||||
(SLuint32) SL_ENGINEOPTION_THREADSAFE,
|
||||
(SLuint32) SL_BOOLEAN_TRUE
|
||||
(SLuint32)SL_ENGINEOPTION_THREADSAFE,
|
||||
(SLuint32)SL_BOOLEAN_TRUE
|
||||
|
||||
};
|
||||
res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL);
|
||||
if (res!=SL_RESULT_SUCCESS) {
|
||||
res = slCreateEngine(&sl, 1, EngineOption, 0, NULL, NULL);
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
|
||||
ERR_EXPLAIN("Could not Initialize OpenSL");
|
||||
ERR_FAIL_V(ERR_INVALID_PARAMETER);
|
||||
}
|
||||
res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE);
|
||||
if (res!=SL_RESULT_SUCCESS) {
|
||||
if (res != SL_RESULT_SUCCESS) {
|
||||
|
||||
ERR_EXPLAIN("Could not Realize OpenSL");
|
||||
ERR_FAIL_V(ERR_INVALID_PARAMETER);
|
||||
@@ -205,37 +195,33 @@ Error AudioDriverOpenSL::init(){
|
||||
print_line("OpenSL Init OK!");
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::start(){
|
||||
|
||||
void AudioDriverOpenSL::start() {
|
||||
|
||||
mutex = Mutex::create();
|
||||
active=false;
|
||||
|
||||
active = false;
|
||||
|
||||
SLint32 numOutputs = 0;
|
||||
SLuint32 deviceID = 0;
|
||||
SLresult res;
|
||||
|
||||
|
||||
buffer_size = 1024;
|
||||
|
||||
for(int i=0;i<BUFFER_COUNT;i++) {
|
||||
for (int i = 0; i < BUFFER_COUNT; i++) {
|
||||
|
||||
buffers[i]=memnew_arr( int16_t,buffer_size*2 );
|
||||
memset(buffers[i],0,buffer_size*4);
|
||||
buffers[i] = memnew_arr(int16_t, buffer_size * 2);
|
||||
memset(buffers[i], 0, buffer_size * 4);
|
||||
}
|
||||
|
||||
mixdown_buffer = memnew_arr( int32_t,buffer_size* 2);
|
||||
mixdown_buffer = memnew_arr(int32_t, buffer_size * 2);
|
||||
|
||||
/* Callback context for the buffer queue callback function */
|
||||
|
||||
/* Get the SL Engine Interface which is implicit */
|
||||
res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf);
|
||||
res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void *)&EngineItf);
|
||||
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
/* Initialize arrays required[] and iidArray[] */
|
||||
SLboolean required[MAX_NUMBER_INTERFACES];
|
||||
SLInterfaceID iidArray[MAX_NUMBER_INTERFACES];
|
||||
@@ -257,22 +243,20 @@ void AudioDriverOpenSL::start(){
|
||||
#else
|
||||
|
||||
{
|
||||
const SLInterfaceID ids[1] = {SL_IID_ENVIRONMENTALREVERB};
|
||||
const SLboolean req[1] = {SL_BOOLEAN_FALSE};
|
||||
res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0,
|
||||
ids, req);
|
||||
const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
|
||||
const SLboolean req[1] = { SL_BOOLEAN_FALSE };
|
||||
res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, ids, req);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
// Realizing the Output Mix object in synchronous mode.
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
// Realizing the Output Mix object in synchronous mode.
|
||||
res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, BUFFER_COUNT};
|
||||
// bufferQueue.locatorType = SL_DATALOCATOR_BUFFERQUEUE;
|
||||
// bufferQueue.numBuffers = BUFFER_COUNT; /* Four buffers in our buffer queue */
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, BUFFER_COUNT };
|
||||
// bufferQueue.locatorType = SL_DATALOCATOR_BUFFERQUEUE;
|
||||
// bufferQueue.numBuffers = BUFFER_COUNT; /* Four buffers in our buffer queue */
|
||||
/* Setup the format of the content in the buffer queue */
|
||||
pcm.formatType = SL_DATAFORMAT_PCM;
|
||||
pcm.numChannels = 2;
|
||||
@@ -288,14 +272,13 @@ void AudioDriverOpenSL::start(){
|
||||
audioSource.pFormat = (void *)&pcm;
|
||||
audioSource.pLocator = (void *)&loc_bufq;
|
||||
|
||||
|
||||
/* Setup the data sink structure */
|
||||
locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
|
||||
locator_outputmix.outputMix= OutputMix;
|
||||
locator_outputmix.outputMix = OutputMix;
|
||||
audioSink.pLocator = (void *)&locator_outputmix;
|
||||
audioSink.pFormat = NULL;
|
||||
/* Initialize the context for Buffer queue callbacks */
|
||||
// cntxt.pDataBase = (void*)&pcmData;
|
||||
// cntxt.pDataBase = (void*)&pcmData;
|
||||
//cntxt.pData = cntxt.pDataBase;
|
||||
//cntxt.size = sizeof(pcmData);
|
||||
/* Set arrays required[] and iidArray[] for SEEK interface
|
||||
@@ -305,27 +288,25 @@ void AudioDriverOpenSL::start(){
|
||||
/* Create the music player */
|
||||
|
||||
{
|
||||
const SLInterfaceID ids[2] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND};
|
||||
const SLboolean req[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
||||
const SLInterfaceID ids[2] = { SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND };
|
||||
const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
|
||||
|
||||
res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player,
|
||||
&audioSource, &audioSink, 1, ids, req);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 1, ids, req);
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
}
|
||||
/* Realizing the player in synchronous mode. */
|
||||
res = (*player)->Realize(player, SL_BOOLEAN_FALSE);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
/* Get seek and play interfaces */
|
||||
res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
res = (*player)->GetInterface(player, SL_IID_PLAY, (void *)&playItf);
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
res = (*player)->GetInterface(player, SL_IID_BUFFERQUEUE,
|
||||
(void*)&bufferQueueItf);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
(void *)&bufferQueueItf);
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
/* Setup to receive buffer queue event callbacks */
|
||||
res = (*bufferQueueItf)->RegisterCallback(bufferQueueItf,
|
||||
_buffer_callbacks, this);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
/* Before we start set volume to -3dB (-300mB) */
|
||||
res = (*bufferQueueItf)->RegisterCallback(bufferQueueItf, _buffer_callbacks, this);
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
/* Before we start set volume to -3dB (-300mB) */
|
||||
#if 0
|
||||
res = (*OutputMix)->GetInterface(OutputMix, SL_IID_VOLUME,
|
||||
(void*)&volumeItf);
|
||||
@@ -335,19 +316,17 @@ void AudioDriverOpenSL::start(){
|
||||
res = (*volumeItf)->SetVolumeLevel(volumeItf, -300);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
#endif
|
||||
last_free=0;
|
||||
last_free = 0;
|
||||
#if 1
|
||||
//fill up buffers
|
||||
for(int i=0;i<BUFFER_COUNT;i++) {
|
||||
for (int i = 0; i < BUFFER_COUNT; i++) {
|
||||
/* Enqueue a few buffers to get the ball rolling */
|
||||
res = (*bufferQueueItf)->Enqueue(bufferQueueItf, buffers[i],
|
||||
4 * buffer_size); /* Size given in */
|
||||
|
||||
res = (*bufferQueueItf)->Enqueue(bufferQueueItf, buffers[i], 4 * buffer_size); /* Size given in */
|
||||
}
|
||||
#endif
|
||||
|
||||
res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING);
|
||||
ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
||||
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
||||
|
||||
#if 0
|
||||
res = (*bufferQueueItf)->GetState(bufferQueueItf, &state);
|
||||
@@ -365,7 +344,7 @@ void AudioDriverOpenSL::start(){
|
||||
(*OutputMix)->Destroy(OutputMix);
|
||||
#endif
|
||||
|
||||
active=true;
|
||||
active = true;
|
||||
}
|
||||
|
||||
int AudioDriverOpenSL::get_mix_rate() const {
|
||||
@@ -373,34 +352,31 @@ int AudioDriverOpenSL::get_mix_rate() const {
|
||||
return 44100;
|
||||
}
|
||||
|
||||
AudioDriverSW::OutputFormat AudioDriverOpenSL::get_output_format() const{
|
||||
AudioDriverSW::OutputFormat AudioDriverOpenSL::get_output_format() const {
|
||||
|
||||
return OUTPUT_STEREO;
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::lock(){
|
||||
void AudioDriverOpenSL::lock() {
|
||||
|
||||
if (active && mutex)
|
||||
mutex->lock();
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::unlock() {
|
||||
|
||||
if (active && mutex)
|
||||
mutex->unlock();
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::finish(){
|
||||
void AudioDriverOpenSL::finish() {
|
||||
|
||||
(*sl)->Destroy(sl);
|
||||
|
||||
}
|
||||
|
||||
void AudioDriverOpenSL::set_pause(bool p_pause) {
|
||||
|
||||
pause=p_pause;
|
||||
pause = p_pause;
|
||||
|
||||
if (active) {
|
||||
if (pause) {
|
||||
@@ -411,13 +387,8 @@ void AudioDriverOpenSL::set_pause(bool p_pause) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AudioDriverOpenSL::AudioDriverOpenSL()
|
||||
{
|
||||
s_ad=this;
|
||||
mutex=Mutex::create();//NULL;
|
||||
pause=false;
|
||||
AudioDriverOpenSL::AudioDriverOpenSL() {
|
||||
s_ad = this;
|
||||
mutex = Mutex::create(); //NULL;
|
||||
pause = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user