From c0671036846854988e69756e147452cc7dee1e07 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 24 Jul 2008 18:15:48 +0000 Subject: [PATCH] bug fix, support for 24/32 bit for ASIO interface --- src/settings.cpp | 6 ++++ windows/sound.cpp | 91 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 5bdf8a4b..5b9c31f3 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -101,6 +101,12 @@ void CSettings::ReadIniFile ( const QString& sFileName ) pClient->SetNetwBufSizeFactIn ( iValue ); } + // network buffer size factor out + if ( GetNumericIniSet ( IniXMLDocument, "client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) ) + { + pClient->SetNetwBufSizeFactOut ( iValue ); + } + // flag whether the chat window shall be opened on a new chat message if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) ) { diff --git a/windows/sound.cpp b/windows/sound.cpp index f392594a..2ebcb663 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -356,9 +356,11 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize ) ASIOGetChannelInfo ( &channelInfos[i] ); // only 16 bit is supported - if ( channelInfos[i].type != ASIOSTInt16LSB ) + if ( ( channelInfos[i].type != ASIOSTInt16LSB ) && + ( channelInfos[i].type != ASIOSTInt24LSB ) && + ( channelInfos[i].type != ASIOSTInt32LSB ) ) { - throw CGenErr ( "Required audio sample format not available (16 bit LSB)." ); + throw CGenErr ( "Required audio sample format not available (16/24/32 bit LSB)." ); } } @@ -593,13 +595,44 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow ) // first check if space in buffer is available if ( !bCaptureBufferOverrun ) { - // copy new captured block in thread transfer buffer - for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) - { - // copy mono data interleaved in stereo buffer - psCaptureBuffer[iBufferPosCapture + - 2 * iCurSample + bufferInfos[i].channelNum] = - ((short*) bufferInfos[i].buffers[index])[iCurSample]; + // copy new captured block in thread transfer buffer (copy + // mono data interleaved in stereo buffer) + switch ( channelInfos[i].type ) + { + case ASIOSTInt16LSB: + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + psCaptureBuffer[iBufferPosCapture + + 2 * iCurSample + bufferInfos[i].channelNum] = + ((short*) bufferInfos[i].buffers[index])[iCurSample]; + } + break; + + case ASIOSTInt24LSB: + +// not yet tested, horrible things might happen with the following code ;-) + + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + // convert current sample in 16 bit format + int iCurSam = 0; + memcpy ( &iCurSam, ((char*) bufferInfos[i].buffers[index]) + iCurSample * 3, 3); + iCurSam >>= 8; + + psCaptureBuffer[iBufferPosCapture + + 2 * iCurSample + bufferInfos[i].channelNum] = static_cast ( iCurSam ); + } + break; + + case ASIOSTInt32LSB: + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + // convert to 16 bit + psCaptureBuffer[iBufferPosCapture + + 2 * iCurSample + bufferInfos[i].channelNum] = + (((int*) bufferInfos[i].buffers[index])[iCurSample] >> 16); + } + break; } } } @@ -608,12 +641,40 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow ) // PLAYBACK ---------------------------------------------------- if ( !bPlayBufferUnderrun ) { - // copy data from sound card in output buffer - for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) - { - // copy interleaved stereo data in mono sound card buffer - ((short*) bufferInfos[i].buffers[index])[iCurSample] = - psPlayBuffer[2 * iCurSample + bufferInfos[i].channelNum]; + // copy data from sound card in output buffer (copy + // interleaved stereo data in mono sound card buffer) + switch ( channelInfos[i].type ) + { + case ASIOSTInt16LSB: + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + ((short*) bufferInfos[i].buffers[index])[iCurSample] = + psPlayBuffer[2 * iCurSample + bufferInfos[i].channelNum]; + } + break; + + case ASIOSTInt24LSB: + +// not yet tested, horrible things might happen with the following code ;-) + + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + // convert current sample in 24 bit format + int iCurSam = static_cast ( psPlayBuffer[2 * iCurSample + bufferInfos[i].channelNum] ); + iCurSam <<= 8; + + memcpy ( ((char*) bufferInfos[i].buffers[index]) + iCurSample * 3, &iCurSam, 3); + } + break; + + case ASIOSTInt32LSB: + for ( iCurSample = 0; iCurSample < iASIOBufferSizeMono; iCurSample++ ) + { + // convert to 32 bit + int iCurSam = static_cast ( psPlayBuffer[2 * iCurSample + bufferInfos[i].channelNum] ); + ((int*) bufferInfos[i].buffers[index])[iCurSample] = ( iCurSam << 16 ); + } + break; } } }