even more Android code, still not working...

This commit is contained in:
Volker Fischer 2013-12-29 12:40:23 +00:00
parent ee4fedc689
commit 3343ea0a77
2 changed files with 90 additions and 51 deletions

View file

@ -63,29 +63,81 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* ar
nullptr, nullptr,
nullptr ); nullptr );
// realize the output mix
(*outputMixObject)->Realize ( outputMixObject, (*outputMixObject)->Realize ( outputMixObject,
SL_BOOLEAN_FALSE ); SL_BOOLEAN_FALSE );
// configure the output buffer queue. // configure the audio (data) source for input
SLDataLocator_IODevice micLocator;
micLocator.locatorType = SL_DATALOCATOR_IODEVICE;
micLocator.deviceType = SL_IODEVICE_AUDIOINPUT;
micLocator.deviceID = SL_DEFAULTDEVICEID_AUDIOINPUT;
micLocator.device = nullptr;
SLDataSource inDataSource;
inDataSource.pLocator = &micLocator;
inDataSource.pFormat = nullptr;
// configure the input buffer queue
SLDataLocator_AndroidSimpleBufferQueue inBufferQueue;
inBufferQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
inBufferQueue.numBuffers = 1; // max number of buffers in queue
// configure the audio (data) sink for input
SLDataSink inDataSink;
inDataSink.pLocator = &inBufferQueue;
inDataSink.pFormat = &streamFormat;
// create the audio recorder
const SLInterfaceID recorderIds[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
const SLboolean recorderReq[] = { SL_BOOLEAN_TRUE };
(*engine)->CreateAudioRecorder ( engine,
&recorderObject,
&inDataSource,
&inDataSink,
1,
recorderIds,
recorderReq );
// realize the audio recorder
(*recorderObject)->Realize ( recorderObject,
SL_BOOLEAN_FALSE );
// get the audio recorder interface
(*recorderObject)->GetInterface ( recorderObject,
SL_IID_RECORD,
&recorder );
// get the audio recorder simple buffer queue interface
(*recorderObject)->GetInterface ( recorderObject,
SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
&recorderSimpleBufQueue );
// register the audio input callback
(*recorderSimpleBufQueue)->RegisterCallback ( recorderSimpleBufQueue,
processInput,
this );
// configure the output buffer queue
SLDataLocator_AndroidSimpleBufferQueue outBufferQueue; SLDataLocator_AndroidSimpleBufferQueue outBufferQueue;
outBufferQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; outBufferQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
outBufferQueue.numBuffers = 1; // max number of buffers in queue outBufferQueue.numBuffers = 1; // max number of buffers in queue
// configure the audio (data) source // configure the audio (data) source for output
SLDataSource dataSource; SLDataSource outDataSource;
dataSource.pLocator = &outBufferQueue; outDataSource.pLocator = &outBufferQueue;
dataSource.pFormat = &streamFormat; outDataSource.pFormat = &streamFormat;
// configure the output mix // configure the output mix
SLDataLocator_OutputMix outputMix; SLDataLocator_OutputMix outputMix;
outputMix.locatorType = SL_DATALOCATOR_OUTPUTMIX; outputMix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
outputMix.outputMix = outputMixObject; outputMix.outputMix = outputMixObject;
// configure the audio (data) sink // configure the audio (data) sink for output
SLDataSink dataSink; SLDataSink outDataSink;
dataSink.pLocator = &outputMix; outDataSink.pLocator = &outputMix;
dataSink.pFormat = nullptr; outDataSink.pFormat = nullptr;
// create the audio player // create the audio player
const SLInterfaceID playerIds[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE }; const SLInterfaceID playerIds[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
@ -93,8 +145,8 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* ar
(*engine)->CreateAudioPlayer ( engine, (*engine)->CreateAudioPlayer ( engine,
&playerObject, &playerObject,
&dataSource, &outDataSource,
&dataSink, &outDataSink,
1, 1,
playerIds, playerIds,
playerReq ); playerReq );
@ -122,6 +174,7 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* ar
void CSound::CloseOpenSL() void CSound::CloseOpenSL()
{ {
// clean up // clean up
(*recorderObject)->Destroy ( recorderObject );
(*playerObject)->Destroy ( playerObject ); (*playerObject)->Destroy ( playerObject );
(*outputMixObject)->Destroy ( outputMixObject ); (*outputMixObject)->Destroy ( outputMixObject );
(*engineObject)->Destroy ( engineObject ); (*engineObject)->Destroy ( engineObject );
@ -224,41 +277,30 @@ int iActualMonoBufferSize = iNewPrefMonoBufferSize;
return iOpenSLBufferSizeMono; return iOpenSLBufferSizeMono;
} }
/* void CSound::processInput ( SLAndroidSimpleBufferQueueItf bufferQueue,
OSStatus CSound::processInput ( void* inRefCon, void* instance )
AudioUnitRenderActionFlags* ioActionFlags,
const AudioTimeStamp* inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList* )
{
CSound* pSound = reinterpret_cast<CSound*> ( inRefCon );
QMutexLocker locker ( &pSound->Mutex );
// get the new audio data
AudioUnitRender ( pSound->audioInputUnit,
ioActionFlags,
inTimeStamp,
inBusNumber,
inNumberFrames,
pSound->pBufferList );
// call processing callback function
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
return noErr;
}
*/
void CSound::processOutput ( SLAndroidSimpleBufferQueueItf bufferQueue,
void* instance)
{ {
CSound* pSound = reinterpret_cast<CSound*> ( instance ); CSound* pSound = reinterpret_cast<CSound*> ( instance );
QMutexLocker locker ( &pSound->Mutex ); QMutexLocker locker ( &pSound->Mutex );
// enqueue the buffer for playback. // enqueue the buffer for record
(*bufferQueue)->Enqueue ( bufferQueue,
&pSound->vecsTmpAudioSndCrdStereo[0],
pSound->iOpenSLBufferSizeStero );
// call processing callback function
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
}
void CSound::processOutput ( SLAndroidSimpleBufferQueueItf bufferQueue,
void* instance )
{
CSound* pSound = reinterpret_cast<CSound*> ( instance );
QMutexLocker locker ( &pSound->Mutex );
// enqueue the buffer for playback
(*bufferQueue)->Enqueue ( bufferQueue, (*bufferQueue)->Enqueue ( bufferQueue,
&pSound->vecsTmpAudioSndCrdStereo[0], &pSound->vecsTmpAudioSndCrdStereo[0],
pSound->iOpenSLBufferSizeStero ); pSound->iOpenSLBufferSizeStero );

View file

@ -53,21 +53,18 @@ protected:
void CloseOpenSL(); void CloseOpenSL();
/*
// callbacks // callbacks
static OSStatus processInput ( void* inRefCon, static void processInput ( SLAndroidSimpleBufferQueueItf bufferQueue,
AudioUnitRenderActionFlags* ioActionFlags, void* instance );
const AudioTimeStamp* inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList* );
*/
static void processOutput ( SLAndroidSimpleBufferQueueItf bufferQueue, static void processOutput ( SLAndroidSimpleBufferQueueItf bufferQueue,
void* instance); void* instance );
SLObjectItf engineObject; SLObjectItf engineObject;
SLEngineItf engine; SLEngineItf engine;
SLObjectItf recorderObject;
SLRecordItf recorder;
SLAndroidSimpleBufferQueueItf recorderSimpleBufQueue;
SLObjectItf outputMixObject; SLObjectItf outputMixObject;
SLObjectItf playerObject; SLObjectItf playerObject;
SLPlayItf player; SLPlayItf player;