diff --git a/src/client.cpp b/src/client.cpp index 057cad8b..267a30a3 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -211,7 +211,7 @@ void CClient::run() // TEST //Sleep(300); - +//wait(3000); // copy data from one stereo buffer in two separate buffers iInCnt = 0; diff --git a/src/llconclientdlgbase.ui b/src/llconclientdlgbase.ui index d5527f1c..c566c240 100755 --- a/src/llconclientdlgbase.ui +++ b/src/llconclientdlgbase.ui @@ -44,8 +44,8 @@ - 0 - 0 + 5 + 5 0 0 diff --git a/src/main.cpp b/src/main.cpp index aeea157e..a02ebeca 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ int main ( int argc, char** argv ) for ( int i = 1; i < argc; i++ ) { /* Server mode flag ------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) == TRUE ) + if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) ) { bIsClient = false; @@ -62,7 +62,7 @@ cerr << "server "; } /* Use GUI flag ----------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) == TRUE ) + if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) ) { bUseGUI = false; @@ -72,7 +72,7 @@ cerr << "nogui "; } /* Use logging flag ------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) == TRUE ) + if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) ) { bUseServerLogging = true; @@ -82,7 +82,7 @@ cerr << "logging "; } /* Initialization file ---------------------------------------------------- */ - if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) == TRUE ) + if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) { strIniFileName = strArgument; continue; diff --git a/src/settings.cpp b/src/settings.cpp index 03d74870..7fc72219 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -188,7 +188,7 @@ bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& s // check range if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) ) { - bReturn = TRUE; + bReturn = true; } } diff --git a/src/socket.cpp b/src/socket.cpp index 119df140..3530ec6e 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -33,8 +33,7 @@ void CSocket::Init() // initialize the listening socket bool bSuccess = SocketDevice.bind ( - QHostAddress ( (quint32) 0 ), // INADDR_ANY - LLCON_PORT_NUMBER ); + QHostAddress ( QHostAddress::Any ), LLCON_PORT_NUMBER ); if ( bIsClient ) { @@ -44,8 +43,7 @@ void CSocket::Init() // if server and client is on same machine, decrease port number by // one by definition bSuccess = SocketDevice.bind ( - QHostAddress( (quint32) 0 ), // INADDR_ANY - LLCON_PORT_NUMBER - 1 ); + QHostAddress( QHostAddress::Any ), LLCON_PORT_NUMBER - 1 ); } } @@ -83,57 +81,60 @@ void CSocket::SendPacket ( const CVector& vecbySendBuf, void CSocket::OnDataReceived() { - QHostAddress SenderAddress; - quint16 SenderPort; + while ( SocketDevice.hasPendingDatagrams() ) + { + QHostAddress SenderAddress; + quint16 SenderPort; - // read block from network interface and query address of sender - const int iNumBytesRead = SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0], - MAX_SIZE_BYTES_NETW_BUF, &SenderAddress, &SenderPort ); + // read block from network interface and query address of sender + const int iNumBytesRead = SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0], + MAX_SIZE_BYTES_NETW_BUF, &SenderAddress, &SenderPort ); - // convert address of client - CHostAddress RecHostAddr ( SenderAddress, SenderPort ); + // convert address of client + CHostAddress RecHostAddr ( SenderAddress, SenderPort ); - // check if an error occurred - if ( iNumBytesRead < 0 ) - { - return; - } + // check if an error occurred + if ( iNumBytesRead < 0 ) + { + return; + } - if ( bIsClient ) - { - // client - // check if packet comes from the server we want to connect - if ( ! ( pChannel->GetAddress() == RecHostAddr ) ) - { - return; - } + if ( bIsClient ) + { + // client + // check if packet comes from the server we want to connect + if ( ! ( pChannel->GetAddress() == RecHostAddr ) ) + { + return; + } - switch ( pChannel->PutData ( vecbyRecBuf, iNumBytesRead ) ) - { - case PS_AUDIO_OK: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN ); - break; + switch ( pChannel->PutData ( vecbyRecBuf, iNumBytesRead ) ) + { + case PS_AUDIO_OK: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN ); + break; - case PS_AUDIO_ERR: - case PS_GEN_ERROR: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED ); - break; + case PS_AUDIO_ERR: + case PS_GEN_ERROR: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED ); + break; - case PS_PROT_ERR: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW ); - break; - } - } - else - { - // server - if ( pChannelSet->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ) ) - { - // this was an audio packet, start server - // tell the server object to wake up if it - // is in sleep mode (Qt will delete the event object when done) - QCoreApplication::postEvent ( pServer, - new CLlconEvent ( MS_PACKET_RECEIVED, 0, 0 ) ); - } - } + case PS_PROT_ERR: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW ); + break; + } + } + else + { + // server + if ( pChannelSet->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ) ) + { + // this was an audio packet, start server + // tell the server object to wake up if it + // is in sleep mode (Qt will delete the event object when done) + QCoreApplication::postEvent ( pServer, + new CLlconEvent ( MS_PACKET_RECEIVED, 0, 0 ) ); + } + } + } } diff --git a/windows/sound.cpp b/windows/sound.cpp index 4387d5ce..2ae48989 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -45,13 +45,13 @@ bool CSound::Read ( CVector& psData ) bool bError = false; // check if device must be opened or reinitialized - if ( bChangParamIn == TRUE ) + if ( bChangParamIn ) { // Reinit sound interface InitRecordingAndPlayback ( iBufferSize ); // Reset flag - bChangParamIn = FALSE; + bChangParamIn = false; } @@ -59,13 +59,13 @@ bool CSound::Read ( CVector& psData ) // wait until data is available if ( ! ( m_WaveInHeader[iWhichBufferIn].dwFlags & WHDR_DONE ) ) { - if ( bBlockingRec == TRUE ) + if ( bBlockingRec ) { WaitForSingleObject ( m_WaveInEvent, INFINITE ); } else { - return FALSE; + return false; } } */ @@ -87,11 +87,11 @@ bool CSound::Read ( CVector& psData ) // very likely that a buffer got lost -> set error flag if ( iNumInBufDone == iCurNumSndBufIn ) { - bError = TRUE; + bError = true; } else { - bError = FALSE; + bError = false; } */ @@ -160,7 +160,7 @@ void CSound::SetInNumBuf ( int iNewNum ) if ( iNewNum != iCurNumSndBufIn ) { iCurNumSndBufIn = iNewNum; - bChangParamIn = TRUE; + bChangParamIn = true; } } @@ -176,13 +176,13 @@ bool CSound::Write ( CVector& psData ) bool bError; // check if device must be opened or reinitialized - if ( bChangParamOut == TRUE ) + if ( bChangParamOut ) { // reinit sound interface InitRecordingAndPlayback ( iBufferSize ); // reset flag - bChangParamOut = FALSE; + bChangParamOut = false; } /* @@ -225,11 +225,11 @@ bool CSound::Write ( CVector& psData ) // set index for done buffer iIndexDoneBuf = iCurNumSndBufOut / 2; - bError = TRUE; + bError = true; } else { - bError = FALSE; + bError = false; } } */ @@ -312,7 +312,7 @@ void CSound::SetOutNumBuf ( int iNewNum ) if ( iNewNum != iCurNumSndBufOut ) { iCurNumSndBufOut = iNewNum; - bChangParamOut = TRUE; + bChangParamOut = true; } } @@ -452,8 +452,8 @@ void CSound::Close() Sleep ( 500 ); // set flag to open devices the next time it is initialized - bChangParamIn = TRUE; - bChangParamOut = TRUE; + bChangParamIn = true; + bChangParamOut = true; } CSound::CSound() @@ -589,8 +589,8 @@ pstrDevices[0] = driverInfo.name; m_WaveOutEvent = CreateEvent ( NULL, FALSE, FALSE, NULL ); // set flag to open devices - bChangParamIn = TRUE; - bChangParamOut = TRUE; + bChangParamIn = true; + bChangParamOut = true; } CSound::~CSound() @@ -779,11 +779,11 @@ long CSound::asioMessages ( long selector, long value, void* message, double* op \******************************************************************************/ bool CSound::Read ( CVector& psData ) { - int i; - bool bError; + int i; + bool bError; // check if device must be opened or reinitialized - if ( bChangParamIn == TRUE ) + if ( bChangParamIn ) { OpenInDevice(); @@ -791,19 +791,19 @@ bool CSound::Read ( CVector& psData ) InitRecording ( iBufferSizeIn, bBlockingRec ); // Reset flag - bChangParamIn = FALSE; + bChangParamIn = false; } // wait until data is available if ( ! ( m_WaveInHeader[iWhichBufferIn].dwFlags & WHDR_DONE ) ) { - if ( bBlockingRec == TRUE ) + if ( bBlockingRec ) { WaitForSingleObject ( m_WaveInEvent, INFINITE ); } else { - return FALSE; + return false; } } @@ -821,11 +821,11 @@ bool CSound::Read ( CVector& psData ) very likely that a buffer got lost -> set error flag */ if ( iNumInBufDone == iCurNumSndBufIn ) { - bError = TRUE; + bError = true; } else { - bError = FALSE; + bError = false; } // copy data from sound card in output buffer @@ -877,12 +877,12 @@ void CSound::PrepareInBuffer ( int iBufNum ) void CSound::InitRecording ( int iNewBufferSize, bool bNewBlocking ) { // check if device must be opened or reinitialized - if ( bChangParamIn == TRUE ) + if ( bChangParamIn ) { OpenInDevice(); // reset flag - bChangParamIn = FALSE; + bChangParamIn = false; } // set internal parameter @@ -960,7 +960,7 @@ void CSound::SetInDev ( int iNewDev ) if ( iNewDev != iCurInDev ) { iCurInDev = iNewDev; - bChangParamIn = TRUE; + bChangParamIn = true; } } @@ -976,7 +976,7 @@ void CSound::SetInNumBuf ( int iNewNum ) if ( iNewNum != iCurNumSndBufIn ) { iCurNumSndBufIn = iNewNum; - bChangParamIn = TRUE; + bChangParamIn = true; } } @@ -992,7 +992,7 @@ bool CSound::Write ( CVector& psData ) bool bError; // check if device must be opened or reinitialized - if ( bChangParamOut == TRUE ) + if ( bChangParamOut ) { OpenOutDevice(); @@ -1000,7 +1000,7 @@ bool CSound::Write ( CVector& psData ) InitPlayback ( iBufferSizeOut, bBlockingPlay ); // reset flag - bChangParamOut = FALSE; + bChangParamOut = false; } // get number of "done"-buffers and position of one of them @@ -1009,9 +1009,9 @@ bool CSound::Write ( CVector& psData ) // now check special cases (Buffer is full or empty) if ( iCntPrepBuf == 0 ) { - if ( bBlockingPlay == TRUE ) + if ( bBlockingPlay ) { - /* Blocking wave out routine. Needed for transmitter. Always + /* Blocking wave out routine. Always ensure that the buffer is completely filled to avoid buffer underruns */ while ( iCntPrepBuf == 0 ) @@ -1026,7 +1026,7 @@ bool CSound::Write ( CVector& psData ) // All buffers are filled, dump new block -------------------------- // It would be better to kill half of the buffer blocks to set the start // back to the middle: TODO - return TRUE; // an error occurred + return true; // an error occurred } } else @@ -1052,11 +1052,11 @@ bool CSound::Write ( CVector& psData ) // set index for done buffer iIndexDoneBuf = iCurNumSndBufOut / 2; - bError = TRUE; + bError = true; } else { - bError = FALSE; + bError = false; } } @@ -1115,12 +1115,12 @@ void CSound::InitPlayback ( int iNewBufferSize, bool bNewBlocking ) int i, j; // check if device must be opened or reinitialized - if ( bChangParamOut == TRUE ) + if ( bChangParamOut ) { OpenOutDevice(); // reset flag - bChangParamOut = FALSE; + bChangParamOut = false; } // set internal parameters @@ -1187,7 +1187,7 @@ void CSound::SetOutDev ( int iNewDev ) if ( iNewDev != iCurOutDev ) { iCurOutDev = iNewDev; - bChangParamOut = TRUE; + bChangParamOut = true; } } @@ -1203,7 +1203,7 @@ void CSound::SetOutNumBuf ( int iNewNum ) if ( iNewNum != iCurNumSndBufOut ) { iCurNumSndBufOut = iNewNum; - bChangParamOut = TRUE; + bChangParamOut = true; } } @@ -1213,8 +1213,8 @@ void CSound::SetOutNumBuf ( int iNewNum ) \******************************************************************************/ void CSound::Close() { - int i; - MMRESULT result; + int i; + MMRESULT result; // reset audio driver if ( m_WaveOut != NULL ) @@ -1292,8 +1292,8 @@ void CSound::Close() } // set flag to open devices the next time it is initialized - bChangParamIn = TRUE; - bChangParamOut = TRUE; + bChangParamIn = true; + bChangParamOut = true; } CSound::CSound() @@ -1324,15 +1324,15 @@ CSound::CSound() } // init wave-format structure - sWaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; - sWaveFormatEx.nChannels = NUM_IN_OUT_CHANNELS; - sWaveFormatEx.wBitsPerSample = BITS_PER_SAMPLE; - sWaveFormatEx.nSamplesPerSec = SND_CRD_SAMPLE_RATE; - sWaveFormatEx.nBlockAlign = sWaveFormatEx.nChannels * + sWaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; + sWaveFormatEx.nChannels = NUM_IN_OUT_CHANNELS; + sWaveFormatEx.wBitsPerSample = BITS_PER_SAMPLE; + sWaveFormatEx.nSamplesPerSec = SND_CRD_SAMPLE_RATE; + sWaveFormatEx.nBlockAlign = sWaveFormatEx.nChannels * sWaveFormatEx.wBitsPerSample / 8; sWaveFormatEx.nAvgBytesPerSec = sWaveFormatEx.nBlockAlign * sWaveFormatEx.nSamplesPerSec; - sWaveFormatEx.cbSize = 0; + sWaveFormatEx.cbSize = 0; // get the number of digital audio devices in this computer, check range iNumDevs = waveInGetNumDevs(); @@ -1359,22 +1359,22 @@ CSound::CSound() // we use an event controlled wave-in (wave-out) structure // create events - m_WaveInEvent = CreateEvent ( NULL, FALSE, FALSE, NULL ); + m_WaveInEvent = CreateEvent ( NULL, FALSE, FALSE, NULL ); m_WaveOutEvent = CreateEvent ( NULL, FALSE, FALSE, NULL ); // set flag to open devices - bChangParamIn = TRUE; - bChangParamOut = TRUE; + bChangParamIn = true; + bChangParamOut = true; // default device number, "wave mapper" iCurInDev = WAVE_MAPPER; iCurOutDev = WAVE_MAPPER; // non-blocking wave out is default - bBlockingPlay = FALSE; + bBlockingPlay = false; // blocking wave in is default - bBlockingRec = TRUE; + bBlockingRec = true; } CSound::~CSound() diff --git a/windows/sound.h b/windows/sound.h index 3a248ffa..c054c581 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -71,8 +71,8 @@ public: CSound(); virtual ~CSound(); - void InitRecording ( int iNewBufferSize, bool bNewBlocking = TRUE ) { InitRecordingAndPlayback ( iNewBufferSize ); } - void InitPlayback ( int iNewBufferSize, bool bNewBlocking = FALSE ) { InitRecordingAndPlayback ( iNewBufferSize ); } + void InitRecording ( int iNewBufferSize, bool bNewBlocking = true ) { InitRecordingAndPlayback ( iNewBufferSize ); } + void InitPlayback ( int iNewBufferSize, bool bNewBlocking = false ) { InitRecordingAndPlayback ( iNewBufferSize ); } bool Read ( CVector& psData ); bool Write ( CVector& psData ); @@ -137,8 +137,8 @@ public: CSound(); virtual ~CSound(); - void InitRecording ( int iNewBufferSize, bool bNewBlocking = TRUE ); - void InitPlayback ( int iNewBufferSize, bool bNewBlocking = FALSE ); + void InitRecording ( int iNewBufferSize, bool bNewBlocking = true ); + void InitPlayback ( int iNewBufferSize, bool bNewBlocking = false ); bool Read ( CVector& psData ); bool Write ( CVector& psData );