diff --git a/src/channel.cpp b/src/channel.cpp index d71d72fe..a8ea1ea5 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -37,11 +37,11 @@ CChannelSet::CChannelSet() QObject::connect(&vecChannels[2],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh2(CVector))); QObject::connect(&vecChannels[3],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh3(CVector))); QObject::connect(&vecChannels[4],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh4(CVector))); -// QObject::connect(&vecChannels[5],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh5(CVector))); -// QObject::connect(&vecChannels[6],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh6(CVector))); -// QObject::connect(&vecChannels[7],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh7(CVector))); -// QObject::connect(&vecChannels[8],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh8(CVector))); -// QObject::connect(&vecChannels[9],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh9(CVector))); + QObject::connect(&vecChannels[5],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh5(CVector))); + QObject::connect(&vecChannels[6],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh6(CVector))); + QObject::connect(&vecChannels[7],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh7(CVector))); + QObject::connect(&vecChannels[8],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh8(CVector))); + QObject::connect(&vecChannels[9],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh9(CVector))); // request jitter buffer size QObject::connect(&vecChannels[0],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh0())); @@ -49,11 +49,11 @@ CChannelSet::CChannelSet() QObject::connect(&vecChannels[2],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh2())); QObject::connect(&vecChannels[3],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh3())); QObject::connect(&vecChannels[4],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh4())); -// QObject::connect(&vecChannels[5],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh5())); -// QObject::connect(&vecChannels[6],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh6())); -// QObject::connect(&vecChannels[7],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh7())); -// QObject::connect(&vecChannels[8],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh8())); -// QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9())); + QObject::connect(&vecChannels[5],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh5())); + QObject::connect(&vecChannels[6],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh6())); + QObject::connect(&vecChannels[7],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh7())); + QObject::connect(&vecChannels[8],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh8())); + QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9())); } void CChannelSet::CreateAndSendChanListForAllConClients() @@ -142,9 +142,22 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, iCurChanID = GetFreeChan(); if ( iCurChanID != INVALID_CHANNEL_ID ) - { + { + // initialize current channel by storing the calling host + // address vecChannels[iCurChanID].SetAddress ( HostAdr ); + // reset the channel gains of current channel, at the same + // time reset gains of this channel ID for all other channels + for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + { + vecChannels[iCurChanID].SetGain ( i, (double) 1.0 ); + + // other channels (we do not distinguish the case if + // i == iCurChanID for simplicity) + vecChannels[i].SetGain ( iCurChanID, (double) 1.0 ); + } + // a new client connected to the server, set flag to create and // send all clients the updated channel list, we cannot create // the message here since the received data has to be put to the @@ -198,42 +211,41 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, return bRet; } -void CChannelSet::GetBlockAllConC ( CVector& vecChanID, +void CChannelSet::GetBlockAllConC ( CVector& vecChanID, CVector >& vecvecdData, - CVector& vecdGains ) -{ - /* init temporal data vector and clear input buffers */ + CVector >& vecvecdGains ) +{ + int i, j; + + // init temporal data vector and clear input buffers CVector vecdData ( MIN_BLOCK_SIZE_SAMPLES ); - vecChanID.Init ( 0 ); - vecvecdData.Init ( 0 ); - vecdGains.Init ( 0 ); + vecChanID.Init ( 0 ); + vecvecdData.Init ( 0 ); + vecvecdGains.Init ( 0 ); - /* make put and get calls thread safe. Do not forget to unlock mutex - afterwards! */ + // make put and get calls thread safe. Do not forget to unlock mutex + // afterwards! Mutex.lock(); { - /* Check all possible channels */ - for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + // check all possible channels + for ( i = 0; i < MAX_NUM_CHANNELS; i++ ) { - /* read out all input buffers to decrease timeout counter on - disconnected channels */ + // read out all input buffers to decrease timeout counter on + // disconnected channels const bool bGetOK = vecChannels[i].GetData ( vecdData ); if ( vecChannels[i].IsConnected() ) { - /* add ID, gain and data */ + // add ID and data vecChanID.Add ( i ); - -// TEST -vecdGains.Add ( 1.0);//vecChannels[i].GetGain() ); const int iOldSize = vecvecdData.Size(); vecvecdData.Enlarge ( 1 ); vecvecdData[iOldSize].Init ( vecdData.Size() ); vecvecdData[iOldSize] = vecdData; - /* send message for get status (for GUI) */ + // send message for get status (for GUI) if ( bGetOK ) { PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i ); @@ -243,23 +255,40 @@ vecdGains.Add ( 1.0);//vecChannels[i].GetGain() ); PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED, i ); } } + } + + // now that we know the IDs of the connected clients, get gains + const int iNumCurConnChan = vecChanID.Size(); + vecvecdGains.Init ( iNumCurConnChan ); + + for ( i = 0; i < iNumCurConnChan; i++ ) + { + vecvecdGains[i].Init ( iNumCurConnChan ); + + for ( j = 0; j < iNumCurConnChan; j++ ) + { + // The second index of "vecvecdGains" does not represent + // the channel ID! Therefore we have to use "vecChanID" to + // query the IDs of the currently connected channels + vecvecdGains[i][j] = vecChannels[i].GetGain( vecChanID[j] ); + } } } - Mutex.unlock(); /* release mutex */ + Mutex.unlock(); // release mutex } void CChannelSet::GetConCliParam ( CVector& vecHostAddresses, - CVector& veciJitBufSize, - CVector& veciNetwOutBlSiFact, - CVector& veciNetwInBlSiFact ) + CVector& veciJitBufSize, + CVector& veciNetwOutBlSiFact, + CVector& veciNetwInBlSiFact ) { CHostAddress InetAddr; /* init return values */ - vecHostAddresses.Init ( MAX_NUM_CHANNELS ); - veciJitBufSize.Init ( MAX_NUM_CHANNELS ); + vecHostAddresses.Init ( MAX_NUM_CHANNELS ); + veciJitBufSize.Init ( MAX_NUM_CHANNELS ); veciNetwOutBlSiFact.Init ( MAX_NUM_CHANNELS ); - veciNetwInBlSiFact.Init ( MAX_NUM_CHANNELS ); + veciNetwInBlSiFact.Init ( MAX_NUM_CHANNELS ); /* Check all possible channels */ for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) @@ -267,10 +296,10 @@ void CChannelSet::GetConCliParam ( CVector& vecHostAddresses, if ( vecChannels[i].GetAddress ( InetAddr ) ) { /* get requested data */ - vecHostAddresses[i] = InetAddr; - veciJitBufSize[i] = vecChannels[i].GetSockBufSize (); + vecHostAddresses[i] = InetAddr; + veciJitBufSize[i] = vecChannels[i].GetSockBufSize (); veciNetwOutBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactOut (); - veciNetwInBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactIn (); + veciNetwInBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactIn (); } } } @@ -310,16 +339,20 @@ CChannel::CChannel() : sName ( "" ), SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessage ( CVector ) ) ); - QObject::connect ( &Protocol, SIGNAL ( ChangeJittBufSize ( int ) ), + QObject::connect ( &Protocol, + SIGNAL ( ChangeJittBufSize ( int ) ), this, SLOT ( OnJittBufSizeChange ( int ) ) ); - QObject::connect ( &Protocol, SIGNAL ( ReqJittBufSize() ), + QObject::connect ( &Protocol, + SIGNAL ( ReqJittBufSize() ), SIGNAL ( ReqJittBufSize() ) ); - QObject::connect ( &Protocol, SIGNAL ( ConClientListMesReceived ( CVector ) ), + QObject::connect ( &Protocol, + SIGNAL ( ConClientListMesReceived ( CVector ) ), SIGNAL ( ConClientListMesReceived ( CVector ) ) ); - QObject::connect ( &Protocol, SIGNAL ( ChangeNetwBlSiFact ( int ) ), + QObject::connect ( &Protocol, + SIGNAL ( ChangeNetwBlSiFact ( int ) ), this, SLOT ( OnNetwBlSiFactChange ( int ) ) ); } @@ -355,14 +388,6 @@ void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut ) ConvBuf.Init ( iNewNetwBlSiFactOut * MIN_BLOCK_SIZE_SAMPLES ); } -void CChannel::OnNetwBlSiFactChange ( int iNewNetwBlSiFact ) -{ -// TEST -//qDebug ( "new network block size factor: %d", iNewNetwBlSiFact ); - - SetNetwBufSizeFactOut ( iNewNetwBlSiFact ); -} - void CChannel::OnSendProtMessage ( CVector vecMessage ) { // only send messages if we are connected, otherwise delete complete queue @@ -397,6 +422,14 @@ void CChannel::SetSockBufSize ( const int iNumBlocks ) Mutex.unlock(); } +void CChannel::OnNetwBlSiFactChange ( int iNewNetwBlSiFact ) +{ +// TEST +//qDebug ( "new network block size factor: %d", iNewNetwBlSiFact ); + + SetNetwBufSizeFactOut ( iNewNetwBlSiFact ); +} + void CChannel::OnJittBufSizeChange ( int iNewJitBufSize ) { // TEST @@ -405,6 +438,14 @@ void CChannel::OnJittBufSizeChange ( int iNewJitBufSize ) SetSockBufSize ( iNewJitBufSize ); } +void CChannel::OnChangeChanGain ( int iChanID, double dNewGain ) +{ + ASSERT ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) ); + + // set value + vecdGains[iChanID] = dNewGain; +} + bool CChannel::GetAddress(CHostAddress& RetAddr) { if ( IsConnected() ) diff --git a/src/channel.h b/src/channel.h index f9770495..9b7fba3c 100755 --- a/src/channel.h +++ b/src/channel.h @@ -43,7 +43,7 @@ /* maximum number of internet connections (channels) */ // if you want to change this paramter, change the connections in this class, too! -#define MAX_NUM_CHANNELS 5//10 /* max number channels for server */ +#define MAX_NUM_CHANNELS 10 /* max number channels for server */ /* no valid channel number */ #define INVALID_CHANNEL_ID (MAX_NUM_CHANNELS + 1) @@ -165,6 +165,7 @@ public slots: void OnSendProtMessage ( CVector vecMessage ); void OnJittBufSizeChange ( int iNewJitBufSize ); void OnNetwBlSiFactChange ( int iNewNetwBlSiFact ); + void OnChangeChanGain ( int iChanID, double dNewGain ); signals: void MessReadyForSending ( CVector vecMessage ); @@ -193,7 +194,7 @@ public: void GetBlockAllConC ( CVector& vecChanID, CVector >& vecvecdData, - CVector& vecdGains ); + CVector >& vecvecdGains ); void GetConCliParam ( CVector& vecHostAddresses, CVector& veciJitBufSize, diff --git a/src/client.cpp b/src/client.cpp index 4077cbcd..835d600a 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -70,20 +70,20 @@ void CClient::OnReqJittBufSize() Channel.CreateNetwBlSiFactMes ( iNetwBufSizeFactIn ); } -bool CClient::SetServerAddr(QString strNAddr) +bool CClient::SetServerAddr ( QString strNAddr ) { QHostAddress InetAddr; - if (InetAddr.setAddress(strNAddr)) + if ( InetAddr.setAddress ( strNAddr ) ) { - /* The server port is fixed and always the same */ - Channel.SetAddress(CHostAddress(InetAddr, LLCON_PORT_NUMBER)); + // the server port is fixed and always the same + Channel.SetAddress ( CHostAddress ( InetAddr, LLCON_PORT_NUMBER ) ); return true; } else { - return false; /* invalid address */ + return false; // invalid address } } diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 5d101c94..e88e4752 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -82,10 +82,10 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, "red color." ) ); /* init server address line edit */ - LineEditServerAddr->setText ( pClient->strIPAddress.c_str () ); + LineEditServerAddr->setText ( pClient->strIPAddress.c_str() ); /* init status label */ - OnTimerStatus (); + OnTimerStatus(); /* init connection button text */ PushButtonConnect->setText ( CON_BUT_CONNECTTEXT ); @@ -98,26 +98,27 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, /* init slider controls --- */ - /* audio in fader */ - SliderAudInFader->setRange(0, AUD_FADER_IN_MAX); + // audio in fader + SliderAudInFader->setRange ( 0, AUD_FADER_IN_MAX ); const int iCurAudInFader = pClient->GetAudioInFader(); - SliderAudInFader->setValue(iCurAudInFader); - SliderAudInFader->setTickInterval(AUD_FADER_IN_MAX / 9); + SliderAudInFader->setValue ( iCurAudInFader ); + SliderAudInFader->setTickInterval ( AUD_FADER_IN_MAX / 9 ); - /* audio reverberation */ - SliderAudReverb->setRange(0, AUD_REVERB_MAX); + // audio reverberation + SliderAudReverb->setRange ( 0, AUD_REVERB_MAX ); const int iCurAudReverb = pClient->GetReverbLevel(); SliderAudReverb->setValue ( AUD_REVERB_MAX - iCurAudReverb ); - SliderAudReverb->setTickInterval(AUD_REVERB_MAX / 9); + SliderAudReverb->setTickInterval ( AUD_REVERB_MAX / 9 ); /* set radio buttons --- */ - /* reverb channel */ + // reverb channel if (pClient->IsReverbOnLeftChan()) RadioButtonRevSelL->setChecked(true); else RadioButtonRevSelR->setChecked(true); + /* Settings menu ------------------------------------------------------- */ pSettingsMenu = new QPopupMenu ( this ); CHECK_PTR ( pSettingsMenu ); @@ -139,23 +140,23 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, /* connections ---------------------------------------------------------- */ - /* push-buttons */ + // push-buttons QObject::connect(PushButtonConnect, SIGNAL(clicked()), this, SLOT(OnConnectDisconBut())); - /* timers */ + // timers QObject::connect(&TimerSigMet, SIGNAL(timeout()), this, SLOT(OnTimerSigMet())); QObject::connect(&TimerStatus, SIGNAL(timeout()), this, SLOT(OnTimerStatus())); - /* sliders */ + // sliders QObject::connect(SliderAudInFader, SIGNAL(valueChanged(int)), this, SLOT(OnSliderAudInFader(int))); QObject::connect(SliderAudReverb, SIGNAL(valueChanged(int)), this, SLOT(OnSliderAudReverb(int))); - /* radio buttons */ + // radio buttons QObject::connect(RadioButtonRevSelL, SIGNAL(clicked()), this, SLOT(OnRevSelL())); QObject::connect(RadioButtonRevSelR, SIGNAL(clicked()), @@ -167,7 +168,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, /* timers --------------------------------------------------------------- */ - /* start timer for status bar */ + // start timer for status bar TimerStatus.start(STATUSBAR_UPDATE_TIME); @@ -176,7 +177,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, //vecpChanFader.Init(0); //vecpChanFader.Add(new CLlconClientDlg::CChannelFader(FrameAudioFaders, FrameAudioFadersLayout, "test")); - +//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders )); /* for ( int z = 0; z < 100; z++) { @@ -256,7 +257,7 @@ void CLlconClientDlg::OnOpenGeneralSettings() } void CLlconClientDlg::OnTimerSigMet () -{ +{ /* get current input levels */ double dCurSigLevelL = pClient->MicLevelL (); double dCurSigLevelR = pClient->MicLevelR (); @@ -292,6 +293,14 @@ void CLlconClientDlg::OnConClientListMesReceived ( CVector ve { int i; + + +//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders )); + + + + + // TODO // remove old controls @@ -310,7 +319,7 @@ for ( i = 0; i < vecChanInfo.Size(); i++ ) vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders, FrameAudioFadersLayout, addrTest.toString() ); } - +//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders )); } diff --git a/src/server.cpp b/src/server.cpp index 9407fcc2..51ba1a0a 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -30,10 +30,10 @@ CServer::CServer() : Socket ( &ChannelSet, this ) { vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES ); - /* init moving average buffer for response time evaluation */ + // init moving average buffer for response time evaluation RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); - /* connect timer timeout signal */ + // connect timer timeout signal QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) ); @@ -67,17 +67,17 @@ void CServer::Start() { if ( !IsRunning() ) { - /* start main timer */ + // start main timer Timer.start ( MIN_BLOCK_DURATION_MS ); - /* init time for response time evaluation */ + // init time for response time evaluation TimeLastBlock = QTime::currentTime(); } } void CServer::Stop() { - /* stop main timer */ + // stop main timer Timer.stop(); qDebug ( CLogTimeDate::toString() + "Server stopped" ); @@ -87,23 +87,22 @@ void CServer::OnTimer() { CVector vecChanID; CVector > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); - CVector vecdGains; + CVector > vecvecdGains; - /* get data from all connected clients */ - ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecdGains ); + // get data from all connected clients + ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData, vecvecdGains ); const int iNumClients = vecChanID.Size(); - /* Check if at least one client is connected. If not, stop server until - one client is connected */ + // Check if at least one client is connected. If not, stop server until + // one client is connected if ( iNumClients != 0 ) { for ( int i = 0; i < iNumClients; i++ ) { -// TODO generate a sparate mix for each channel + // generate a sparate mix for each channel + // actual processing of audio data -> mix + vecsSendData = ProcessData ( vecvecdData, vecvecdGains[i] ); -// actual processing of audio data -> mix -vecsSendData = ProcessData ( vecvecdData, vecdGains ); - // send separate mix to current clients Socket.SendPacket ( ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ), @@ -111,18 +110,18 @@ vecsSendData = ProcessData ( vecvecdData, vecdGains ); } - /* update response time measurement --------------------------------- */ - /* add time difference */ + // update response time measurement ------------------------------------ + // add time difference const QTime CurTime = QTime::currentTime (); - /* we want to calculate the standard deviation (we assume that the mean - is correct at the block period time) */ + // we want to calculate the standard deviation (we assume that the mean + // is correct at the block period time) const double dCurAddVal = ( (double) TimeLastBlock.msecsTo ( CurTime ) - MIN_BLOCK_DURATION_MS ); - RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */ + RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value - /* store old time value */ + // store old time value TimeLastBlock = CurTime; } else @@ -147,7 +146,7 @@ CVector CServer::ProcessData ( CVector >& vecvecdData, // 3 dB offset to avoid overload if all clients are set to gain 1 const double dNorm = (double) 2.0; - /* mix all audio data from all clients together */ + // mix all audio data from all clients together for ( int i = 0; i < MIN_BLOCK_SIZE_SAMPLES; i++ ) { double dMixedData = 0.0; @@ -157,7 +156,7 @@ CVector CServer::ProcessData ( CVector >& vecvecdData, dMixedData += vecvecdData[j][i] * vecdGains[j]; } - /* normalization and truncating to short */ + // normalization and truncating to short vecsOutData[i] = Double2Short ( dMixedData / dNorm ); } @@ -166,7 +165,7 @@ CVector CServer::ProcessData ( CVector >& vecvecdData, bool CServer::GetTimingStdDev ( double& dCurTiStdDev ) { - dCurTiStdDev = 0.0; /* init return value */ + dCurTiStdDev = 0.0; // init return value /* only return value if server is active and the actual measurement is updated */