some more Coreaudio work (still not working)

This commit is contained in:
Volker Fischer 2010-03-09 20:36:35 +00:00
parent 5b0618e4c6
commit d15cce1c00

View file

@ -76,8 +76,8 @@ void CSound::OpenCoreAudio()
throw CGenErr ( tr ( "CoreAudio creating component instance failed" ) ); throw CGenErr ( tr ( "CoreAudio creating component instance failed" ) );
} }
// TODO // we enable input and disable output
UInt32 enableIO = 0; UInt32 enableIO = 1;
err = AudioUnitSetProperty ( audioUnit, err = AudioUnitSetProperty ( audioUnit,
kAudioOutputUnitProperty_EnableIO, kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input, kAudioUnitScope_Input,
@ -85,7 +85,7 @@ void CSound::OpenCoreAudio()
&enableIO, &enableIO,
sizeof ( enableIO ) ); sizeof ( enableIO ) );
enableIO = 1; enableIO = 0;
err = AudioUnitSetProperty ( audioUnit, err = AudioUnitSetProperty ( audioUnit,
kAudioOutputUnitProperty_EnableIO, kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output, kAudioUnitScope_Output,
@ -93,13 +93,13 @@ void CSound::OpenCoreAudio()
&enableIO, &enableIO,
sizeof ( enableIO ) ); sizeof ( enableIO ) );
// set up a callback function to generate output to the output unit // set up a callback function for new input data
AURenderCallbackStruct input; AURenderCallbackStruct input;
input.inputProc = process; input.inputProc = process;
input.inputProcRefCon = this; input.inputProcRefCon = this;
if ( AudioUnitSetProperty ( audioUnit, if ( AudioUnitSetProperty ( audioUnit,
kAudioUnitProperty_SetRenderCallback, kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global, kAudioUnitScope_Global,
0, 0,
&input, &input,
@ -111,7 +111,7 @@ void CSound::OpenCoreAudio()
// set input device // set input device
size = sizeof ( AudioDeviceID ); size = sizeof ( AudioDeviceID );
AudioDeviceID inputDevice; AudioDeviceID inputDevice;
if ( AudioHardwareGetProperty ( kAudioHardwarePropertyDefaultOutputDevice, if ( AudioHardwareGetProperty ( kAudioHardwarePropertyDefaultInputDevice,
&size, &size,
&inputDevice ) ) &inputDevice ) )
{ {
@ -125,7 +125,7 @@ void CSound::OpenCoreAudio()
&inputDevice, &inputDevice,
sizeof ( inputDevice ) ) ) sizeof ( inputDevice ) ) )
{ {
throw CGenErr ( tr ( "CoreAudio AudioUnitSetProperty call failed" ) ); throw CGenErr ( tr ( "CoreAudio input AudioUnitSetProperty call failed" ) );
} }
// set up stream format // set up stream format
@ -227,9 +227,9 @@ printf("Buffer_Size: %d", (int) bufferSizeFrames);
//malloc buffer lists //malloc buffer lists
theBufferList = (AudioBufferList*) malloc( theBufferList = (AudioBufferList*) malloc(
offsetof(AudioBufferList, mBuffers[0]) + (sizeof(AudioBuffer) * 2)); offsetof(AudioBufferList, mBuffers[0]) + (sizeof(AudioBuffer) * 1));
theBufferList->mNumberBuffers = 2; theBufferList->mNumberBuffers = 1;
//pre-malloc buffers for AudioBufferLists //pre-malloc buffers for AudioBufferLists
for ( UInt32 i = 0; i < theBufferList->mNumberBuffers; i++ ) for ( UInt32 i = 0; i < theBufferList->mNumberBuffers; i++ )
@ -279,6 +279,7 @@ for ( UInt32 channel = 0; channel < theBufferList->mNumberBuffers; channel++)
// get the new audio data // get the new audio data
ComponentResult err =
AudioUnitRender ( pSound->audioUnit, AudioUnitRender ( pSound->audioUnit,
ioActionFlags, ioActionFlags,
inTimeStamp, inTimeStamp,
@ -286,6 +287,14 @@ for ( UInt32 channel = 0; channel < theBufferList->mNumberBuffers; channel++)
inNumberFrames, inNumberFrames,
theBufferList ); theBufferList );
// TEST
for ( int test = 0; test < theBufferList->mBuffers[0].mDataByteSize / 2; test++ )
{
fprintf ( pFile, "%d\n",
static_cast<short*>(theBufferList->mBuffers[0].mData)[test]);
}
fflush ( pFile );
/* /*
// TEST // TEST
@ -325,7 +334,8 @@ fflush ( pFile );
*/ */
// TEST // TEST
printf ( "processing Core Audio %d, inBusNumber: %d\n", (int) inNumberFrames, (int) inBusNumber ); printf ( "buffersize: %d, inBus: %d, ioActionFlags: %d, err: %d\n",
(int) inNumberFrames, (int) inBusNumber, (int) ioActionFlags, (int) err );
/* /*