go back to original version

This commit is contained in:
Volker Fischer 2008-08-05 20:59:01 +00:00
parent 91f7ef489a
commit 5fe78dda7d
7 changed files with 38 additions and 94 deletions

View File

@ -32,7 +32,7 @@
/* Definitions ****************************************************************/ /* Definitions ****************************************************************/
// time for fading effect for masking drop outs // time for fading effect for masking drop outs
#define FADE_IN_OUT_TIME ( (double) 0.3 ) // ms #define FADE_IN_OUT_TIME ( (double) 0.3 ) // ms
#define FADE_IN_OUT_NUM_SAM ( (int) ( SERVER_SAMPLE_RATE * FADE_IN_OUT_TIME ) / 1000 ) #define FADE_IN_OUT_NUM_SAM ( (int) ( SYSTEM_SAMPLE_RATE * FADE_IN_OUT_TIME ) / 1000 )
// for extrapolation a shorter time for fading // for extrapolation a shorter time for fading
#define FADE_IN_OUT_NUM_SAM_EXTRA 5 // samples #define FADE_IN_OUT_NUM_SAM_EXTRA 5 // samples

View File

@ -47,12 +47,12 @@ CChannelSet::CChannelSet()
QObject::connect ( &vecChannels[5], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh5 ( CVector<uint8_t> ) ) ); QObject::connect ( &vecChannels[5], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh5 ( CVector<uint8_t> ) ) );
// request jitter buffer size // request jitter buffer size
QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh0() ) ); QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh0() ) );
QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh1() ) ); QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh1() ) );
QObject::connect ( &vecChannels[2], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh2() ) ); QObject::connect ( &vecChannels[2], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh2() ) );
QObject::connect ( &vecChannels[3], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh3() ) ); QObject::connect ( &vecChannels[3], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh3() ) );
QObject::connect ( &vecChannels[4], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh4() ) ); QObject::connect ( &vecChannels[4], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh4() ) );
QObject::connect ( &vecChannels[5], SIGNAL ( NewConnection()), this, SLOT ( OnNewConnectionCh5() ) ); QObject::connect ( &vecChannels[5], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh5() ) );
// request connected clients list // request connected clients list
QObject::connect ( &vecChannels[0], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh0() ) ); QObject::connect ( &vecChannels[0], SIGNAL ( ReqConnClientsList() ), this, SLOT ( OnReqConnClientsListCh0() ) );
@ -433,25 +433,15 @@ CChannel::CChannel() : sName ( "" ),
iCurNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR ) iCurNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
{ {
// 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, consider all possible sample rates (audio // audio packet was received
// quality types: low quality, high quality)
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; 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 )
// low quality audio vecNetwInBufSizes[i] = AudioCompressionIn.Init (
vecNetwInBufSizesAudLQ[i] = AudioCompressionInLowQSampRate.Init (
( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES, ( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM ); CAudioCompression::CT_IMAADPCM );
// high quality audio
vecNetwInBufSizesAudHQ[i] = AudioCompressionInHighQSampRate.Init (
( i + 1 ) * MIN_SERVER_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
} }
// set initial minimum block size value (default)
SetMinBlockSize ( MIN_BLOCK_SIZE_SAMPLES );
// init the socket buffer // init the socket buffer
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
@ -501,20 +491,6 @@ CChannel::CChannel() : sName ( "" ),
this, SIGNAL ( PingReceived ( QTime ) ) ); this, SIGNAL ( PingReceived ( QTime ) ) );
} }
void CChannel::SetMinBlockSize ( const int iNewMinBlockSize )
{
// store new parameter
iCurMinBlockSize = iNewMinBlockSize;
// TODO init dependencies on minimum block size here!!!
}
void CChannel::SetEnable ( const bool bNEnStat ) void CChannel::SetEnable ( const bool bNEnStat )
{ {
// set internal parameter // set internal parameter
@ -532,15 +508,11 @@ void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor )
// store new value // store new value
iCurNetwInBlSiFact = iNewBlockSizeFactor; iCurNetwInBlSiFact = iNewBlockSizeFactor;
// init audio compression units // init audio compression unit
AudioCompressionInLowQSampRate.Init ( AudioCompressionIn.Init (
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES, iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM ); CAudioCompression::CT_IMAADPCM );
AudioCompressionInHighQSampRate.Init (
iNewBlockSizeFactor * MIN_SERVER_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
// initial value for connection time out counter // initial value for connection time out counter
iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) / iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) /
( iNewBlockSizeFactor * MIN_BLOCK_DURATION_MS ); ( iNewBlockSizeFactor * MIN_BLOCK_DURATION_MS );
@ -655,9 +627,7 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// init flags // init flags
bool bIsProtocolPacket = false; bool bIsProtocolPacket = false;
bool bIsAudioPacket = false; bool bIsAudioPacket = false;
bool bIsHQAudioPacket = false; // is high quality audio packet (high sample rate)
bool bNewConnection = false; bool bNewConnection = false;
int iInputBlockSizeFactor;
if ( bIsEnabled ) if ( bIsEnabled )
{ {
@ -684,40 +654,27 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ ) for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
// check for low/high quality audio packets and set flags // check for low/high quality audio packets and set flags
if ( iNumBytes == vecNetwInBufSizesAudLQ[i] ) if ( iNumBytes == vecNetwInBufSizes[i] )
{ {
bIsAudioPacket = true; bIsAudioPacket = true;
bIsHQAudioPacket = false;
iInputBlockSizeFactor = i + 1;
}
if ( iNumBytes == vecNetwInBufSizesAudHQ[i] ) // check if we are correctly initialized
{ const int iNewNetwInBlSiFact = i + 1;
bIsAudioPacket = true; if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
bIsHQAudioPacket = true; {
iInputBlockSizeFactor = i + 1; // re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
}
} }
} }
// only process if packet has correct size // only process if packet has correct size
if ( bIsAudioPacket ) if ( bIsAudioPacket )
{ {
// check if we are correctly initialized
if ( iInputBlockSizeFactor != iCurNetwInBlSiFact )
{
// re-initialize to new value
SetNetwInBlSiFact ( iInputBlockSizeFactor );
}
Mutex.lock(); Mutex.lock();
{ {
// TODO use bIsHQAudioPacket
// decompress audio // decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionInHighQSampRate.Decode ( vecbyData ) ); CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( 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
@ -726,7 +683,7 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i]; vecdResInData[i] = (double) vecsData[i];
const int iInSize = ResampleObj.Resample(vecdResInData, vecdResOutData, const int iInSize = ResampleObj.Resample(vecdResInData, vecdResOutData,
(double) SERVER_SAMPLE_RATE / (SERVER_SAMPLE_RATE - dSamRateOffset)); (double) SYSTEM_SAMPLE_RATE / (SYSTEM_SAMPLE_RATE - dSamRateOffset));
*/ */
vecdResOutData.Init ( iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES ); vecdResOutData.Init ( iCurNetwInBlSiFact * MIN_BLOCK_SIZE_SAMPLES );

View File

@ -99,9 +99,6 @@ public:
void SetRemoteChanGain ( const int iId, const double dGain ) void SetRemoteChanGain ( const int iId, const double dGain )
{ Protocol.CreateChanGainMes ( iId, dGain ); } { Protocol.CreateChanGainMes ( iId, dGain ); }
void SetMinBlockSize ( const int iNewMinBlockSize );
int GetMinBlockSize() { return iCurMinBlockSize; }
void SetSockBufSize ( const int iNumBlocks ); void SetSockBufSize ( const int iNumBlocks );
int GetSockBufSize() { return iCurSockBufSize; } int GetSockBufSize() { return iCurSockBufSize; }
@ -140,8 +137,7 @@ protected:
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor ); void SetNetwInBlSiFact ( const int iNewBlockSizeFactor );
// audio compression // audio compression
CAudioCompression AudioCompressionInLowQSampRate; CAudioCompression AudioCompressionIn;
CAudioCompression AudioCompressionInHighQSampRate;
CAudioCompression AudioCompressionOut; CAudioCompression AudioCompressionOut;
int iAudComprSizeOut; int iAudComprSizeOut;
@ -175,10 +171,7 @@ protected:
bool bIsEnabled; bool bIsEnabled;
int vecNetwInBufSizesAudLQ[MAX_NET_BLOCK_SIZE_FACTOR]; int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR];
int vecNetwInBufSizesAudHQ[MAX_NET_BLOCK_SIZE_FACTOR];
int iCurMinBlockSize;
int iCurNetwInBlSiFact; int iCurNetwInBlSiFact;
int iCurNetwOutBlSiFact; int iCurNetwOutBlSiFact;

View File

@ -173,12 +173,12 @@ void CClient::Init()
// resample objects are always initialized with the input block size // resample objects are always initialized with the input block size
// record // record
ResampleObjDownL.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SERVER_SAMPLE_RATE ); ResampleObjDownL.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SYSTEM_SAMPLE_RATE );
ResampleObjDownR.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SERVER_SAMPLE_RATE ); ResampleObjDownR.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SYSTEM_SAMPLE_RATE );
// playback // playback
ResampleObjUpL.Init ( iBlockSizeSam, SERVER_SAMPLE_RATE, SND_CRD_SAMPLE_RATE ); ResampleObjUpL.Init ( iBlockSizeSam, SYSTEM_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
ResampleObjUpR.Init ( iBlockSizeSam, SERVER_SAMPLE_RATE, SND_CRD_SAMPLE_RATE ); ResampleObjUpR.Init ( iBlockSizeSam, SYSTEM_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
// init network buffers // init network buffers
vecsNetwork.Init ( iBlockSizeSam ); vecsNetwork.Init ( iBlockSizeSam );
@ -333,7 +333,7 @@ void CClient::run()
connected to the server. In this case, exactly the same audio material is connected to the server. In this case, exactly the same audio material is
coming back and we can simply compare the samples */ coming back and we can simply compare the samples */
/* store send data instatic buffer (may delay is 100 ms) */ /* store send data instatic buffer (may delay is 100 ms) */
const int iMaxDelaySamples = (int) ((float) 0.3 /*0.1*/ * SERVER_SAMPLE_RATE); const int iMaxDelaySamples = (int) ((float) 0.3 /*0.1*/ * SYSTEM_SAMPLE_RATE);
static CVector<short> vecsOutBuf(iMaxDelaySamples); static CVector<short> vecsOutBuf(iMaxDelaySamples);
/* update buffer */ /* update buffer */

View File

@ -52,12 +52,8 @@
// defined port number for client and server // defined port number for client and server
#define LLCON_PORT_NUMBER 22122 #define LLCON_PORT_NUMBER 22122
// server sample rate // system sample rate
#define SERVER_SAMPLE_RATE 24000 // TODO: 32000 #define SYSTEM_SAMPLE_RATE 24000
// client low quality audio sample rate (high quality is the same as the server
// sample rate)
#define CLIENT_LOWQUALITY_SAMPLE_RATE 24000
// sound card sample rate. Should be always 48 kHz to avoid sound card driver // sound card sample rate. Should be always 48 kHz to avoid sound card driver
// internal sample rate conversion which might be buggy // internal sample rate conversion which might be buggy
@ -67,9 +63,7 @@
// of this duration // of this duration
#define MIN_BLOCK_DURATION_MS 2 // ms #define MIN_BLOCK_DURATION_MS 2 // ms
// TODO rename MIN_BLOCK_SIZE_SAMPLES -> MIN_CLIENT_LQ_BLOCK_SIZE_SAMPLES #define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SYSTEM_SAMPLE_RATE / 1000 )
#define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * CLIENT_LOWQUALITY_SAMPLE_RATE / 1000 )
#define MIN_SERVER_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SERVER_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 )
// maximum value of factor for network block size // maximum value of factor for network block size

View File

@ -29,7 +29,7 @@
CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber ) : CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber ) :
Socket ( &ChannelSet, this, iPortNumber ) Socket ( &ChannelSet, this, iPortNumber )
{ {
vecsSendData.Init ( MIN_SERVER_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 );
@ -97,7 +97,7 @@ void CServer::Stop()
void CServer::OnTimer() void CServer::OnTimer()
{ {
CVector<int> vecChanID; CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
CVector<CVector<double> > vecvecdGains; CVector<CVector<double> > vecvecdGains;
// get data from all connected clients // get data from all connected clients
@ -150,7 +150,7 @@ void CServer::OnTimer()
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData, CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains ) CVector<double>& vecdGains )
{ {
CVector<short> vecsOutData ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); CVector<short> vecsOutData ( MIN_BLOCK_SIZE_SAMPLES );
const int iNumClients = vecvecdData.Size(); const int iNumClients = vecvecdData.Size();
@ -158,7 +158,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
const double dNorm = (double) 2.0; const double dNorm = (double) 2.0;
// mix all audio data from all clients together // mix all audio data from all clients together
for ( int i = 0; i < MIN_SERVER_BLOCK_SIZE_SAMPLES; i++ ) for ( int i = 0; i < MIN_BLOCK_SIZE_SAMPLES; i++ )
{ {
double dMixedData = 0.0; double dMixedData = 0.0;

View File

@ -140,7 +140,7 @@ CAudioReverb::CAudioReverb ( const double rT60 )
// delay lengths for 44100 Hz sample rate // delay lengths for 44100 Hz sample rate
int lengths[9] = { 1777, 1847, 1993, 2137, 389, 127, 43, 211, 179 }; int lengths[9] = { 1777, 1847, 1993, 2137, 389, 127, 43, 211, 179 };
const double scaler = (double) SERVER_SAMPLE_RATE / 44100.0; const double scaler = (double) SYSTEM_SAMPLE_RATE / 44100.0;
if ( scaler != 1.0 ) if ( scaler != 1.0 )
{ {
@ -224,7 +224,7 @@ void CAudioReverb::setT60 ( const double rT60 )
for ( int i = 0; i < 4; i++ ) for ( int i = 0; i < 4; i++ )
{ {
combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 * combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 *
combDelays_[i].Size() / ( rT60 * SERVER_SAMPLE_RATE ) ) ); combDelays_[i].Size() / ( rT60 * SYSTEM_SAMPLE_RATE ) ) );
} }
} }