server runs on short blocks

This commit is contained in:
Volker Fischer 2006-02-17 21:08:05 +00:00
parent 6d226d0a24
commit 136fe90d4d
4 changed files with 66 additions and 56 deletions

View file

@ -31,37 +31,42 @@
int CChannelSet::GetFreeChan()
{
/* 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;
}
}
/* no free channel found, return invalid ID */
return INVALID_CHANNEL_ID;
}
int CChannelSet::CheckAddr(const CHostAddress& Addr)
int CChannelSet::CheckAddr ( const CHostAddress& Addr )
{
CHostAddress InetAddr;
/* 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 */
if (InetAddr == Addr)
if ( InetAddr == Addr )
{
return i;
}
}
}
/* IP not found, return invalid ID */
return INVALID_CHANNEL_ID;
}
bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
const int iNumBytesRead, const CHostAddress& HostAdr)
bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
const int iNumBytesRead,
const CHostAddress& HostAdr )
{
Mutex.lock ();
@ -106,64 +111,68 @@ bool CChannelSet::PutData(const CVector<unsigned char>& vecbyRecBuf,
return !bChanOK; /* return 1 if error */
}
void CChannelSet::GetBlockAllConC(CVector<int>& vecChanID,
CVector<CVector<double> >& vecvecdData)
void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
CVector<CVector<double> >& vecvecdData )
{
/* init temporal data vector and clear input buffers */
CVector<double> vecdData(BLOCK_SIZE_SAMPLES);
CVector<double> vecdData ( MIN_BLOCK_SIZE_SAMPLES );
vecChanID.Init(0);
vecvecdData.Init(0);
vecChanID.Init ( 0 );
vecvecdData.Init ( 0 );
/* make put and get calls thread safe. Do not forget to unlock mutex
afterwards! */
Mutex.lock();
Mutex.lock ();
/* 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
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 */
vecChanID.Add(i);
vecChanID.Add ( i );
const int iOldSize = vecvecdData.Size();
vecvecdData.Enlarge(1);
vecvecdData[iOldSize].Init(vecdData.Size());
const int iOldSize = vecvecdData.Size ();
vecvecdData.Enlarge ( 1 );
vecvecdData[iOldSize].Init ( vecdData.Size () );
vecvecdData[iOldSize] = vecdData;
/* send message for get status (for GUI) */
if (bGetOK)
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i);
if ( bGetOK )
{
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN, i );
}
else
PostWinMessage(MS_JIT_BUF_GET, MUL_COL_LED_RED, i);
{
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_RED, i );
}
}
}
Mutex.unlock(); /* release mutex */
Mutex.unlock (); /* release mutex */
}
void CChannelSet::GetConCliParam(CVector<CHostAddress>& vecHostAddresses,
CVector<double>& vecdSamOffs)
void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<double>& vecdSamOffs )
{
CHostAddress InetAddr;
/* init return values */
vecHostAddresses.Init(MAX_NUM_CHANNELS);
vecdSamOffs.Init(MAX_NUM_CHANNELS);
vecHostAddresses.Init ( MAX_NUM_CHANNELS );
vecdSamOffs.Init ( MAX_NUM_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 */
vecHostAddresses[i] = InetAddr;
vecdSamOffs[i] = vecChannels[i].GetResampleOffset();
vecdSamOffs[i] = vecChannels[i].GetResampleOffset ();
}
}
}
@ -195,7 +204,7 @@ CChannel::CChannel()
byTimeStampIdxCnt = 0;
/* 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 */
ConvBuf.Init ( BLOCK_SIZE_SAMPLES );

View file

@ -42,7 +42,7 @@
/* version and application name */
#ifndef VERSION
# define VERSION "0.9.2cvs"
# define VERSION "0.9.3cvs"
#endif
#define APP_NAME "llcon"
@ -72,14 +72,14 @@
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)
/* 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 */
#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
#ifdef _WIN32
# define AUD_SLIDER_LENGTH 15
# define AUD_SLIDER_LENGTH 30
#else
# define AUD_SLIDER_LENGTH 6
#endif

View file

@ -153,7 +153,7 @@ void CLlconServerDlg::OnTimer()
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));
}

View file

@ -26,39 +26,40 @@
/* 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 */
RespTimeMoAvBuf.Init(LEN_MOV_AV_RESPONSE);
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE );
/* 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 () )
{
/* start main timer */
Timer.start(BLOCK_DURATION_MS);
Timer.start ( MIN_BLOCK_DURATION_MS );
/* init time for response time evaluation */
TimeLastBlock = QTime::currentTime();
TimeLastBlock = QTime::currentTime ();
}
}
void CServer::Stop()
void CServer::Stop ()
{
/* stop main timer */
Timer.stop();
Timer.stop ();
}
void CServer::OnTimer()
void CServer::OnTimer ()
{
CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( BLOCK_SIZE_SAMPLES );
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
/* get data from all connected clients */
ChannelSet.GetBlockAllConC ( vecChanID, vecvecdData );
@ -87,8 +88,8 @@ void CServer::OnTimer()
/* 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 ) - BLOCK_DURATION_MS );
const double dCurAddVal = ( (double) TimeLastBlock.msecsTo ( CurTime ) -
MIN_BLOCK_DURATION_MS );
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */
@ -110,7 +111,7 @@ void CServer::OnTimer()
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
{
CVector<short> vecsOutData;
vecsOutData.Init ( BLOCK_SIZE_SAMPLES );
vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES );
const int iNumClients = vecvecdData.Size ();
@ -119,7 +120,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
const double dNorm = sqrt ( (double) iNumClients );
/* 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;