some changes to the sound interface, changed names of macros for network buffer sizes

This commit is contained in:
Volker Fischer 2006-10-30 20:35:46 +00:00
parent 25e275edce
commit ab24ff7d00
10 changed files with 93 additions and 41 deletions

View file

@ -127,6 +127,24 @@ bool CSound::Read(CVector<short>& psData)
ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn); ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn);
//snd_pcm_sframes_t test = snd_pcm_avail_update ( rhandle );
//qDebug ( "test: %d", test );
//if ( test == 64 )
// snd_pcm_prepare ( rhandle );
/*
snd_pcm_status( rhandle, status );
snd_pcm_sframes_t test = snd_pcm_status_get_delay(status);
//qDebug ( "test: %d", test );
*/
//static FILE* pFile = fopen("test.dat", "w");
//fprintf(pFile, "%d\n", test);
//fflush(pFile);
if ( ret < 0 ) if ( ret < 0 )
{ {
if ( ret == -EPIPE ) if ( ret == -EPIPE )
@ -312,6 +330,35 @@ bool CSound::Write ( CVector<short>& psData )
{ {
ret = snd_pcm_writei ( phandle, &psData[start], size ); ret = snd_pcm_writei ( phandle, &psData[start], size );
//snd_pcm_sframes_t test = snd_pcm_avail_update ( phandle );
//qDebug ( "test: %d", test );
//if ( test == 64 )
// snd_pcm_prepare ( rhandle );
/*
snd_pcm_sframes_t delayp;
snd_pcm_delay ( phandle, &delayp ) ;
qDebug ( "test: %d", delayp );
*/
//snd_pcm_status_t* status;
//snd_pcm_status_alloca(&status);
//snd_pcm_status( phandle, status );
//snd_pcm_sframes_t test = snd_pcm_status_get_delay(status);
//qDebug ( "test: %d", test );
//snd_pcm_status( phandle, status );
//snd_pcm_sframes_t test = snd_pcm_status_get_delay(status);
//qDebug ( "test: %d", test );
//static FILE* pFile = fopen("test.dat", "w");
//fprintf(pFile, "%d\n", test);
//fflush(pFile);
if ( ret < 0 ) if ( ret < 0 )
{ {
if ( ret == -EPIPE ) if ( ret == -EPIPE )

View file

@ -50,7 +50,7 @@ public:
iCurPeriodSizeOut(NUM_PERIOD_BLOCKS_OUT), bChangParamIn(true), iCurPeriodSizeOut(NUM_PERIOD_BLOCKS_OUT), bChangParamIn(true),
bChangParamOut(true) bChangParamOut(true)
#endif #endif
{} {snd_pcm_status_alloca(&status);}
virtual ~CSound() {Close();} virtual ~CSound() {Close();}
/* Not implemented yet, always return one device and default string */ /* Not implemented yet, always return one device and default string */
@ -88,6 +88,12 @@ protected:
int iCurPeriodSizeIn; int iCurPeriodSizeIn;
bool bChangParamOut; bool bChangParamOut;
int iCurPeriodSizeOut; int iCurPeriodSizeOut;
// TEST
snd_pcm_status_t* status;
#else #else
/* Dummy definitions */ /* Dummy definitions */
void SetInNumBuf(int iNewNum) {} void SetInNumBuf(int iNewNum) {}

View file

@ -230,7 +230,7 @@ CChannel::CChannel()
{ {
// query all possible network in buffer sizes for determining if an // query all possible network in buffer sizes for determining if an
// audio packet was received // audio packet was received
for ( int i = 0; i < NET_BLOCK_SIZE_FACTOR_MAX; i++ ) for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
// network block size factor must start from 1 -> ( i + 1 ) // network block size factor must start from 1 -> ( i + 1 )
vecNetwInBufSizes[i] = AudioCompressionIn.Init ( vecNetwInBufSizes[i] = AudioCompressionIn.Init (
@ -241,14 +241,14 @@ CChannel::CChannel()
/* init time stamp index counter */ /* init time stamp index counter */
byTimeStampIdxCnt = 0; byTimeStampIdxCnt = 0;
iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR; iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR;
/* init the socket buffer */ /* init the socket buffer */
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
// set initial input and output block size factors // set initial input and output block size factors
SetNetwBufSizeFactOut ( NET_BLOCK_SIZE_FACTOR ); SetNetwBufSizeFactOut ( iCurNetwInBlSiFact );
SetNetwInBlSiFact ( NET_BLOCK_SIZE_FACTOR ); SetNetwInBlSiFact ( iCurNetwInBlSiFact );
/* init time-out for the buffer with zero -> no connection */ /* init time-out for the buffer with zero -> no connection */
iConTimeOut = 0; iConTimeOut = 0;
@ -373,7 +373,7 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
bool bIsAudioPacket = false; bool bIsAudioPacket = false;
// check if this is an audio packet by checking all possible lengths // check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < NET_BLOCK_SIZE_FACTOR_MAX; i++ ) for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
if ( iNumBytes == vecNetwInBufSizes[i] ) if ( iNumBytes == vecNetwInBufSizes[i] )
{ {

View file

@ -142,7 +142,7 @@ protected:
int iConTimeOut; int iConTimeOut;
int iConTimeOutStartVal; int iConTimeOutStartVal;
int vecNetwInBufSizes[NET_BLOCK_SIZE_FACTOR_MAX]; int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR];
int iCurNetwInBlSiFact; int iCurNetwInBlSiFact;
int iCurNetwOutBlSiFact; int iCurNetwOutBlSiFact;

View file

@ -30,7 +30,7 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ),
iAudioInFader ( AUD_FADER_IN_MAX / 2 ), iAudioInFader ( AUD_FADER_IN_MAX / 2 ),
iReverbLevel ( AUD_REVERB_MAX / 6 ), iReverbLevel ( AUD_REVERB_MAX / 6 ),
bReverbOnLeftChan ( false ), bReverbOnLeftChan ( false ),
iNetwBufSizeFactIn ( NET_BLOCK_SIZE_FACTOR ) iNetwBufSizeFactIn ( DEF_NET_BLOCK_SIZE_FACTOR )
{ {
// connection for protocol // connection for protocol
QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),

View file

@ -63,12 +63,11 @@
#define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SAMPLE_RATE / 1000 ) #define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SAMPLE_RATE / 1000 )
#define MIN_SND_CRD_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 ) #define MIN_SND_CRD_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
/* first tests showed that with 24000 kHz a block time shorter than 5 ms leads to
much higher DSL network latencies. A length of 6 ms seems to be optimal */
#define NET_BLOCK_SIZE_FACTOR 3 // 3 * 2 ms = 6 ms
// maximum value of factor for network block size // maximum value of factor for network block size
#define NET_BLOCK_SIZE_FACTOR_MAX 8 #define MAX_NET_BLOCK_SIZE_FACTOR 8
/* default network block size factor */
#define DEF_NET_BLOCK_SIZE_FACTOR 3
/* 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 10 /* number of blocks */

View file

@ -99,7 +99,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf)); TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
/* network buffer size factor in */ /* network buffer size factor in */
SliderNetBufSiFactIn->setRange(1, NET_BLOCK_SIZE_FACTOR_MAX); SliderNetBufSiFactIn->setRange(1, MAX_NET_BLOCK_SIZE_FACTOR);
const int iCurNetBufSiFactIn = pClient->GetNetwBufSizeFactIn(); const int iCurNetBufSiFactIn = pClient->GetNetwBufSizeFactIn();
SliderNetBufSiFactIn->setValue(iCurNetBufSiFactIn); SliderNetBufSiFactIn->setValue(iCurNetBufSiFactIn);
TextNetBufSiFactIn->setText("In:\n" + QString().setNum( TextNetBufSiFactIn->setText("In:\n" + QString().setNum(
@ -107,7 +107,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
" ms"); " ms");
/* network buffer size factor out */ /* network buffer size factor out */
SliderNetBufSiFactOut->setRange(1, NET_BLOCK_SIZE_FACTOR_MAX); SliderNetBufSiFactOut->setRange(1, MAX_NET_BLOCK_SIZE_FACTOR);
const int iCurNetBufSiFactOut = pClient->GetNetwBufSizeFactOut(); const int iCurNetBufSiFactOut = pClient->GetNetwBufSizeFactOut();
SliderNetBufSiFactOut->setValue(iCurNetBufSiFactOut); SliderNetBufSiFactOut->setValue(iCurNetBufSiFactOut);
TextNetBufSiFactOut->setText("Out:\n" + QString().setNum( TextNetBufSiFactOut->setText("Out:\n" + QString().setNum(

View file

@ -26,7 +26,7 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CServer::CServer () : Socket ( &ChannelSet, this ) CServer::CServer() : Socket ( &ChannelSet, this )
{ {
vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES ); vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES );
@ -34,8 +34,8 @@ CServer::CServer () : Socket ( &ChannelSet, this )
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 () ), QObject::connect ( &Timer, SIGNAL ( timeout() ),
this, SLOT ( OnTimer () ) ); this, SLOT ( OnTimer() ) );
// connection for protocol // connection for protocol
QObject::connect ( &ChannelSet, QObject::connect ( &ChannelSet,
@ -45,7 +45,7 @@ CServer::CServer () : Socket ( &ChannelSet, this )
#ifdef _WIN32 #ifdef _WIN32
// event handling of custom events seems not to work under Windows in this // event handling of custom events seems not to work under Windows in this
// class, do not use automatic start/stop of server in Windows version // class, do not use automatic start/stop of server in Windows version
Start (); Start();
#endif #endif
} }
@ -53,7 +53,7 @@ void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
{ {
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t // convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () ); CVector<unsigned char> vecbyDataConv ( vecMessage.Size() );
for ( int i = 0; i < vecMessage.Size (); i++ ) { for ( int i = 0; i < vecMessage.Size (); i++ ) {
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] ); vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
} }
@ -63,27 +63,27 @@ for ( int i = 0; i < vecMessage.Size (); i++ ) {
Socket.SendPacket ( vecbyDataConv, ChannelSet.GetAddress ( iChID ) ); Socket.SendPacket ( vecbyDataConv, ChannelSet.GetAddress ( iChID ) );
} }
void CServer::Start () void CServer::Start()
{ {
if ( !IsRunning () ) if ( !IsRunning() )
{ {
/* start main timer */ /* start main timer */
Timer.start ( MIN_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();
qDebug ( CLogTimeDate::toString() + "Server stopped" ); qDebug ( CLogTimeDate::toString() + "Server stopped" );
} }
void CServer::OnTimer () void CServer::OnTimer()
{ {
CVector<int> vecChanID; CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES ); CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
@ -129,7 +129,7 @@ void CServer::OnTimer ()
#ifndef _WIN32 #ifndef _WIN32
// event handling of custom events seems not to work under Windows in this // event handling of custom events seems not to work under Windows in this
// class, do not use automatic start/stop of server in Windows version // class, do not use automatic start/stop of server in Windows version
Stop (); Stop();
#endif #endif
} }
} }
@ -139,7 +139,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
CVector<short> vecsOutData; CVector<short> vecsOutData;
vecsOutData.Init ( MIN_BLOCK_SIZE_SAMPLES ); vecsOutData.Init ( MIN_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 */
@ -168,11 +168,11 @@ bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
/* only return value if server is active and the actual measurement is /* only return value if server is active and the actual measurement is
updated */ updated */
if ( IsRunning () ) if ( IsRunning() )
{ {
/* we want to return the standard deviation, for that we need to calculate /* we want to return the standard deviation, for that we need to calculate
the sqaure root */ the sqaure root */
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage () ); dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage() );
return true; return true;
} }
@ -182,19 +182,19 @@ bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
} }
} }
void CServer::customEvent(QCustomEvent* Event) void CServer::customEvent ( QCustomEvent* Event )
{ {
if (Event->type() == QEvent::User + 11) if ( Event->type() == QEvent::User + 11 )
{ {
const int iMessType = ((CLlconEvent*) Event)->iMessType; const int iMessType = ( ( CLlconEvent* ) Event )->iMessType;
switch(iMessType) switch ( iMessType )
{ {
case MS_PACKET_RECEIVED: case MS_PACKET_RECEIVED:
// wake up the server if a packet was received // wake up the server if a packet was received
// if the server is still running, the call to Start() will have // if the server is still running, the call to Start() will have
// no effect // no effect
Start (); Start();
break; break;
} }
} }

View file

@ -83,12 +83,12 @@ void CSettings::ReadIniFile()
} }
// network buffer size factor in // network buffer size factor in
if ( GetNumericIniSet(ini, "Client", "netwbusifactin", 1, NET_BLOCK_SIZE_FACTOR_MAX, iValue ) == TRUE ) { if ( GetNumericIniSet(ini, "Client", "netwbusifactin", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE ) {
pClient->SetNetwBufSizeFactIn ( iValue ); pClient->SetNetwBufSizeFactIn ( iValue );
} }
// network buffer size factor out // network buffer size factor out
if ( GetNumericIniSet(ini, "Client", "netwbusifactout", 1, NET_BLOCK_SIZE_FACTOR_MAX, iValue ) == TRUE ) { if ( GetNumericIniSet(ini, "Client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE ) {
pClient->SetNetwBufSizeFactOut ( iValue ); pClient->SetNetwBufSizeFactOut ( iValue );
} }
} }

View file

@ -38,7 +38,7 @@
/* Definitions ****************************************************************/ /* Definitions ****************************************************************/
/* maximum block size for network input buffer. Consider two bytes per sample */ /* maximum block size for network input buffer. Consider two bytes per sample */
#define MAX_SIZE_BYTES_NETW_BUF ( NET_BLOCK_SIZE_FACTOR_MAX * MIN_BLOCK_SIZE_SAMPLES * 2 ) #define MAX_SIZE_BYTES_NETW_BUF ( MAX_NET_BLOCK_SIZE_FACTOR * MIN_BLOCK_SIZE_SAMPLES * 2 )
/* Classes ********************************************************************/ /* Classes ********************************************************************/