some changes to the sound interface, changed names of macros for network buffer sizes
This commit is contained in:
parent
25e275edce
commit
ab24ff7d00
10 changed files with 93 additions and 41 deletions
|
@ -125,7 +125,25 @@ bool CSound::Read(CVector<short>& psData)
|
|||
bChangParamIn = false;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -311,6 +329,35 @@ bool CSound::Write ( CVector<short>& psData )
|
|||
while ( 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 )
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
iCurPeriodSizeOut(NUM_PERIOD_BLOCKS_OUT), bChangParamIn(true),
|
||||
bChangParamOut(true)
|
||||
#endif
|
||||
{}
|
||||
{snd_pcm_status_alloca(&status);}
|
||||
virtual ~CSound() {Close();}
|
||||
|
||||
/* Not implemented yet, always return one device and default string */
|
||||
|
@ -87,7 +87,13 @@ protected:
|
|||
bool bChangParamIn;
|
||||
int iCurPeriodSizeIn;
|
||||
bool bChangParamOut;
|
||||
int iCurPeriodSizeOut;
|
||||
int iCurPeriodSizeOut;
|
||||
|
||||
|
||||
// TEST
|
||||
snd_pcm_status_t* status;
|
||||
|
||||
|
||||
#else
|
||||
/* Dummy definitions */
|
||||
void SetInNumBuf(int iNewNum) {}
|
||||
|
|
|
@ -230,7 +230,7 @@ CChannel::CChannel()
|
|||
{
|
||||
// query all possible network in buffer sizes for determining if an
|
||||
// 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 )
|
||||
vecNetwInBufSizes[i] = AudioCompressionIn.Init (
|
||||
|
@ -241,14 +241,14 @@ CChannel::CChannel()
|
|||
/* init time stamp index counter */
|
||||
byTimeStampIdxCnt = 0;
|
||||
|
||||
iCurNetwInBlSiFact = NET_BLOCK_SIZE_FACTOR;
|
||||
iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR;
|
||||
|
||||
/* init the socket buffer */
|
||||
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
|
||||
|
||||
// set initial input and output block size factors
|
||||
SetNetwBufSizeFactOut ( NET_BLOCK_SIZE_FACTOR );
|
||||
SetNetwInBlSiFact ( NET_BLOCK_SIZE_FACTOR );
|
||||
SetNetwBufSizeFactOut ( iCurNetwInBlSiFact );
|
||||
SetNetwInBlSiFact ( iCurNetwInBlSiFact );
|
||||
|
||||
/* init time-out for the buffer with zero -> no connection */
|
||||
iConTimeOut = 0;
|
||||
|
@ -373,7 +373,7 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
|||
bool bIsAudioPacket = false;
|
||||
|
||||
// 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] )
|
||||
{
|
||||
|
|
|
@ -142,7 +142,7 @@ protected:
|
|||
int iConTimeOut;
|
||||
int iConTimeOutStartVal;
|
||||
|
||||
int vecNetwInBufSizes[NET_BLOCK_SIZE_FACTOR_MAX];
|
||||
int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR];
|
||||
|
||||
int iCurNetwInBlSiFact;
|
||||
int iCurNetwOutBlSiFact;
|
||||
|
|
|
@ -30,7 +30,7 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ),
|
|||
iAudioInFader ( AUD_FADER_IN_MAX / 2 ),
|
||||
iReverbLevel ( AUD_REVERB_MAX / 6 ),
|
||||
bReverbOnLeftChan ( false ),
|
||||
iNetwBufSizeFactIn ( NET_BLOCK_SIZE_FACTOR )
|
||||
iNetwBufSizeFactIn ( DEF_NET_BLOCK_SIZE_FACTOR )
|
||||
{
|
||||
// connection for protocol
|
||||
QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
||||
|
|
11
src/global.h
11
src/global.h
|
@ -63,16 +63,15 @@
|
|||
#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 )
|
||||
|
||||
/* 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
|
||||
#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) */
|
||||
#define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */
|
||||
|
||||
|
||||
/* default network buffer size */
|
||||
#define DEF_NET_BUF_SIZE_NUM_BL 5 /* number of blocks */
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
|||
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
|
||||
|
||||
/* 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();
|
||||
SliderNetBufSiFactIn->setValue(iCurNetBufSiFactIn);
|
||||
TextNetBufSiFactIn->setText("In:\n" + QString().setNum(
|
||||
|
@ -107,7 +107,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
|||
" ms");
|
||||
|
||||
/* 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();
|
||||
SliderNetBufSiFactOut->setValue(iCurNetBufSiFactOut);
|
||||
TextNetBufSiFactOut->setText("Out:\n" + QString().setNum(
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
|
||||
/* Implementation *************************************************************/
|
||||
CServer::CServer () : Socket ( &ChannelSet, this )
|
||||
CServer::CServer() : Socket ( &ChannelSet, this )
|
||||
{
|
||||
vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES );
|
||||
|
||||
|
@ -34,8 +34,8 @@ CServer::CServer () : Socket ( &ChannelSet, this )
|
|||
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() ) );
|
||||
|
||||
// connection for protocol
|
||||
QObject::connect ( &ChannelSet,
|
||||
|
@ -45,7 +45,7 @@ CServer::CServer () : Socket ( &ChannelSet, this )
|
|||
#ifdef _WIN32
|
||||
// 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
|
||||
Start ();
|
||||
Start();
|
||||
#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
|
||||
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () );
|
||||
CVector<unsigned char> vecbyDataConv ( vecMessage.Size() );
|
||||
for ( int i = 0; i < vecMessage.Size (); 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 ) );
|
||||
}
|
||||
|
||||
void CServer::Start ()
|
||||
void CServer::Start()
|
||||
{
|
||||
if ( !IsRunning () )
|
||||
if ( !IsRunning() )
|
||||
{
|
||||
/* start main timer */
|
||||
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();
|
||||
|
||||
qDebug ( CLogTimeDate::toString() + "Server stopped" );
|
||||
}
|
||||
|
||||
void CServer::OnTimer ()
|
||||
void CServer::OnTimer()
|
||||
{
|
||||
CVector<int> vecChanID;
|
||||
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
|
||||
|
@ -129,7 +129,7 @@ void CServer::OnTimer ()
|
|||
#ifndef _WIN32
|
||||
// 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
|
||||
Stop ();
|
||||
Stop();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData )
|
|||
CVector<short> vecsOutData;
|
||||
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
|
||||
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
|
||||
updated */
|
||||
if ( IsRunning () )
|
||||
if ( IsRunning() )
|
||||
{
|
||||
/* we want to return the standard deviation, for that we need to calculate
|
||||
the sqaure root */
|
||||
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage () );
|
||||
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage() );
|
||||
|
||||
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:
|
||||
// wake up the server if a packet was received
|
||||
// if the server is still running, the call to Start() will have
|
||||
// no effect
|
||||
Start ();
|
||||
Start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,12 +83,12 @@ void CSettings::ReadIniFile()
|
|||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
/* Definitions ****************************************************************/
|
||||
/* 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 ********************************************************************/
|
||||
|
|
Loading…
Reference in a new issue