added new file for protocol (just template right now), new code style
This commit is contained in:
parent
270725688f
commit
dd914c411c
14 changed files with 351 additions and 160 deletions
|
@ -13,7 +13,8 @@ llcon_SOURCES = ../src/buffer.cpp \
|
||||||
../src/llconserverdlg.cpp \
|
../src/llconserverdlg.cpp \
|
||||||
../src/server.cpp \
|
../src/server.cpp \
|
||||||
../src/settings.cpp \
|
../src/settings.cpp \
|
||||||
../src/multicolorled.cpp \
|
../src/protocol.cpp \
|
||||||
|
../src/multicolorled.cpp \
|
||||||
sound.cpp \
|
sound.cpp \
|
||||||
../src/buffer.h \
|
../src/buffer.h \
|
||||||
../src/global.h \
|
../src/global.h \
|
||||||
|
@ -26,6 +27,7 @@ llcon_SOURCES = ../src/buffer.cpp \
|
||||||
../src/client.h \
|
../src/client.h \
|
||||||
../src/server.h \
|
../src/server.h \
|
||||||
../src/settings.h \
|
../src/settings.h \
|
||||||
|
../src/protocol.h \
|
||||||
../src/multicolorled.h \
|
../src/multicolorled.h \
|
||||||
../src/llconserverdlg.h \
|
../src/llconserverdlg.h \
|
||||||
../src/llconclientdlg.h \
|
../src/llconclientdlg.h \
|
||||||
|
|
|
@ -63,37 +63,45 @@ int CChannelSet::CheckAddr(const CHostAddress& Addr)
|
||||||
bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
|
bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
|
||||||
const int iNumBytesRead, const CHostAddress& HostAdr)
|
const int iNumBytesRead, const CHostAddress& HostAdr)
|
||||||
{
|
{
|
||||||
Mutex.lock();
|
Mutex.lock ();
|
||||||
|
|
||||||
/* get channel ID ------------------------------------------------------- */
|
/* get channel ID ------------------------------------------------------- */
|
||||||
bool bChanOK = true;
|
bool bChanOK = true;
|
||||||
|
|
||||||
/* check address */
|
/* check address */
|
||||||
int iCurChanID = CheckAddr(HostAdr);
|
int iCurChanID = CheckAddr ( HostAdr );
|
||||||
|
|
||||||
if (iCurChanID == INVALID_CHANNEL_ID)
|
if ( iCurChanID == INVALID_CHANNEL_ID )
|
||||||
{
|
{
|
||||||
/* a new client is calling, look for free channel */
|
/* a new client is calling, look for free channel */
|
||||||
iCurChanID = GetFreeChan();
|
iCurChanID = GetFreeChan ();
|
||||||
|
|
||||||
if (iCurChanID != INVALID_CHANNEL_ID)
|
if ( iCurChanID != INVALID_CHANNEL_ID )
|
||||||
vecChannels[iCurChanID].SetAddress(HostAdr);
|
{
|
||||||
else
|
vecChannels[iCurChanID].SetAddress ( HostAdr );
|
||||||
bChanOK = false; /* no free channel available */
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bChanOK = false; /* no free channel available */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* put received data in jitter buffer ----------------------------------- */
|
/* put received data in jitter buffer ----------------------------------- */
|
||||||
if (bChanOK)
|
if ( bChanOK )
|
||||||
{
|
{
|
||||||
/* put packet in socket buffer */
|
/* put packet in socket buffer */
|
||||||
if (vecChannels[iCurChanID].PutData(vecbyRecBuf, iNumBytesRead))
|
if ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
|
||||||
PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID);
|
{
|
||||||
else
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN, iCurChanID );
|
||||||
PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED, iCurChanID );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex.unlock();
|
Mutex.unlock ();
|
||||||
|
|
||||||
return !bChanOK; /* return 1 if error */
|
return !bChanOK; /* return 1 if error */
|
||||||
}
|
}
|
||||||
|
@ -213,25 +221,6 @@ void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )
|
||||||
Mutex.unlock ();
|
Mutex.unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CChannel::GetTimeStampIdx ()
|
|
||||||
{
|
|
||||||
/* only send time stamp index after a pre-defined number of packets */
|
|
||||||
if ( iTimeStampActCnt > 0 )
|
|
||||||
{
|
|
||||||
iTimeStampActCnt--;
|
|
||||||
return INVALID_TIME_STAMP_IDX;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* reset time stamp activation counter */
|
|
||||||
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
|
|
||||||
|
|
||||||
/* wraps around automatically */
|
|
||||||
byTimeStampIdxCnt++;
|
|
||||||
return byTimeStampIdxCnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
||||||
{
|
{
|
||||||
if (IsConnected())
|
if (IsConnected())
|
||||||
|
@ -262,9 +251,6 @@ bool CChannel::PutData(const CVector<unsigned char>& vecbyData,
|
||||||
|
|
||||||
/* do resampling to compensate for sample rate offsets in the
|
/* do resampling to compensate for sample rate offsets in the
|
||||||
different sound cards of the clients */
|
different sound cards of the clients */
|
||||||
// we should not do resampling here since we already have resampling
|
|
||||||
// in the client audio path, we could use this resampling for this
|
|
||||||
// sample rate correction, too
|
|
||||||
/*
|
/*
|
||||||
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
||||||
vecdResInData[i] = (double) vecsData[i];
|
vecdResInData[i] = (double) vecsData[i];
|
||||||
|
@ -338,7 +324,25 @@ CVector<unsigned char> CChannel::PrepSendPacket(const CVector<short>& vecsNPacke
|
||||||
|
|
||||||
return vecbySendBuf;
|
return vecbySendBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CChannel::GetTimeStampIdx ()
|
||||||
|
{
|
||||||
|
/* only send time stamp index after a pre-defined number of packets */
|
||||||
|
if ( iTimeStampActCnt > 0 )
|
||||||
|
{
|
||||||
|
iTimeStampActCnt--;
|
||||||
|
return INVALID_TIME_STAMP_IDX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* reset time stamp activation counter */
|
||||||
|
iTimeStampActCnt = NUM_BL_TIME_STAMPS - 1;
|
||||||
|
|
||||||
|
/* wraps around automatically */
|
||||||
|
byTimeStampIdxCnt++;
|
||||||
|
return byTimeStampIdxCnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
|
@ -395,8 +399,6 @@ fflush(pFile);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* calculate linear regression for sample rate estimation */
|
/* calculate linear regression for sample rate estimation */
|
||||||
/* first, calculate averages */
|
/* first, calculate averages */
|
||||||
double dTimeAv = 0;
|
double dTimeAv = 0;
|
||||||
|
@ -434,15 +436,10 @@ fflush(pFile);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static FILE* pFile = fopen("v.dat", "w");
|
static FILE* pFile = fopen("v.dat", "w");
|
||||||
fprintf(pFile, "%e\n", dSamRateEst);
|
fprintf(pFile, "%e\n", dSamRateEst);
|
||||||
fflush(pFile);
|
fflush(pFile);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
#define CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
||||||
|
|
||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "audiocompr.h"
|
#include "audiocompr.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "resample.h"
|
#include "resample.h"
|
||||||
#include "qdatetime.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
/* time interval of taps for sample rate offset estimation (time stamps) */
|
/* time interval of taps for sample rate offset estimation (time stamps) */
|
||||||
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
|
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
|
||||||
|
|
||||||
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / MIN_BLOCK_DURATION_MS )
|
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / BLOCK_DURATION_MS )
|
||||||
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
|
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
|
||||||
|
|
||||||
/* length of the moving average buffer for response time measurement */
|
/* length of the moving average buffer for response time measurement */
|
||||||
|
|
|
@ -68,9 +68,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
||||||
OnTimerStatus ();
|
OnTimerStatus ();
|
||||||
|
|
||||||
/* init sample rate offset label */
|
/* init sample rate offset label */
|
||||||
// TextSamRateOffsValue->setText ( "0 Hz" );
|
TextSamRateOffsValue->setText ( "0 Hz" );
|
||||||
// FIXME disable sample rate estimation result label since estimation does not work
|
|
||||||
TextSamRateOffsValue->setText ( "---" );
|
|
||||||
|
|
||||||
/* init connection button text */
|
/* init connection button text */
|
||||||
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
|
PushButtonConnect->setText ( CON_BUT_CONNECTTEXT );
|
||||||
|
@ -275,17 +273,9 @@ void CLlconClientDlg::OnTimerStatus()
|
||||||
TextLabelStatus->setText(tr("disconnected"));
|
TextLabelStatus->setText(tr("disconnected"));
|
||||||
|
|
||||||
/* update sample rate offset label */
|
/* update sample rate offset label */
|
||||||
// FIXME disable sample rate estimation result label since estimation does not work
|
|
||||||
/*
|
|
||||||
QString strSamRaOffs;
|
QString strSamRaOffs;
|
||||||
|
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset(), 'f', 2);
|
||||||
// FIXME: sample rate estimation result must be corrected since we use
|
|
||||||
// smaller buffers in client now. Actual estimation should be fixed, not here
|
|
||||||
|
|
||||||
strSamRaOffs.setNum(pClient->GetChannel()->GetResampleOffset() *
|
|
||||||
MIN_BLOCK_DURATION_MS / BLOCK_DURATION_MS, 'f', 2);
|
|
||||||
TextSamRateOffsValue->setText(strSamRaOffs + " Hz");
|
TextSamRateOffsValue->setText(strSamRaOffs + " Hz");
|
||||||
*/
|
|
||||||
|
|
||||||
/* response time */
|
/* response time */
|
||||||
TextLabelStdDevTimer->setText(QString().
|
TextLabelStdDevTimer->setText(QString().
|
||||||
|
|
|
@ -107,7 +107,8 @@ CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal,
|
||||||
void CLlconServerDlg::OnTimer()
|
void CLlconServerDlg::OnTimer()
|
||||||
{
|
{
|
||||||
CVector<CHostAddress> vecHostAddresses;
|
CVector<CHostAddress> vecHostAddresses;
|
||||||
CVector<double> vecdSamOffs;
|
CVector<double> vecdSamOffs;
|
||||||
|
double dCurTiStdDev;
|
||||||
|
|
||||||
ListViewMutex.lock();
|
ListViewMutex.lock();
|
||||||
|
|
||||||
|
@ -140,9 +141,16 @@ void CLlconServerDlg::OnTimer()
|
||||||
|
|
||||||
ListViewMutex.unlock();
|
ListViewMutex.unlock();
|
||||||
|
|
||||||
/* response time */
|
/* response time (if available) */
|
||||||
TextLabelResponseTime->setText(QString().
|
if ( Server.GetTimingStdDev ( dCurTiStdDev ) )
|
||||||
setNum(Server.GetTimingStdDev(), 'f', 2) + " ms");
|
{
|
||||||
|
TextLabelResponseTime->setText(QString().
|
||||||
|
setNum(dCurTiStdDev, 'f', 2) + " ms");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TextLabelResponseTime->setText("---");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLlconServerDlg::OnSliderNetBuf(int value)
|
void CLlconServerDlg::OnSliderNetBuf(int value)
|
||||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -34,25 +34,27 @@
|
||||||
QApplication* pApp = NULL;
|
QApplication* pApp = NULL;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
/* Application object */
|
/* Application object */
|
||||||
QApplication app(argc, argv);
|
QApplication app ( argc, argv );
|
||||||
|
|
||||||
/* check if server or client application shall be started */
|
/* check if server or client application shall be started */
|
||||||
bool bIsClient = true;
|
bool bIsClient = true;
|
||||||
|
|
||||||
/* QT docu: argv()[0] is the program name, argv()[1] is the first
|
/* QT docu: argv()[0] is the program name, argv()[1] is the first
|
||||||
argument and argv()[argc()-1] is the last argument */
|
argument and argv()[argc()-1] is the last argument */
|
||||||
if (argc > 1)
|
if ( argc > 1 )
|
||||||
{
|
{
|
||||||
/* only "-s" is supported right now */
|
/* only "-s" is supported right now */
|
||||||
std::string strShortOpt = "-s";
|
std::string strShortOpt = "-s";
|
||||||
if (!strShortOpt.compare(argv[1]))
|
if ( !strShortOpt.compare ( argv[1] ) )
|
||||||
bIsClient = false;
|
{
|
||||||
|
bIsClient = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bIsClient)
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
// actual client object
|
// actual client object
|
||||||
CClient Client;
|
CClient Client;
|
||||||
|
@ -98,7 +100,8 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam,
|
||||||
/* In case of simulation no events should be generated */
|
/* In case of simulation no events should be generated */
|
||||||
if ( pApp != NULL )
|
if ( pApp != NULL )
|
||||||
{
|
{
|
||||||
CLlconEvent* LlconEv = new CLlconEvent ( MessID, iMessageParam, iChanNum );
|
CLlconEvent* LlconEv =
|
||||||
|
new CLlconEvent ( MessID, iMessageParam, iChanNum );
|
||||||
|
|
||||||
/* Qt will delete the event object when done */
|
/* Qt will delete the event object when done */
|
||||||
QThread::postEvent ( pApp->mainWidget (), LlconEv );
|
QThread::postEvent ( pApp->mainWidget (), LlconEv );
|
||||||
|
|
31
src/protocol.cpp
Executable file
31
src/protocol.cpp
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
/******************************************************************************\
|
||||||
|
* Copyright (c) 2004-2006
|
||||||
|
*
|
||||||
|
* Author(s):
|
||||||
|
* Volker Fischer
|
||||||
|
*
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
\******************************************************************************/
|
||||||
|
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Implementation *************************************************************/
|
||||||
|
|
||||||
|
// TODO
|
63
src/protocol.h
Executable file
63
src/protocol.h
Executable file
|
@ -0,0 +1,63 @@
|
||||||
|
/******************************************************************************\
|
||||||
|
* Copyright (c) 2004-2006
|
||||||
|
*
|
||||||
|
* Author(s):
|
||||||
|
* Volker Fischer
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
\******************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_)
|
||||||
|
#define PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Classes ********************************************************************/
|
||||||
|
class CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CProtocol() {}
|
||||||
|
virtual ~CProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CServerProtocol : public CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CServerProtocol() {}
|
||||||
|
virtual ~CServerProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CClientProtocol : public CProtocol
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CClientProtocol() {}
|
||||||
|
virtual ~CClientProtocol() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* !defined(PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_) */
|
119
src/server.cpp
119
src/server.cpp
|
@ -38,76 +38,119 @@ CServer::CServer() : Socket(&ChannelSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::Start()
|
void CServer::Start()
|
||||||
{
|
{
|
||||||
/* start main timer */
|
if ( !IsRunning () )
|
||||||
Timer.start(BLOCK_DURATION_MS);
|
{
|
||||||
|
/* start main timer */
|
||||||
|
Timer.start(BLOCK_DURATION_MS);
|
||||||
|
|
||||||
/* init time for response time evaluation */
|
/* init time for response time evaluation */
|
||||||
TimeLastBlock = QTime::currentTime();
|
TimeLastBlock = QTime::currentTime();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServer::Stop()
|
||||||
|
{
|
||||||
|
/* stop main timer */
|
||||||
|
Timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
void CServer::OnTimer()
|
void CServer::OnTimer()
|
||||||
{
|
{
|
||||||
CVector<int> vecChanID;
|
CVector<int> vecChanID;
|
||||||
CVector<CVector<double> > vecvecdData(BLOCK_SIZE_SAMPLES);
|
CVector<CVector<double> > vecvecdData ( BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
/* get data from all connected clients */
|
/* get data from all connected clients */
|
||||||
ChannelSet.GetBlockAllConC(vecChanID, vecvecdData);
|
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
||||||
|
const int iNumClients = vecvecdData.Size ();
|
||||||
/* actual processing of audio data -> mix */
|
|
||||||
vecsSendData = ProcessData(vecvecdData);
|
/* Check if at least one client is connected. If not, stop server until
|
||||||
|
one client is connected */
|
||||||
/* get number of connected clients from vector size */
|
if ( iNumClients != 0 )
|
||||||
const int iNumClients = vecvecdData.Size();
|
|
||||||
|
|
||||||
/* send the same data to all connected clients */
|
|
||||||
for (int i = 0; i < iNumClients; i++)
|
|
||||||
{
|
{
|
||||||
Socket.SendPacket(ChannelSet.PrepSendPacket(vecChanID[i], vecsSendData),
|
/* actual processing of audio data -> mix */
|
||||||
ChannelSet.GetAddress(vecChanID[i]),
|
vecsSendData = ProcessData ( vecvecdData );
|
||||||
ChannelSet.GetTimeStampIdx(vecChanID[i]));
|
|
||||||
}
|
/* send the same data to all connected clients */
|
||||||
|
for ( int i = 0; i < iNumClients; i++ )
|
||||||
|
{
|
||||||
|
Socket.SendPacket (
|
||||||
|
ChannelSet.PrepSendPacket ( vecChanID[i], vecsSendData ),
|
||||||
|
ChannelSet.GetAddress ( vecChanID[i] ),
|
||||||
|
ChannelSet.GetTimeStampIdx ( vecChanID[i] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* update response time measurement ------------------------------------- */
|
/* update response time measurement --------------------------------- */
|
||||||
/* add time difference */
|
/* add time difference */
|
||||||
const QTime CurTime = QTime::currentTime();
|
const QTime CurTime = QTime::currentTime ();
|
||||||
|
|
||||||
/* we want to calculate the standard deviation (we assume that the mean is
|
/* we want to calculate the standard deviation (we assume that the mean
|
||||||
correct at the block period time) */
|
is correct at the block period time) */
|
||||||
const double dCurAddVal =
|
const double dCurAddVal =
|
||||||
((double) TimeLastBlock.msecsTo(CurTime) - BLOCK_DURATION_MS);
|
( (double) TimeLastBlock.msecsTo ( CurTime ) - 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;
|
TimeLastBlock = CurTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* disable server */
|
||||||
|
|
||||||
|
// TODO not yet working since the socket does not have access to the server
|
||||||
|
// object and cannot restart the server if packets arrive...
|
||||||
|
|
||||||
|
// Stop ();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CVector<short> CServer::ProcessData(CVector<CVector<double> >& vecvecdData)
|
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
|
||||||
{
|
{
|
||||||
CVector<short> vecsOutData;
|
CVector<short> vecsOutData;
|
||||||
vecsOutData.Init(BLOCK_SIZE_SAMPLES);
|
vecsOutData.Init ( BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
const int iNumClients = vecvecdData.Size();
|
const int iNumClients = vecvecdData.Size ();
|
||||||
|
|
||||||
/* we normalize with sqrt() of N to avoid that the level drops too much
|
/* we normalize with sqrt() of N to avoid that the level drops too much
|
||||||
in case that a new client connects */
|
in case that a new client connects */
|
||||||
const double dNorm = sqrt((double) iNumClients);
|
const double dNorm = sqrt ( (double) iNumClients );
|
||||||
|
|
||||||
/* mix all audio data from all clients together */
|
/* mix all audio data from all clients together */
|
||||||
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
|
for ( int i = 0; i < BLOCK_SIZE_SAMPLES; i++ )
|
||||||
{
|
{
|
||||||
double dMixedData = 0.0;
|
double dMixedData = 0.0;
|
||||||
|
|
||||||
for (int j = 0; j < iNumClients; j++)
|
for ( int j = 0; j < iNumClients; j++ )
|
||||||
{
|
{
|
||||||
dMixedData += vecvecdData[j][i];
|
dMixedData += vecvecdData[j][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* normalization and truncating to short */
|
/* normalization and truncating to short */
|
||||||
vecsOutData[i] = Double2Short(dMixedData / dNorm);
|
vecsOutData[i] = Double2Short ( dMixedData / dNorm );
|
||||||
}
|
}
|
||||||
|
|
||||||
return vecsOutData;
|
return vecsOutData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
|
||||||
|
{
|
||||||
|
dCurTiStdDev = 0.0; /* init return value */
|
||||||
|
|
||||||
|
/* only return value if server is active and the actual measurement is
|
||||||
|
updated */
|
||||||
|
if ( IsRunning () )
|
||||||
|
{
|
||||||
|
/* we want to return the standard deviation, for that we need to calculate
|
||||||
|
the sqaure root */
|
||||||
|
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage () );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
26
src/server.h
26
src/server.h
|
@ -42,23 +42,23 @@ class CServer : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CServer();
|
CServer ();
|
||||||
virtual ~CServer() {}
|
virtual ~CServer () {}
|
||||||
|
|
||||||
void Start();
|
void Start ();
|
||||||
void GetConCliParam(CVector<CHostAddress>& vecHostAddresses,
|
void Stop ();
|
||||||
CVector<double>& vecdSamOffs)
|
bool IsRunning() { return Timer.isActive (); }
|
||||||
{ChannelSet.GetConCliParam(vecHostAddresses, vecdSamOffs);}
|
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||||
|
CVector<double>& vecdSamOffs )
|
||||||
|
{ ChannelSet.GetConCliParam ( vecHostAddresses, vecdSamOffs ); }
|
||||||
|
|
||||||
/* we want to return the standard deviation. For that we need to calculate
|
bool GetTimingStdDev ( double& dCurTiStdDev );
|
||||||
the sqaure root */
|
|
||||||
double GetTimingStdDev() {return sqrt(RespTimeMoAvBuf.GetAverage());}
|
|
||||||
|
|
||||||
CChannelSet* GetChannelSet() {return &ChannelSet;}
|
CChannelSet* GetChannelSet () { return &ChannelSet; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CVector<short> ProcessData(CVector<CVector<double> >& vecvecdData);
|
CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData );
|
||||||
|
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
CVector<short> vecsSendData;
|
CVector<short> vecsSendData;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ protected:
|
||||||
QTime TimeLastBlock;
|
QTime TimeLastBlock;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnTimer();
|
void OnTimer ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,96 +26,104 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
void CSocket::Init()
|
void CSocket::Init ()
|
||||||
{
|
{
|
||||||
/* allocate memory for network receive and send buffer in samples */
|
/* allocate memory for network receive and send buffer in samples */
|
||||||
vecbyRecBuf.Init(MAX_SIZE_BYTES_NETW_BUF);
|
vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF );
|
||||||
|
|
||||||
/* initialize the listening socket */
|
/* initialize the listening socket */
|
||||||
bool bSuccess = SocketDevice.bind(
|
bool bSuccess = SocketDevice.bind (
|
||||||
QHostAddress((Q_UINT32) 0) /* INADDR_ANY */, LLCON_PORT_NUMBER);
|
QHostAddress ( (Q_UINT32) 0 ) /* INADDR_ANY */, LLCON_PORT_NUMBER );
|
||||||
|
|
||||||
if (bIsClient)
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
/* if no success, try if server is on same machine (only for client) */
|
/* if no success, try if server is on same machine (only for client) */
|
||||||
if (!bSuccess)
|
if ( !bSuccess )
|
||||||
{
|
{
|
||||||
/* if server and client is on same machine, decrease port number by
|
/* if server and client is on same machine, decrease port number by
|
||||||
one by definition */
|
one by definition */
|
||||||
bSuccess =
|
bSuccess = SocketDevice.bind (
|
||||||
SocketDevice.bind(QHostAddress((Q_UINT32) 0) /* INADDR_ANY */,
|
QHostAddress( (Q_UINT32) 0 ) /* INADDR_ANY */,
|
||||||
LLCON_PORT_NUMBER - 1);
|
LLCON_PORT_NUMBER - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bSuccess)
|
if ( !bSuccess )
|
||||||
{
|
{
|
||||||
/* show error message */
|
/* show error message */
|
||||||
QMessageBox::critical(0, "Network Error", "Cannot bind the socket.",
|
QMessageBox::critical ( 0, "Network Error", "Cannot bind the socket.",
|
||||||
QMessageBox::Ok, QMessageBox::NoButton);
|
QMessageBox::Ok, QMessageBox::NoButton );
|
||||||
|
|
||||||
/* exit application */
|
/* exit application */
|
||||||
exit(1);
|
exit ( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QSocketNotifier* pSocketNotivRead =
|
QSocketNotifier* pSocketNotivRead =
|
||||||
new QSocketNotifier(SocketDevice.socket(), QSocketNotifier::Read);
|
new QSocketNotifier ( SocketDevice.socket (), QSocketNotifier::Read );
|
||||||
|
|
||||||
/* connect the "activated" signal */
|
/* connect the "activated" signal */
|
||||||
QObject::connect(pSocketNotivRead, SIGNAL(activated(int)),
|
QObject::connect ( pSocketNotivRead, SIGNAL ( activated ( int ) ),
|
||||||
this, SLOT(OnDataReceived()));
|
this, SLOT ( OnDataReceived () ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSocket::SendPacket(const CVector<unsigned char>& vecbySendBuf,
|
void CSocket::SendPacket( const CVector<unsigned char>& vecbySendBuf,
|
||||||
const CHostAddress& HostAddr, const int iTimeStampIdx)
|
const CHostAddress& HostAddr,
|
||||||
|
const int iTimeStampIdx )
|
||||||
{
|
{
|
||||||
const int iVecSizeOut = vecbySendBuf.Size();
|
const int iVecSizeOut = vecbySendBuf.Size ();
|
||||||
|
|
||||||
if ( iVecSizeOut != 0 )
|
if ( iVecSizeOut != 0 )
|
||||||
{
|
{
|
||||||
/* send packet through network */
|
/* send packet through network */
|
||||||
SocketDevice.writeBlock ((const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
|
SocketDevice.writeBlock (
|
||||||
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort);
|
(const char*) &((CVector<unsigned char>) vecbySendBuf)[0],
|
||||||
|
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sent time stamp if required */
|
/* sent time stamp if required */
|
||||||
if (iTimeStampIdx != INVALID_TIME_STAMP_IDX)
|
if ( iTimeStampIdx != INVALID_TIME_STAMP_IDX )
|
||||||
{
|
{
|
||||||
/* Always one byte long */
|
/* Always one byte long */
|
||||||
SocketDevice.writeBlock((const char*) &iTimeStampIdx, 1,
|
SocketDevice.writeBlock ( (const char*) &iTimeStampIdx, 1,
|
||||||
HostAddr.InetAddr, HostAddr.iPort);
|
HostAddr.InetAddr, HostAddr.iPort );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSocket::OnDataReceived()
|
void CSocket::OnDataReceived ()
|
||||||
{
|
{
|
||||||
/* read block from network interface */
|
/* read block from network interface */
|
||||||
const int iNumBytesRead = SocketDevice.readBlock((char*) &vecbyRecBuf[0],
|
const int iNumBytesRead = SocketDevice.readBlock( (char*) &vecbyRecBuf[0],
|
||||||
MAX_SIZE_BYTES_NETW_BUF);
|
MAX_SIZE_BYTES_NETW_BUF);
|
||||||
|
|
||||||
/* check if an error occurred */
|
/* check if an error occurred */
|
||||||
if (iNumBytesRead < 0)
|
if ( iNumBytesRead < 0 )
|
||||||
return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* get host address of client */
|
/* get host address of client */
|
||||||
CHostAddress RecHostAddr(SocketDevice.peerAddress(),
|
CHostAddress RecHostAddr ( SocketDevice.peerAddress (),
|
||||||
SocketDevice.peerPort());
|
SocketDevice.peerPort () );
|
||||||
|
|
||||||
if (bIsClient)
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
/* client */
|
/* client */
|
||||||
/* check if packet comes from the server we want to connect */
|
/* check if packet comes from the server we want to connect */
|
||||||
if (!(pChannel->GetAddress() == RecHostAddr))
|
if ( ! ( pChannel->GetAddress () == RecHostAddr ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pChannel->PutData(vecbyRecBuf, iNumBytesRead))
|
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
|
||||||
PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_GREEN);
|
{
|
||||||
else
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN );
|
||||||
PostWinMessage(MS_JIT_BUF_PUT, MUL_COL_LED_RED);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* server */
|
/* server */
|
||||||
pChannelSet->PutData(vecbyRecBuf, iNumBytesRead, RecHostAddr);
|
pChannelSet->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/util.h
40
src/util.h
|
@ -29,7 +29,8 @@
|
||||||
#include <qpopupmenu.h>
|
#include <qpopupmenu.h>
|
||||||
#include <qwhatsthis.h>
|
#include <qwhatsthis.h>
|
||||||
#include <qtextview.h>
|
#include <qtextview.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
using namespace std; /* Because of the library: "vector" */
|
using namespace std; /* Because of the library: "vector" */
|
||||||
|
@ -376,6 +377,43 @@ protected:
|
||||||
double allpassCoefficient_;
|
double allpassCoefficient_;
|
||||||
double combCoefficient_[4];
|
double combCoefficient_[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Time conversion ---------------------------------------------------------- */
|
||||||
|
// needed for ping measurement
|
||||||
|
class CTimeConv
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// QTime to network time vector
|
||||||
|
static CVector<unsigned char> QTi2NetTi ( const QTime qTiIn )
|
||||||
|
{
|
||||||
|
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
|
||||||
|
CVector<unsigned char> veccNetTi ( 5 );
|
||||||
|
|
||||||
|
veccNetTi[0] = static_cast<unsigned char> ( qTiIn.hour () );
|
||||||
|
veccNetTi[1] = static_cast<unsigned char> ( qTiIn.minute () );
|
||||||
|
veccNetTi[2] = static_cast<unsigned char> ( qTiIn.second () );
|
||||||
|
|
||||||
|
const int iMs = qTiIn.msec ();
|
||||||
|
veccNetTi[3] = static_cast<unsigned char> ( ( iMs >> 8 ) & 255 );
|
||||||
|
veccNetTi[4] = static_cast<unsigned char> ( iMs & 255 );
|
||||||
|
|
||||||
|
return veccNetTi;
|
||||||
|
}
|
||||||
|
|
||||||
|
// network time vector to QTime
|
||||||
|
static QTime NetTi2QTi ( const CVector<unsigned char> netTiIn )
|
||||||
|
{
|
||||||
|
// vector format: 1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms
|
||||||
|
return QTime (
|
||||||
|
static_cast<int> ( netTiIn[0] ), // hour
|
||||||
|
static_cast<int> ( netTiIn[1] ), // minute
|
||||||
|
static_cast<int> ( netTiIn[2] ), // seconds
|
||||||
|
// msec
|
||||||
|
static_cast<int> ( ( netTiIn[3] << 8 ) | netTiIn[4] )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */
|
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */
|
||||||
|
|
|
@ -178,6 +178,10 @@ SOURCE=..\src\multicolorled.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\protocol.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\resample.cpp
|
SOURCE=..\src\resample.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@ -238,6 +242,10 @@ SOURCE=..\src\multicolorled.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\src\protocol.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\src\resample.h
|
SOURCE=..\src\resample.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
Loading…
Reference in a new issue