|
@@ -35,12 +35,7 @@
|
|
|
|
|
|
/* Structure for passing information to callback function */
|
|
/* Structure for passing information to callback function */
|
|
|
|
|
|
-void AudioDriverOpenSL::_buffer_callback(
|
|
|
|
- SLAndroidSimpleBufferQueueItf queueItf
|
|
|
|
- /* SLuint32 eventFlags,
|
|
|
|
- const void * pBuffer,
|
|
|
|
- SLuint32 bufferSize,
|
|
|
|
- SLuint32 dataUsed*/) {
|
|
|
|
|
|
+void AudioDriverOpenSL::_buffer_callback(SLAndroidSimpleBufferQueueItf queueItf) {
|
|
|
|
|
|
bool mix = true;
|
|
bool mix = true;
|
|
|
|
|
|
@@ -74,34 +69,12 @@ void AudioDriverOpenSL::_buffer_callback(
|
|
}
|
|
}
|
|
|
|
|
|
(*queueItf)->Enqueue(queueItf, ptr, 4 * buffer_size);
|
|
(*queueItf)->Enqueue(queueItf, ptr, 4 * buffer_size);
|
|
-
|
|
|
|
-#if 0
|
|
|
|
- SLresult res;
|
|
|
|
- CallbackCntxt *pCntxt = (CallbackCntxt*)pContext;
|
|
|
|
- if(pCntxt->pData < (pCntxt->pDataBase + pCntxt->size))
|
|
|
|
- {
|
|
|
|
- res = (*queueItf)->Enqueue(queueItf, (void*) pCntxt->pData,
|
|
|
|
- 2 * AUDIO_DATA_BUFFER_SIZE, SL_BOOLEAN_FALSE); /* Size given
|
|
|
|
- in bytes. */
|
|
|
|
- CheckErr(res);
|
|
|
|
- /* Increase data pointer by buffer size */
|
|
|
|
- pCntxt->pData += AUDIO_DATA_BUFFER_SIZE;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void AudioDriverOpenSL::_buffer_callbacks(
|
|
|
|
- SLAndroidSimpleBufferQueueItf queueItf,
|
|
|
|
- /*SLuint32 eventFlags,
|
|
|
|
- const void * pBuffer,
|
|
|
|
- SLuint32 bufferSize,
|
|
|
|
- SLuint32 dataUsed,*/
|
|
|
|
- void *pContext) {
|
|
|
|
|
|
+void AudioDriverOpenSL::_buffer_callbacks(SLAndroidSimpleBufferQueueItf queueItf, void *pContext) {
|
|
|
|
|
|
AudioDriverOpenSL *ad = (AudioDriverOpenSL *)pContext;
|
|
AudioDriverOpenSL *ad = (AudioDriverOpenSL *)pContext;
|
|
|
|
|
|
- // ad->_buffer_callback(queueItf,eventFlags,pBuffer,bufferSize,dataUsed);
|
|
|
|
ad->_buffer_callback(queueItf);
|
|
ad->_buffer_callback(queueItf);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -112,65 +85,6 @@ const char *AudioDriverOpenSL::get_name() const {
|
|
return "Android";
|
|
return "Android";
|
|
}
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
|
-int AudioDriverOpenSL::thread_func(SceSize args, void *argp) {
|
|
|
|
-
|
|
|
|
- AudioDriverOpenSL* ad = s_ad;
|
|
|
|
- sceAudioOutput2Reserve(AUDIO_OUTPUT_SAMPLE);
|
|
|
|
-
|
|
|
|
- int half=0;
|
|
|
|
- while(!ad->exit_thread) {
|
|
|
|
-
|
|
|
|
- int16_t *ptr = &ad->outbuff[AUDIO_OUTPUT_SAMPLE*2*half];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if (!ad->active) {
|
|
|
|
-
|
|
|
|
- for(int i=0;i<AUDIO_OUTPUT_SAMPLE*2;i++) {
|
|
|
|
- ptr[i]=0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- //printf("samples: %i\n",AUDIO_OUTPUT_SAMPLE);
|
|
|
|
- ad->lock();
|
|
|
|
-
|
|
|
|
- ad->audio_server_process(AUDIO_OUTPUT_SAMPLE,ad->outbuff_32);
|
|
|
|
-
|
|
|
|
- ad->unlock();
|
|
|
|
-
|
|
|
|
- const int32_t* src_buff=ad->outbuff_32;
|
|
|
|
-
|
|
|
|
- for(int i=0;i<AUDIO_OUTPUT_SAMPLE*2;i++) {
|
|
|
|
-
|
|
|
|
- ptr[i]=src_buff[i]>>16;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /* Output 16-bit PCM STEREO data that is in pcmBuf without changing the volume */
|
|
|
|
- sceAudioOutput2OutputBlocking(
|
|
|
|
- SCE_AUDIO_VOLUME_0dB*3, //0db at 0x8000, that's obvious
|
|
|
|
- ptr
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- if (half)
|
|
|
|
- half=0;
|
|
|
|
- else
|
|
|
|
- half=1;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- sceAudioOutput2Release();
|
|
|
|
-
|
|
|
|
- sceKernelExitThread(SCE_KERNEL_EXIT_SUCCESS);
|
|
|
|
- ad->thread_exited=true;
|
|
|
|
- return SCE_KERNEL_EXIT_SUCCESS;
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#endif
|
|
|
|
Error AudioDriverOpenSL::init() {
|
|
Error AudioDriverOpenSL::init() {
|
|
|
|
|
|
SLresult
|
|
SLresult
|
|
@@ -221,41 +135,24 @@ void AudioDriverOpenSL::start() {
|
|
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[] */
|
|
/* Initialize arrays required[] and iidArray[] */
|
|
SLboolean required[MAX_NUMBER_INTERFACES];
|
|
SLboolean required[MAX_NUMBER_INTERFACES];
|
|
SLInterfaceID iidArray[MAX_NUMBER_INTERFACES];
|
|
SLInterfaceID iidArray[MAX_NUMBER_INTERFACES];
|
|
|
|
|
|
-#if 0
|
|
|
|
-
|
|
|
|
- for (int i=0; i<MAX_NUMBER_INTERFACES; i++)
|
|
|
|
- {
|
|
|
|
- required[i] = SL_BOOLEAN_FALSE;
|
|
|
|
- iidArray[i] = SL_IID_NULL;
|
|
|
|
- }
|
|
|
|
- // Set arrays required[] and iidArray[] for VOLUME interface
|
|
|
|
- required[0] = SL_BOOLEAN_TRUE;
|
|
|
|
- iidArray[0] = SL_IID_VOLUME;
|
|
|
|
-
|
|
|
|
- // Create Output Mix object to be used by player
|
|
|
|
- res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 1,
|
|
|
|
- iidArray, required);
|
|
|
|
-#else
|
|
|
|
-
|
|
|
|
{
|
|
{
|
|
const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
|
|
const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
|
|
const SLboolean req[1] = { SL_BOOLEAN_FALSE };
|
|
const SLboolean req[1] = { SL_BOOLEAN_FALSE };
|
|
res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, ids, req);
|
|
res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, ids, req);
|
|
}
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
|
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
// Realizing the Output Mix object in synchronous mode.
|
|
// Realizing the Output Mix object in synchronous mode.
|
|
res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE);
|
|
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 };
|
|
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 */
|
|
/* Setup the format of the content in the buffer queue */
|
|
pcm.formatType = SL_DATAFORMAT_PCM;
|
|
pcm.formatType = SL_DATAFORMAT_PCM;
|
|
pcm.numChannels = 2;
|
|
pcm.numChannels = 2;
|
|
@@ -276,16 +173,11 @@ void AudioDriverOpenSL::start() {
|
|
locator_outputmix.outputMix = OutputMix;
|
|
locator_outputmix.outputMix = OutputMix;
|
|
audioSink.pLocator = (void *)&locator_outputmix;
|
|
audioSink.pLocator = (void *)&locator_outputmix;
|
|
audioSink.pFormat = NULL;
|
|
audioSink.pFormat = NULL;
|
|
- /* Initialize the context for Buffer queue callbacks */
|
|
|
|
- // cntxt.pDataBase = (void*)&pcmData;
|
|
|
|
- //cntxt.pData = cntxt.pDataBase;
|
|
|
|
- //cntxt.size = sizeof(pcmData);
|
|
|
|
- /* Set arrays required[] and iidArray[] for SEEK interface
|
|
|
|
- (PlayItf is implicit) */
|
|
|
|
|
|
+
|
|
|
|
+ /* Set arrays required[] and iidArray[] for SEEK interface (PlayItf is implicit) */
|
|
required[0] = SL_BOOLEAN_TRUE;
|
|
required[0] = SL_BOOLEAN_TRUE;
|
|
iidArray[0] = SL_IID_BUFFERQUEUE;
|
|
iidArray[0] = SL_IID_BUFFERQUEUE;
|
|
/* Create the music player */
|
|
/* Create the music player */
|
|
-
|
|
|
|
{
|
|
{
|
|
const SLInterfaceID ids[2] = { SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND };
|
|
const SLInterfaceID ids[2] = { SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND };
|
|
const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
|
|
const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
|
|
@@ -305,44 +197,18 @@ void AudioDriverOpenSL::start() {
|
|
/* Setup to receive buffer queue event callbacks */
|
|
/* Setup to receive buffer queue event callbacks */
|
|
res = (*bufferQueueItf)->RegisterCallback(bufferQueueItf, _buffer_callbacks, this);
|
|
res = (*bufferQueueItf)->RegisterCallback(bufferQueueItf, _buffer_callbacks, this);
|
|
ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
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);
|
|
|
|
- ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
|
|
|
- /* Setup the data source structure for the buffer queue */
|
|
|
|
-
|
|
|
|
- res = (*volumeItf)->SetVolumeLevel(volumeItf, -300);
|
|
|
|
- ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
|
|
|
-#endif
|
|
|
|
|
|
+
|
|
last_free = 0;
|
|
last_free = 0;
|
|
-#if 1
|
|
|
|
|
|
+
|
|
//fill up buffers
|
|
//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 */
|
|
/* 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);
|
|
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);
|
|
|
|
- ERR_FAIL_COND( res !=SL_RESULT_SUCCESS );
|
|
|
|
- while(state.count)
|
|
|
|
- {
|
|
|
|
- (*bufferQueueItf)->GetState(bufferQueueItf, &state);
|
|
|
|
- }
|
|
|
|
- /* Make sure player is stopped */
|
|
|
|
- res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED);
|
|
|
|
- CheckErr(res);
|
|
|
|
- /* Destroy the player */
|
|
|
|
- (*player)->Destroy(player);
|
|
|
|
- /* Destroy Output Mix object */
|
|
|
|
- (*OutputMix)->Destroy(OutputMix);
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
active = true;
|
|
active = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -375,19 +241,30 @@ void AudioDriverOpenSL::finish() {
|
|
|
|
|
|
void AudioDriverOpenSL::set_pause(bool p_pause) {
|
|
void AudioDriverOpenSL::set_pause(bool p_pause) {
|
|
|
|
|
|
|
|
+ SLresult res;
|
|
|
|
+ SLuint32 playState;
|
|
|
|
+
|
|
pause = p_pause;
|
|
pause = p_pause;
|
|
|
|
|
|
if (active) {
|
|
if (active) {
|
|
- if (pause) {
|
|
|
|
- (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED);
|
|
|
|
- } else {
|
|
|
|
- (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING);
|
|
|
|
|
|
+ res = (*playItf)->GetPlayState(playItf, &playState);
|
|
|
|
+
|
|
|
|
+ ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
|
|
+
|
|
|
|
+ if (pause && playState == SL_PLAYSTATE_PLAYING) {
|
|
|
|
+ res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED);
|
|
|
|
+
|
|
|
|
+ ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
|
|
+ } else if (!pause && playState == SL_PLAYSTATE_PAUSED) {
|
|
|
|
+ res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING);
|
|
|
|
+
|
|
|
|
+ ERR_FAIL_COND(res != SL_RESULT_SUCCESS);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
AudioDriverOpenSL::AudioDriverOpenSL() {
|
|
AudioDriverOpenSL::AudioDriverOpenSL() {
|
|
s_ad = this;
|
|
s_ad = this;
|
|
- mutex = Mutex::create(); //NULL;
|
|
|
|
|
|
+ mutex = Mutex::create();
|
|
pause = false;
|
|
pause = false;
|
|
}
|
|
}
|