diff --git a/ChangeLog b/ChangeLog index 370eda2d..92676b10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ TODO issue with Mac audio interface: https://sourceforge.net/p/llcon/discussion/ TODO let the user select all possible sound card buffer sizes, this should solve Ticket #53 + TODO auto jitter buffer performance not good at 64 samples frame size -> to be checked again TODO for different frame sizes (64/128) the start value of 6 for the jitter buffer might be too low diff --git a/mac/sound.cpp b/mac/sound.cpp index 18c1edc0..81c95683 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -277,6 +277,9 @@ int CSound::CountChannels ( AudioDeviceID devID, { 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; } } @@ -812,28 +815,11 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice, if ( inDevice == pSound->CurrentAudioInputDeviceID ) { - // we should have a matching number of buffers to channels - if ( inInputData->mNumberBuffers == (UInt32) iNumInChan && - inInputData->mBuffers[0].mDataByteSize == static_cast ( iCoreAudioBufferSizeMono * 4 ) ) + // check size (float32 has four bytes) + if ( inInputData->mBuffers[0].mDataByteSize == + static_cast ( iCoreAudioBufferSizeMono * iNumInChan * 4 ) ) { - // One buffer per channel mode - AudioBuffer left = inInputData->mBuffers[iSelInputLeftChannel]; - Float32* pLeftData = static_cast ( left.mData ); - AudioBuffer right = inInputData->mBuffers[iSelInputRightChannel]; - Float32* pRightData = static_cast ( right.mData ); - - // copy input data - for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ ) - { - // left - pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( pLeftData[i] * _MAXSHORT ); - - // right - pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( pRightData[i] * _MAXSHORT ); - } - } else if ( inInputData->mBuffers[0].mDataByteSize == static_cast ( iCoreAudioBufferSizeMono * iNumInChan * 4 ) ) - { - // One buffer with all the channels in + // one buffer with all the channels in interleaved format: // get a pointer to the input data of the correct type Float32* pInData = static_cast ( inInputData->mBuffers[0].mData ); @@ -864,6 +850,25 @@ if ( iNumInChan == 4 ) } } + else if ( inInputData->mNumberBuffers == (UInt32) iNumInChan && // we should have a matching number of buffers to channels + inInputData->mBuffers[0].mDataByteSize == static_cast ( iCoreAudioBufferSizeMono * 4 ) ) + { + // one buffer per channel mode: + AudioBuffer left = inInputData->mBuffers[iSelInputLeftChannel]; + Float32* pLeftData = static_cast ( left.mData ); + AudioBuffer right = inInputData->mBuffers[iSelInputRightChannel]; + Float32* pRightData = static_cast ( right.mData ); + + // copy input data + for ( int i = 0; i < iCoreAudioBufferSizeMono; i++ ) + { + // left + pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( pLeftData[i] * _MAXSHORT ); + + // right + pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( pRightData[i] * _MAXSHORT ); + } + } else { // incompatible sizes, clear work buffer