next try to fix the Mac audio interface issue

This commit is contained in:
Volker Fischer 2020-04-15 16:11:01 +02:00
parent e4752f4d96
commit 9f7877af88
2 changed files with 46 additions and 27 deletions

View file

@ -255,35 +255,47 @@ void CSound::GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
} }
int CSound::CountChannels ( AudioDeviceID devID, int CSound::CountChannels ( AudioDeviceID devID,
const int iNumChanPerFrame,
bool isInput ) bool isInput )
{ {
OSStatus err; OSStatus err;
UInt32 propSize; UInt32 propSize;
int result = 0; int result = 0;
AudioObjectPropertyScope theScope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; // check for the case the we have interleaved format, in that case we assume
// that only the very first buffer contains all our channels
AudioObjectPropertyAddress theAddress = { kAudioDevicePropertyStreamConfiguration, if ( iNumChanPerFrame > 1 )
theScope,
0 };
AudioObjectGetPropertyDataSize ( devID, &theAddress, 0, NULL, &propSize );
AudioBufferList *buflist = (AudioBufferList*) malloc ( propSize );
err = AudioObjectGetPropertyData ( devID, &theAddress, 0, NULL, &propSize, buflist );
if ( !err )
{ {
for ( UInt32 i = 0; i < buflist->mNumberBuffers; ++i ) result = iNumChanPerFrame;
{ }
// The correct value mNumberChannels for an AudioBuffer can be derived from the mChannelsPerFrame else
// and the interleaved flag. For non interleaved formats, mNumberChannels is always 1. {
// For interleaved formats, mNumberChannels is equal to mChannelsPerFrame. // it seems we have multiple buffers where each buffer has only one channel,
result += buflist->mBuffers[i].mNumberChannels; // in that case we assume that each input channel has its own buffer
} AudioObjectPropertyScope theScope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
AudioObjectPropertyAddress theAddress = { kAudioDevicePropertyStreamConfiguration,
theScope,
0 };
AudioObjectGetPropertyDataSize ( devID, &theAddress, 0, NULL, &propSize );
AudioBufferList *buflist = (AudioBufferList*) malloc ( propSize );
err = AudioObjectGetPropertyData ( devID, &theAddress, 0, NULL, &propSize, buflist );
if ( !err )
{
for ( UInt32 i = 0; i < buflist->mNumberBuffers; ++i )
{
// The correct value mNumberChannels for an AudioBuffer can be derived from the mChannelsPerFrame
// and the interleaved flag. For non interleaved formats, mNumberChannels is always 1.
// For interleaved formats, mNumberChannels is equal to mChannelsPerFrame.
result += buflist->mBuffers[i].mNumberChannels;
}
}
free ( buflist );
} }
free ( buflist );
return result; return result;
} }
@ -449,6 +461,9 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
"not compatible with this software." ); "not compatible with this software." );
} }
// store the input number of channels per frame for this stream
const int iNumInChanPerFrame = CurDevStreamFormat.mChannelsPerFrame;
// check the output // check the output
AudioObjectGetPropertyData ( outputStreamID, AudioObjectGetPropertyData ( outputStreamID,
&stPropertyAddress, &stPropertyAddress,
@ -467,9 +482,12 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
"not compatible with this software." ); "not compatible with this software." );
} }
// store the output number of channels per frame for this stream
const int iNumOutChanPerFrame = CurDevStreamFormat.mChannelsPerFrame;
// store the input and out number of channels for this device // store the input and out number of channels for this device
iNumInChan = CountChannels ( audioInputDevice[iDriverIdx], true ); iNumInChan = CountChannels ( audioInputDevice[iDriverIdx], iNumInChanPerFrame, true );
iNumOutChan = CountChannels ( audioOutputDevice[iDriverIdx], false ); iNumOutChan = CountChannels ( audioOutputDevice[iDriverIdx], iNumOutChanPerFrame, false );
// clip the number of input/output channels to our allowed maximum // clip the number of input/output channels to our allowed maximum
if ( iNumInChan > MAX_NUM_IN_OUT_CHANNELS ) if ( iNumInChan > MAX_NUM_IN_OUT_CHANNELS )
@ -813,7 +831,7 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
const int iSelOutputLeftChannel = pSound->iSelOutputLeftChannel; const int iSelOutputLeftChannel = pSound->iSelOutputLeftChannel;
const int iSelOutputRightChannel = pSound->iSelOutputRightChannel; const int iSelOutputRightChannel = pSound->iSelOutputRightChannel;
if ( inDevice == pSound->CurrentAudioInputDeviceID ) if ( ( inDevice == pSound->CurrentAudioInputDeviceID ) && inInputData )
{ {
// check size (float32 has four bytes) // check size (float32 has four bytes)
if ( inInputData->mBuffers[0].mDataByteSize == if ( inInputData->mBuffers[0].mDataByteSize ==
@ -879,7 +897,7 @@ if ( iNumInChan == 4 )
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo ); pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
} }
if ( inDevice == pSound->CurrentAudioOutputDeviceID ) if ( ( inDevice == pSound->CurrentAudioOutputDeviceID ) && outOutputData )
{ {
// check size (float32 has four bytes) // check size (float32 has four bytes)
if ( outOutputData->mBuffers[0].mDataByteSize == if ( outOutputData->mBuffers[0].mDataByteSize ==

View file

@ -78,8 +78,9 @@ protected:
virtual QString LoadAndInitializeDriver ( int iIdx ); virtual QString LoadAndInitializeDriver ( int iIdx );
QString CheckDeviceCapabilities ( const int iDriverIdx ); QString CheckDeviceCapabilities ( const int iDriverIdx );
OSStatus CountChannels ( AudioDeviceID devID, int CountChannels ( AudioDeviceID devID,
bool isInput ); const int iNumChanPerFrame,
bool isInput );
UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID, UInt32 SetBufferSize ( AudioDeviceID& audioDeviceID,
const bool bIsInput, const bool bIsInput,