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 ****************************************************************/
// time for fading effect for masking drop outs
#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
#define FADE_IN_OUT_NUM_SAM_EXTRA 5 // samples

View file

@ -433,25 +433,15 @@ CChannel::CChannel() : sName ( "" ),
iCurNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
{
// query all possible network in buffer sizes for determining if an
// audio packet was received, consider all possible sample rates (audio
// quality types: low quality, high quality)
// audio packet was received
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{
// network block size factor must start from 1 -> ( i + 1 )
// low quality audio
vecNetwInBufSizesAudLQ[i] = AudioCompressionInLowQSampRate.Init (
vecNetwInBufSizes[i] = AudioCompressionIn.Init (
( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES,
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
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
@ -501,20 +491,6 @@ CChannel::CChannel() : sName ( "" ),
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 )
{
// set internal parameter
@ -532,15 +508,11 @@ void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor )
// store new value
iCurNetwInBlSiFact = iNewBlockSizeFactor;
// init audio compression units
AudioCompressionInLowQSampRate.Init (
// init audio compression unit
AudioCompressionIn.Init (
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
AudioCompressionInHighQSampRate.Init (
iNewBlockSizeFactor * MIN_SERVER_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
// initial value for connection time out counter
iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) /
( iNewBlockSizeFactor * MIN_BLOCK_DURATION_MS );
@ -655,9 +627,7 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
// init flags
bool bIsProtocolPacket = false;
bool bIsAudioPacket = false;
bool bIsHQAudioPacket = false; // is high quality audio packet (high sample rate)
bool bNewConnection = false;
int iInputBlockSizeFactor;
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++ )
{
// check for low/high quality audio packets and set flags
if ( iNumBytes == vecNetwInBufSizesAudLQ[i] )
if ( iNumBytes == vecNetwInBufSizes[i] )
{
bIsAudioPacket = true;
bIsHQAudioPacket = false;
iInputBlockSizeFactor = i + 1;
}
if ( iNumBytes == vecNetwInBufSizesAudHQ[i] )
// check if we are correctly initialized
const int iNewNetwInBlSiFact = i + 1;
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
{
bIsAudioPacket = true;
bIsHQAudioPacket = true;
iInputBlockSizeFactor = i + 1;
// re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact );
}
}
}
// only process if packet has correct size
if ( bIsAudioPacket )
{
// check if we are correctly initialized
if ( iInputBlockSizeFactor != iCurNetwInBlSiFact )
{
// re-initialize to new value
SetNetwInBlSiFact ( iInputBlockSizeFactor );
}
Mutex.lock();
{
// TODO use bIsHQAudioPacket
// decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionInHighQSampRate.Decode ( vecbyData ) );
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
// do resampling to compensate for sample rate offsets in the
// different sound cards of the clients
@ -726,7 +683,7 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i];
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 );

View file

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

View file

@ -173,12 +173,12 @@ void CClient::Init()
// resample objects are always initialized with the input block size
// record
ResampleObjDownL.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SERVER_SAMPLE_RATE );
ResampleObjDownR.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, SYSTEM_SAMPLE_RATE );
// playback
ResampleObjUpL.Init ( iBlockSizeSam, SERVER_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
ResampleObjUpR.Init ( iBlockSizeSam, SERVER_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
ResampleObjUpL.Init ( iBlockSizeSam, SYSTEM_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
ResampleObjUpR.Init ( iBlockSizeSam, SYSTEM_SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
// init network buffers
vecsNetwork.Init ( iBlockSizeSam );
@ -333,7 +333,7 @@ void CClient::run()
connected to the server. In this case, exactly the same audio material is
coming back and we can simply compare the samples */
/* 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);
/* update buffer */

View file

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

View file

@ -29,7 +29,7 @@
CServer::CServer ( const bool bUseLogging, const quint16 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
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE );
@ -97,7 +97,7 @@ void CServer::Stop()
void CServer::OnTimer()
{
CVector<int> vecChanID;
CVector<CVector<double> > vecvecdData ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
CVector<CVector<double> > vecvecdData ( MIN_BLOCK_SIZE_SAMPLES );
CVector<CVector<double> > vecvecdGains;
// get data from all connected clients
@ -150,7 +150,7 @@ void CServer::OnTimer()
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
CVector<double>& vecdGains )
{
CVector<short> vecsOutData ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
CVector<short> vecsOutData ( MIN_BLOCK_SIZE_SAMPLES );
const int iNumClients = vecvecdData.Size();
@ -158,7 +158,7 @@ CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
const double dNorm = (double) 2.0;
// 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;

View file

@ -140,7 +140,7 @@ CAudioReverb::CAudioReverb ( const double rT60 )
// delay lengths for 44100 Hz sample rate
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 )
{
@ -224,7 +224,7 @@ void CAudioReverb::setT60 ( const double rT60 )
for ( int i = 0; i < 4; i++ )
{
combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 *
combDelays_[i].Size() / ( rT60 * SERVER_SAMPLE_RATE ) ) );
combDelays_[i].Size() / ( rT60 * SYSTEM_SAMPLE_RATE ) ) );
}
}