diff --git a/src/client.cpp b/src/client.cpp index 19c9bfe2..89c4c813 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -188,7 +188,19 @@ void CClient::run() #endif // init object - Init(); + try + { + Init(); + } + catch ( CGenErr generr ) + { + // TODO better error management -> should be catched in main thread + // problem: how to catch errors in a different thread...? + + // quick hack solution + QMessageBox::critical ( 0, APP_NAME, generr.strError, "Quit", 0 ); + exit ( 0 ); + } // runtime phase ------------------------------------------------------------ diff --git a/src/client.h b/src/client.h index abbf6c65..863eb095 100755 --- a/src/client.h +++ b/src/client.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "global.h" #include "socket.h" #include "resample.h" diff --git a/src/global.h b/src/global.h index a889b1b0..57d10f2e 100755 --- a/src/global.h +++ b/src/global.h @@ -133,6 +133,7 @@ typedef unsigned int _MESSAGE_IDENT; #define MS_JIT_BUF_GET 4 #define MS_PACKET_RECEIVED 5 #define MS_PROTOCOL 6 +#define MS_ERROR_IN_THREAD 7 #define MUL_COL_LED_RED 0 #define MUL_COL_LED_YELLOW 1 diff --git a/windows/sound.cpp b/windows/sound.cpp index 6ae4bfd0..0f3ffc42 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -60,15 +60,18 @@ HANDLE m_ASIOEvent; int iInCurBlockToWrite; short* psSoundcardBuffer[MAX_SND_BUF_IN]; bool bBufferOverrun; -short* psCaptureConvBuf; -int iCurPosCaptConvBuf; // wave out int iOutCurBlockToWrite; short* psPlaybackBuffer[MAX_SND_BUF_OUT]; bool bBufferUnderrun; + +// ASIO buffer size conversion buffer +short* psCaptureConvBuf; +int iCurPosCaptConvBuf; short* psPlayConvBuf; int iCurPosPlayConvBuf; +int iASIOConfBufSize; int iCurNumSndBufIn; int iCurNumSndBufOut; @@ -313,7 +316,8 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize ) // TEST test if requested buffer size is supported by the audio hardware, if not, fire error if ( iASIOBufferSizeMono != iBufferSizeMono ) { - throw CGenErr ( "Required sound card buffer size not allowed by the audio hardware." ); + throw CGenErr ( QString ( "Required sound card buffer size of %1 samples " + "not supported by the audio hardware." ).arg(iBufferSizeMono) ); } // prepare input channels @@ -397,12 +401,15 @@ if ( iASIOBufferSizeMono != iBufferSizeMono ) // create memory for ASIO buffer conversion if required if ( iASIOBufferSizeMono != iBufferSizeMono ) { + // required size: two times of one stereo buffer of the larger buffer + iASIOConfBufSize = max(4 * iASIOBufferSizeMono, 2 * iBufferSizeStereo); + if ( psCaptureConvBuf != NULL ) { delete[] psCaptureConvBuf; } - psCaptureConvBuf = new short[max(2 * iASIOBufferSizeMono, iBufferSizeStereo)]; + psCaptureConvBuf = new short[iASIOConfBufSize]; iCurPosCaptConvBuf = 0; if ( psPlayConvBuf != NULL ) @@ -410,7 +417,7 @@ if ( iASIOBufferSizeMono != iBufferSizeMono ) delete[] psPlayConvBuf; } - psPlayConvBuf = new short[max(2 * iASIOBufferSizeMono, iBufferSizeStereo)]; + psPlayConvBuf = new short[iASIOConfBufSize]; iCurPosPlayConvBuf = 0; }