server runs on short blocks
This commit is contained in:
parent
6d226d0a24
commit
136fe90d4d
4 changed files with 66 additions and 56 deletions
|
@ -31,28 +31,32 @@
|
||||||
int CChannelSet::GetFreeChan()
|
int CChannelSet::GetFreeChan()
|
||||||
{
|
{
|
||||||
/* look for a free channel */
|
/* look for a free channel */
|
||||||
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
if (!vecChannels[i].IsConnected())
|
if ( !vecChannels[i].IsConnected () )
|
||||||
return i;
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no free channel found, return invalid ID */
|
/* no free channel found, return invalid ID */
|
||||||
return INVALID_CHANNEL_ID;
|
return INVALID_CHANNEL_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CChannelSet::CheckAddr(const CHostAddress& Addr)
|
int CChannelSet::CheckAddr ( const CHostAddress& Addr )
|
||||||
{
|
{
|
||||||
CHostAddress InetAddr;
|
CHostAddress InetAddr;
|
||||||
|
|
||||||
/* Check for all possible channels if IP is already in use */
|
/* Check for all possible channels if IP is already in use */
|
||||||
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
if (vecChannels[i].GetAddress(InetAddr))
|
if ( vecChannels[i].GetAddress ( InetAddr ) )
|
||||||
{
|
{
|
||||||
/* IP found, return channel number */
|
/* IP found, return channel number */
|
||||||
if (InetAddr == Addr)
|
if ( InetAddr == Addr )
|
||||||
return i;
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +64,9 @@ int CChannelSet::CheckAddr(const CHostAddress& Addr)
|
||||||
return INVALID_CHANNEL_ID;
|
return INVALID_CHANNEL_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ();
|
||||||
|
|
||||||
|
@ -106,64 +111,68 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
|
||||||
return !bChanOK; /* return 1 if error */
|
return !bChanOK; /* return 1 if error */
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannelSet::GetBlockAllConC(CVector<int>& vecChanID,
|
void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
|
||||||
CVector<CVector<double> >& vecvecdData)
|
CVector<CVector<double> >& vecvecdData )
|
||||||
{
|
{
|
||||||
/* init temporal data vector and clear input buffers */
|
/* init temporal data vector and clear input buffers */
|
||||||
CVector<double> vecdData(BLOCK_SIZE_SAMPLES);
|
CVector<double> vecdData ( MIN_BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
vecChanID.Init(0);
|
vecChanID.Init ( 0 );
|
||||||
vecvecdData.Init(0);
|
vecvecdData.Init ( 0 );
|
||||||
|
|
||||||
/* make put and get calls thread safe. Do not forget to unlock mutex
|
/* make put and get calls thread safe. Do not forget to unlock mutex
|
||||||
afterwards! */
|
afterwards! */
|
||||||
Mutex.lock();
|
Mutex.lock ();
|
||||||
|
|
||||||
/* Check all possible channels */
|
/* Check all possible channels */
|
||||||
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
/* read out all input buffers to decrease timeout counter on
|
/* read out all input buffers to decrease timeout counter on
|
||||||
disconnected channels */
|
disconnected channels */
|
||||||
bool bGetOK = vecChannels[i].GetData(vecdData);
|
const bool bGetOK = vecChannels[i].GetData ( vecdData );
|
||||||
|
|
||||||
if (vecChannels[i].IsConnected())
|
if ( vecChannels[i].IsConnected () )
|
||||||
{
|
{
|
||||||
/* add ID and data */
|
/* add ID and data */
|
||||||
vecChanID.Add(i);
|
vecChanID.Add ( i );
|
||||||
|
|
||||||
const int iOldSize = vecvecdData.Size();
|
const int iOldSize = vecvecdData.Size ();
|
||||||
vecvecdData.Enlarge(1);
|
vecvecdData.Enlarge ( 1 );
|
||||||
vecvecdData[iOldSize].Init(vecdData.Size());
|
vecvecdData[iOldSize].Init ( vecdData.Size () );
|
||||||
vecvecdData[iOldSize] = vecdData;
|
vecvecdData[iOldSize] = vecdData;
|
||||||
|
|
||||||
/* send message for get status (for GUI) */
|
/* send message for get status (for GUI) */
|
||||||
if (bGetOK)
|
if ( bGetOK )
|
||||||
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i);
|
{
|
||||||
else
|
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i );
|
||||||
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_RED, i);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED, i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex.unlock(); /* release mutex */
|
Mutex.unlock (); /* release mutex */
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChannelSet::GetConCliParam(CVector<CHostAddress>& vecHostAddresses,
|
void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||||
CVector<double>& vecdSamOffs)
|
CVector<double>& vecdSamOffs )
|
||||||
{
|
{
|
||||||
CHostAddress InetAddr;
|
CHostAddress InetAddr;
|
||||||
|
|
||||||
/* init return values */
|
/* init return values */
|
||||||
vecHostAddresses.Init(MAX_NUM_CHANNELS);
|
vecHostAddresses.Init ( MAX_NUM_CHANNELS );
|
||||||
vecdSamOffs.Init(MAX_NUM_CHANNELS);
|
vecdSamOffs.Init ( MAX_NUM_CHANNELS );
|
||||||
|
|
||||||
/* Check all possible channels */
|
/* Check all possible channels */
|
||||||
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
|
||||||
{
|
{
|
||||||
if (vecChannels[i].GetAddress(InetAddr))
|
if ( vecChannels[i].GetAddress ( InetAddr ) )
|
||||||
{
|
{
|
||||||
/* add new address and sample rate offset to vectors */
|
/* add new address and sample rate offset to vectors */
|
||||||
vecHostAddresses[i] = InetAddr;
|
vecHostAddresses[i] = InetAddr;
|
||||||
vecdSamOffs[i] = vecChannels[i].GetResampleOffset();
|
vecdSamOffs[i] = vecChannels[i].GetResampleOffset ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +204,7 @@ CChannel::CChannel()
|
||||||
byTimeStampIdxCnt = 0;
|
byTimeStampIdxCnt = 0;
|
||||||
|
|
||||||
/* init the socket buffer */
|
/* init the socket buffer */
|
||||||
SetSockBufSize ( BLOCK_SIZE_SAMPLES, DEF_NET_BUF_SIZE_NUM_BL );
|
SetSockBufSize ( MIN_BLOCK_SIZE_SAMPLES, DEF_NET_BUF_SIZE_NUM_BL );
|
||||||
|
|
||||||
/* init conversion buffer */
|
/* init conversion buffer */
|
||||||
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );
|
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
/* version and application name */
|
/* version and application name */
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
# define VERSION "0.9.2cvs"
|
# define VERSION "0.9.3cvs"
|
||||||
#endif
|
#endif
|
||||||
#define APP_NAME "llcon"
|
#define APP_NAME "llcon"
|
||||||
|
|
||||||
|
@ -72,14 +72,14 @@
|
||||||
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)
|
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)
|
||||||
|
|
||||||
/* maximum network buffer size (which can be chosen by slider) */
|
/* maximum network buffer size (which can be chosen by slider) */
|
||||||
#define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */
|
#define MAX_NET_BUF_SIZE_NUM_BL 12 /* number of blocks */
|
||||||
|
|
||||||
/* default network buffer size */
|
/* default network buffer size */
|
||||||
#define DEF_NET_BUF_SIZE_NUM_BL 2 /* number of blocks */
|
#define DEF_NET_BUF_SIZE_NUM_BL 5 /* number of blocks */
|
||||||
|
|
||||||
// number of ticks of audio in/out buffer sliders
|
// number of ticks of audio in/out buffer sliders
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define AUD_SLIDER_LENGTH 15
|
# define AUD_SLIDER_LENGTH 30
|
||||||
#else
|
#else
|
||||||
# define AUD_SLIDER_LENGTH 6
|
# define AUD_SLIDER_LENGTH 6
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -153,7 +153,7 @@ void CLlconServerDlg::OnTimer()
|
||||||
|
|
||||||
void CLlconServerDlg::OnSliderNetBuf(int value)
|
void CLlconServerDlg::OnSliderNetBuf(int value)
|
||||||
{
|
{
|
||||||
pServer->GetChannelSet()->SetSockBufSize( BLOCK_SIZE_SAMPLES, value );
|
pServer->GetChannelSet()->SetSockBufSize( MIN_BLOCK_SIZE_SAMPLES, value );
|
||||||
TextNetBuf->setText("Size: " + QString().setNum(value));
|
TextNetBuf->setText("Size: " + QString().setNum(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,39 +26,40 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CServer::CServer() : Socket(&ChannelSet)
|
CServer::CServer () : Socket ( &ChannelSet )
|
||||||
{
|
{
|
||||||
vecsSendData.Init(BLOCK_SIZE_SAMPLES);
|
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);
|
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE );
|
||||||
|
|
||||||
/* connect timer timeout signal */
|
/* connect timer timeout signal */
|
||||||
QObject::connect(&Timer, SIGNAL(timeout()), this, SLOT(OnTimer()));
|
QObject::connect ( &Timer, SIGNAL ( timeout () ),
|
||||||
|
this, SLOT ( OnTimer () ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::Start()
|
void CServer::Start ()
|
||||||
{
|
{
|
||||||
if ( !IsRunning () )
|
if ( !IsRunning () )
|
||||||
{
|
{
|
||||||
/* start main timer */
|
/* start main timer */
|
||||||
Timer.start(BLOCK_DURATION_MS);
|
Timer.start ( MIN_BLOCK_DURATION_MS );
|
||||||
|
|
||||||
/* init time for response time evaluation */
|
/* init time for response time evaluation */
|
||||||
TimeLastBlock = QTime::currentTime();
|
TimeLastBlock = QTime::currentTime ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::Stop()
|
void CServer::Stop ()
|
||||||
{
|
{
|
||||||
/* stop main timer */
|
/* stop main timer */
|
||||||
Timer.stop();
|
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 ( MIN_BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
/* get data from all connected clients */
|
/* get data from all connected clients */
|
||||||
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
|
||||||
|
@ -87,8 +88,8 @@ void CServer::OnTimer()
|
||||||
|
|
||||||
/* we want to calculate the standard deviation (we assume that the mean
|
/* we want to calculate the standard deviation (we assume that the mean
|
||||||
is correct at the block period time) */
|
is correct at the block period time) */
|
||||||
const double dCurAddVal =
|
const double dCurAddVal = ( (double) TimeLastBlock.msecsTo ( CurTime ) -
|
||||||
( (double) TimeLastBlock.msecsTo ( CurTime ) - BLOCK_DURATION_MS );
|
MIN_BLOCK_DURATION_MS );
|
||||||
|
|
||||||
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */
|
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ void CServer::OnTimer()
|
||||||
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 ( MIN_BLOCK_SIZE_SAMPLES );
|
||||||
|
|
||||||
const int iNumClients = vecvecdData.Size ();
|
const int iNumClients = vecvecdData.Size ();
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
|
||||||
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 < MIN_BLOCK_SIZE_SAMPLES; i++ )
|
||||||
{
|
{
|
||||||
double dMixedData = 0.0;
|
double dMixedData = 0.0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue