code style changes

This commit is contained in:
Volker Fischer 2006-12-06 21:10:24 +00:00
parent e335718eb5
commit 63adf15507
2 changed files with 100 additions and 84 deletions

View file

@ -87,7 +87,7 @@ void CChannelSet::CreateAndSendChanListForAllConClients()
int CChannelSet::GetFreeChan()
{
/* look for a free channel */
// look for a free channel
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( !vecChannels[i].IsConnected() )
@ -132,13 +132,13 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
{
bool bChanOK = true;
/* get channel ID --------------------------------------------------- */
/* check address */
// get channel ID ------------------------------------------------------
// check address
int iCurChanID = CheckAddr ( HostAdr );
if ( iCurChanID == INVALID_CHANNEL_ID )
{
/* a new client is calling, look for free channel */
// a new client is calling, look for free channel
iCurChanID = GetFreeChan();
if ( iCurChanID != INVALID_CHANNEL_ID )
@ -166,20 +166,21 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
}
else
{
/* no free channel available */
// no free channel available
bChanOK = false;
// create and send "server full" message
// TODO
// TODO problem: if channel is not officially connected, we cannot send messages
}
}
/* put received data in jitter buffer ------------------------------- */
// put received data in jitter buffer ----------------------------------
if ( bChanOK )
{
/* put packet in socket buffer */
// put packet in socket buffer
switch ( vecChannels[iCurChanID].PutData ( vecbyRecBuf, iNumBytesRead ) )
{
case PS_AUDIO_OK:
@ -284,18 +285,18 @@ void CChannelSet::GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
{
CHostAddress InetAddr;
/* init return values */
// init return values
vecHostAddresses.Init ( MAX_NUM_CHANNELS );
veciJitBufSize.Init ( MAX_NUM_CHANNELS );
veciNetwOutBlSiFact.Init ( MAX_NUM_CHANNELS );
veciNetwInBlSiFact.Init ( MAX_NUM_CHANNELS );
/* Check all possible channels */
// check all possible channels
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
if ( vecChannels[i].GetAddress ( InetAddr ) )
{
/* get requested data */
// get requested data
vecHostAddresses[i] = InetAddr;
veciJitBufSize[i] = vecChannels[i].GetSockBufSize ();
veciNetwOutBlSiFact[i] = vecChannels[i].GetNetwBufSizeFactOut ();
@ -323,18 +324,18 @@ CChannel::CChannel() : sName ( "" ),
iCurNetwInBlSiFact = DEF_NET_BLOCK_SIZE_FACTOR;
/* init the socket buffer */
// init the socket buffer
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
// set initial input and output block size factors
SetNetwBufSizeFactOut ( iCurNetwInBlSiFact );
SetNetwInBlSiFact ( iCurNetwInBlSiFact );
/* init time-out for the buffer with zero -> no connection */
// init time-out for the buffer with zero -> no connection
iConTimeOut = 0;
/* connections ---------------------------------------------------------- */
// connections -------------------------------------------------------------
QObject::connect ( &Protocol,
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
@ -361,7 +362,7 @@ void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor )
// store new value
iCurNetwInBlSiFact = iNewBlockSizeFactor;
/* init audio compression unit */
// init audio compression unit
iAudComprSizeIn = AudioCompressionIn.Init (
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
@ -379,12 +380,12 @@ void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
// store new value
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
/* init audio compression unit */
// init audio compression unit
iAudComprSizeOut = AudioCompressionOut.Init (
iNewNetwBlSiFactOut * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM );
/* init conversion buffer */
// init conversion buffer
ConvBuf.Init ( iNewNetwBlSiFactOut * MIN_BLOCK_SIZE_SAMPLES );
}
@ -405,7 +406,7 @@ void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
void CChannel::SetSockBufSize ( const int iNumBlocks )
{
/* this opperation must be done with mutex */
// this opperation must be done with mutex
Mutex.lock();
{
iCurSockBufSize = iNumBlocks;
@ -484,16 +485,16 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
}
}
/* only process if packet has correct size */
// only process if packet has correct size
if ( bIsAudioPacket )
{
Mutex.lock();
{
/* decompress audio */
// decompress audio
CVector<short> vecsDecomprAudio ( AudioCompressionIn.Decode ( vecbyData ) );
/* do resampling to compensate for sample rate offsets in the
different sound cards of the clients */
// do resampling to compensate for sample rate offsets in the
// different sound cards of the clients
/*
for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++)
vecdResInData[i] = (double) vecsData[i];
@ -565,35 +566,35 @@ bool CChannel::GetData ( CVector<double>& vecdData )
{
bool bGetOK = false;
Mutex.lock(); /* get mutex lock */
Mutex.lock(); // get mutex lock
{
bGetOK = SockBuf.Get ( vecdData );
if ( !bGetOK )
{
/* decrease time-out counter */
// decrease time-out counter
if ( iConTimeOut > 0 )
{
iConTimeOut--;
}
}
}
Mutex.unlock(); /* get mutex unlock */
Mutex.unlock(); // get mutex unlock
return bGetOK;
}
CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
{
/* if the block is not ready we have to initialize with zero length to
tell the following network send routine that nothing should be sent */
// if the block is not ready we have to initialize with zero length to
// tell the following network send routine that nothing should be sent
CVector<unsigned char> vecbySendBuf ( 0 );
/* use conversion buffer to convert sound card block size in network
block size */
// use conversion buffer to convert sound card block size in network
// block size
if ( ConvBuf.Put ( vecsNPacket ) )
{
/* a packet is ready, compress audio */
// a packet is ready, compress audio
vecbySendBuf.Init ( iAudComprSizeOut );
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() );
}

View file

@ -134,119 +134,134 @@ uint32_t CCRC::GetCRC()
three series allpass units, followed by four parallel comb filters, and two
decorrelation delay lines in parallel at the output.
*/
CAudioReverb::CAudioReverb(const double rT60)
CAudioReverb::CAudioReverb ( const double rT60 )
{
int delay, i;
/* 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) SAMPLE_RATE / 44100.0;
int delay, i;
if (scaler != 1.0)
if ( scaler != 1.0 )
{
for (i = 0; i < 9; i++)
for ( i = 0; i < 9; i++ )
{
delay = (int) floor(scaler * lengths[i]);
delay = (int) floor ( scaler * lengths[i] );
if ((delay & 1) == 0)
if ( ( delay & 1 ) == 0 )
{
delay++;
}
while (!isPrime(delay))
while ( !isPrime ( delay ) )
{
delay += 2;
}
lengths[i] = delay;
}
}
for (i = 0; i < 3; i++)
allpassDelays_[i].Init(lengths[i + 4]);
for ( i = 0; i < 3; i++ )
{
allpassDelays_[i].Init ( lengths[i + 4] );
}
for (i = 0; i < 4; i++)
combDelays_[i].Init(lengths[i]);
for ( i = 0; i < 4; i++ )
{
combDelays_[i].Init ( lengths[i] );
}
setT60(rT60);
setT60 ( rT60 );
allpassCoefficient_ = (double) 0.7;
Clear();
}
bool CAudioReverb::isPrime(const int number)
bool CAudioReverb::isPrime ( const int number )
{
/*
Returns true if argument value is prime. Taken from "class Effect" in
"STK abstract effects parent class".
*/
if (number == 2)
if ( number == 2 )
{
return true;
}
if (number & 1)
if ( number & 1 )
{
for (int i = 3; i < (int) sqrt((double) number) + 1; i += 2)
for ( int i = 3; i < (int) sqrt ( (double) number ) + 1; i += 2 )
{
if ( ( number % i ) == 0 )
{
if ((number % i) == 0)
return false;
}
}
return true; /* prime */
return true; // prime
}
else
return false; /* even */
{
return false; // even
}
}
void CAudioReverb::Clear()
{
/* Reset and clear all internal state */
allpassDelays_[0].Reset(0);
allpassDelays_[1].Reset(0);
allpassDelays_[2].Reset(0);
combDelays_[0].Reset(0);
combDelays_[1].Reset(0);
combDelays_[2].Reset(0);
combDelays_[3].Reset(0);
// reset and clear all internal state
allpassDelays_[0].Reset ( 0 );
allpassDelays_[1].Reset ( 0 );
allpassDelays_[2].Reset ( 0 );
combDelays_[0].Reset ( 0 );
combDelays_[1].Reset ( 0 );
combDelays_[2].Reset ( 0 );
combDelays_[3].Reset ( 0 );
}
void CAudioReverb::setT60(const double rT60)
void CAudioReverb::setT60 ( const double rT60 )
{
/* Set the reverberation T60 decay time */
for (int i = 0; i < 4; i++)
// set the reverberation T60 decay time
for ( int i = 0; i < 4; i++ )
{
combCoefficient_[i] = pow((double) 10.0, (double) (-3.0 *
combDelays_[i].Size() / (rT60 * SAMPLE_RATE)));
combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 *
combDelays_[i].Size() / ( rT60 * SAMPLE_RATE ) ) );
}
}
double CAudioReverb::ProcessSample(const double input)
double CAudioReverb::ProcessSample ( const double input )
{
/* Compute one output sample */
// compute one output sample
double temp, temp0, temp1, temp2;
temp = allpassDelays_[0].Get();
temp0 = allpassCoefficient_ * temp;
temp0 += input;
allpassDelays_[0].Add((int) temp0);
temp0 = -(allpassCoefficient_ * temp0) + temp;
allpassDelays_[0].Add ( (int) temp0 );
temp0 = - ( allpassCoefficient_ * temp0 ) + temp;
temp = allpassDelays_[1].Get();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays_[1].Add((int) temp1);
temp1 = -(allpassCoefficient_ * temp1) + temp;
allpassDelays_[1].Add ( (int) temp1 );
temp1 = - ( allpassCoefficient_ * temp1 ) + temp;
temp = allpassDelays_[2].Get();
temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
allpassDelays_[2].Add((int) temp2);
temp2 = -(allpassCoefficient_ * temp2) + temp;
allpassDelays_[2].Add ( (int) temp2 );
temp2 = - ( allpassCoefficient_ * temp2 ) + temp;
const double temp3 = temp2 + (combCoefficient_[0] * combDelays_[0].Get());
const double temp4 = temp2 + (combCoefficient_[1] * combDelays_[1].Get());
const double temp5 = temp2 + (combCoefficient_[2] * combDelays_[2].Get());
const double temp6 = temp2 + (combCoefficient_[3] * combDelays_[3].Get());
const double temp3 = temp2 + ( combCoefficient_[0] * combDelays_[0].Get() );
const double temp4 = temp2 + ( combCoefficient_[1] * combDelays_[1].Get() );
const double temp5 = temp2 + ( combCoefficient_[2] * combDelays_[2].Get() );
const double temp6 = temp2 + ( combCoefficient_[3] * combDelays_[3].Get() );
combDelays_[0].Add((int) temp3);
combDelays_[1].Add((int) temp4);
combDelays_[2].Add((int) temp5);
combDelays_[3].Add((int) temp6);
combDelays_[0].Add ( (int) temp3 );
combDelays_[1].Add ( (int) temp4 );
combDelays_[2].Add ( (int) temp5 );
combDelays_[3].Add ( (int) temp6 );
return (temp3 + temp4 + temp5 + temp6) * (double) 0.5;
return ( temp3 + temp4 + temp5 + temp6 ) * (double) 0.5;
}