This commit is contained in:
Volker Fischer 2020-04-13 20:19:06 +02:00
parent c8c0b17fc7
commit 21318f993d
2 changed files with 27 additions and 21 deletions

View File

@ -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

View File

@ -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<UInt32> ( iCoreAudioBufferSizeMono * 4 ) )
// check size (float32 has four bytes)
if ( inInputData->mBuffers[0].mDataByteSize ==
static_cast<UInt32> ( iCoreAudioBufferSizeMono * iNumInChan * 4 ) )
{
// One buffer per channel mode
AudioBuffer left = inInputData->mBuffers[iSelInputLeftChannel];
Float32* pLeftData = static_cast<Float32*> ( left.mData );
AudioBuffer right = inInputData->mBuffers[iSelInputRightChannel];
Float32* pRightData = static_cast<Float32*> ( 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<UInt32> ( 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<Float32*> ( 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<UInt32> ( iCoreAudioBufferSizeMono * 4 ) )
{
// one buffer per channel mode:
AudioBuffer left = inInputData->mBuffers[iSelInputLeftChannel];
Float32* pLeftData = static_cast<Float32*> ( left.mData );
AudioBuffer right = inInputData->mBuffers[iSelInputRightChannel];
Float32* pRightData = static_cast<Float32*> ( 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