small changes (mostly in comments)

This commit is contained in:
Volker Fischer 2007-12-31 13:09:12 +00:00
parent a7a90201c2
commit 84d69211c5
7 changed files with 114 additions and 106 deletions

View File

@ -1,5 +1,5 @@
/******************************************************************************\
* Copyright (c) 2004-2006
* Copyright (c) 2004-2008
*
* Author(s):
* Volker Fischer, Erik de Castro Lopo
@ -41,7 +41,7 @@ int CAudioCompression::Init ( const int iNewAudioLen,
switch ( eNewAuCoTy )
{
case CT_NONE:
return iCodeSize = 2 * iNewAudioLen; /* short = 2 * byte */
return iCodeSize = 2 * iNewAudioLen; // short = 2 * byte
case CT_IMAADPCM:
return ImaAdpcm.Init ( iNewAudioLen );
@ -54,7 +54,7 @@ CVector<unsigned char> CAudioCompression::Encode ( const CVector<short>& vecsAud
{
if ( eAudComprType == CT_NONE )
{
/* no compression, simply ship pure samples */
// no compression, simply ship pure samples
CVector<unsigned char> vecbyOut ( iCodeSize );
const int iAudSize = iCodeSize / 2;
@ -70,7 +70,7 @@ CVector<unsigned char> CAudioCompression::Encode ( const CVector<short>& vecsAud
switch ( eAudComprType )
{
case CT_IMAADPCM:
return ImaAdpcm.Encode ( vecsAudio ); /* IMA-ADPCM */
return ImaAdpcm.Encode ( vecsAudio ); // IMA-ADPCM
default:
return CVector<unsigned char> ( 0 );
@ -82,7 +82,7 @@ CVector<short> CAudioCompression::Decode ( const CVector<unsigned char>& vecbyAd
{
if ( eAudComprType == CT_NONE )
{
/* no compression, reassemble pure samples */
// no compression, reassemble pure samples
const int iAudSize = iCodeSize / 2;
CVector<short> vecsOut ( iAudSize );
@ -103,7 +103,7 @@ CVector<short> CAudioCompression::Decode ( const CVector<unsigned char>& vecbyAd
switch ( eAudComprType )
{
case CT_IMAADPCM:
return ImaAdpcm.Decode ( vecbyAdpcm ); /* IMA-ADPCM */
return ImaAdpcm.Decode ( vecbyAdpcm ); // IMA-ADPCM
default:
return CVector<short> ( 0 );
@ -115,7 +115,7 @@ CVector<short> CAudioCompression::Decode ( const CVector<unsigned char>& vecbyAd
/* IMA-ADPCM implementation ------------------------------------------------- */
int CImaAdpcm::Init ( const int iNewAudioLen )
{
/* set lengths for audio and compressed data */
// set lengths for audio and compressed data
iAudSize = iNewAudioLen;
iAdpcmSize = 4 /* bytes header */ + (int) ceil (
(double) ( iAudSize - 2 /* first two samples are in header */ ) / 2 );
@ -131,7 +131,7 @@ CVector<unsigned char> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
CVector<unsigned char> vecbyAdpcm;
CVector<unsigned char> vecbyAdpcmTemp;
/* init size */
// init size
vecbyAdpcm.Init ( iAdpcmSize );
vecbyAdpcmTemp.Init ( iAudSize );
@ -146,8 +146,10 @@ CVector<unsigned char> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
/* encode the samples as 4 bit ------------------------------------------- */
for ( i = 1; i < iAudSize; i++ )
{
/* init diff and step */
// init diff and step
int diff = vecsAudio[i] - iPrevAudio;
ASSERT ( iStepindEnc < IMA_STEP_SIZE_TAB_LEN );
int step = ima_step_size[iStepindEnc];
short bytecode = 0;
@ -180,20 +182,21 @@ CVector<unsigned char> CImaAdpcm::Encode ( const CVector<short>& vecsAudio )
iPrevAudio += vpdiff;
}
/* adjust step size */
// adjust step size
ASSERT ( bytecode < IMA_INDX_ADJUST_TAB_LEN );
iStepindEnc += ima_indx_adjust[bytecode];
/* check that values do not exceed the bounds */
// check that values do not exceed the bounds
iPrevAudio = CheckBounds ( iPrevAudio, _MINSHORT, _MAXSHORT );
iStepindEnc = CheckBounds ( iStepindEnc, 0, IMA_STEP_SIZE_TAB_LEN - 1 );
/* use the input buffer as an intermediate result buffer */
// use the input buffer as an intermediate result buffer
vecbyAdpcmTemp[i] = bytecode;
}
/* pack the 4 bit encoded samples ---------------------------------------- */
/* The first encoded audio sample is in header */
// The first encoded audio sample is in header
vecbyAdpcm[3] = vecbyAdpcmTemp[1] & 0x0F;
for ( i = 4; i < iAdpcmSize; i++ )
@ -220,17 +223,17 @@ CVector<short> CImaAdpcm::Decode ( const CVector<unsigned char>& vecbyAdpcm )
current -= 0x10000;
}
/* get and bound step index */
// get and bound step index
int iStepindDec = CheckBounds ( vecbyAdpcm[2], 0, IMA_STEP_SIZE_TAB_LEN - 1 );
/* set first sample which was delivered in the header */
// set first sample which was delivered in the header
vecsAudio[0] = current;
/* --------------------------------------------------------------------------
pull apart the packed 4 bit samples and store them in their correct sample
positions */
/* The first encoded audio sample is in header */
// The first encoded audio sample is in header
vecsAudio[1] = vecbyAdpcm[3] & 0x0F;
for ( i = 4; i < iAdpcmSize; i++ )
@ -246,6 +249,8 @@ CVector<short> CImaAdpcm::Decode ( const CVector<unsigned char>& vecbyAdpcm )
{
const short bytecode = vecsAudio[i] & 0xF ;
ASSERT ( iStepindDec < IMA_STEP_SIZE_TAB_LEN );
short step = ima_step_size[iStepindDec];
int current = vecsAudio[i - 1];
@ -268,9 +273,11 @@ CVector<short> CImaAdpcm::Decode ( const CVector<unsigned char>& vecbyAdpcm )
}
current += diff;
ASSERT ( bytecode < IMA_INDX_ADJUST_TAB_LEN );
iStepindDec += ima_indx_adjust[bytecode];
/* check that values do not exceed the bounds */
// check that values do not exceed the bounds
current = CheckBounds ( current, _MINSHORT, _MAXSHORT );
iStepindDec = CheckBounds ( iStepindDec, 0, IMA_STEP_SIZE_TAB_LEN - 1 );

View File

@ -31,8 +31,9 @@
/* Definitions ****************************************************************/
/* tables */
static int ima_indx_adjust[16] =
// tables
#define IMA_INDX_ADJUST_TAB_LEN 16
static int ima_indx_adjust[IMA_INDX_ADJUST_TAB_LEN] =
{ -1, -1, -1, -1, /* +0 - +3, decrease the step size */
2, 4, 6, 8, /* +4 - +7, increase the step size */
-1, -1, -1, -1, /* -0 - -3, decrease the step size */

View File

@ -31,20 +31,20 @@
/* Implementation *************************************************************/
void CNetBuf::Init ( const int iNewBlockSize, const int iNewNumBlocks )
{
/* total size -> size of one block times number of blocks */
// total size -> size of one block times number of blocks
iBlockSize = iNewBlockSize;
iMemSize = iNewBlockSize * iNewNumBlocks;
/* fade in first block added to the buffer */
// fade in first block added to the buffer
bFadeInNewPutData = true;
/* allocate and clear memory for actual data buffer */
// allocate and clear memory for actual data buffer
vecdMemory.Init ( iMemSize );
/* use the "get" flag to make sure the buffer is cleared */
// use the "get" flag to make sure the buffer is cleared
Clear ( CT_GET );
/* initialize number of samples for fading effect */
// initialize number of samples for fading effect
if ( FADE_IN_OUT_NUM_SAM < iBlockSize )
{
iNumSamFading = iBlockSize;
@ -63,8 +63,8 @@ void CNetBuf::Init ( const int iNewBlockSize, const int iNewNumBlocks )
iNumSamFadingExtra = FADE_IN_OUT_NUM_SAM;
}
/* init variables for extrapolation (in case a fade out is needed) */
dExPDiff = 0.0;
// init variables for extrapolation (in case a fade out is needed)
dExPDiff = 0.0;
dExPLastV = 0.0;
}
@ -78,36 +78,36 @@ fflush(pFileBI);
bool bPutOK = true;
/* get size of data to be added to the buffer */
// get size of data to be added to the buffer
const int iInSize = vecdData.Size();
/* Check if there is not enough space available -> correct */
// Check if there is not enough space available -> correct
if ( GetAvailSpace() < iInSize )
{
/* not enough space in buffer for put operation, correct buffer to
prepare for new data */
// not enough space in buffer for put operation, correct buffer to
// prepare for new data
Clear ( CT_PUT );
/* set flag to fade in new block to avoid clicks */
// set flag to fade in new block to avoid clicks
bFadeInNewPutData = true;
bPutOK = false; /* return error flag */
bPutOK = false; // return error flag
}
/* fade in new block if required */
// fade in new block if required
if ( bFadeInNewPutData )
{
FadeInAudioDataBlock ( vecdData );
}
/* copy new data in internal buffer */
// copy new data in internal buffer
int iCurPos = 0;
if ( iPutPos + iInSize > iMemSize )
{
/* remaining space size for second block */
// remaining space size for second block
const int iRemSpace = iPutPos + iInSize - iMemSize;
/* data must be written in two steps because of wrap around */
// data must be written in two steps because of wrap around
while (iPutPos < iMemSize)
{
vecdMemory[iPutPos++] = vecdData[iCurPos++];
@ -120,7 +120,7 @@ fflush(pFileBI);
}
else
{
/* data can be written in one step */
// data can be written in one step
const int iEnd = iPutPos + iInSize;
while ( iPutPos < iEnd )
{
@ -128,7 +128,7 @@ fflush(pFileBI);
}
}
/* set buffer state flag */
// set buffer state flag
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_FULL;
@ -143,35 +143,35 @@ fflush(pFileBI);
bool CNetBuf::Get ( CVector<double>& vecdData )
{
bool bGetOK = true; /* init return value */
bool bGetOK = true; // init return value
bool bFadeOutExtrap = false;
/* get size of data to be get from the buffer */
// get size of data to be get from the buffer
const int iInSize = vecdData.Size();
/* Check if there is not enough data available -> correct */
// Check if there is not enough data available -> correct
if ( GetAvailData() < iInSize )
{
/* not enough data in buffer for get operation, correct buffer to
prepare for getting data */
// not enough data in buffer for get operation, correct buffer to
// prepare for getting data
Clear ( CT_GET );
/* set flag to fade in next new block in buffer and fade out last
block by extrapolation to avoid clicks */
// set flag to fade in next new block in buffer and fade out last
// block by extrapolation to avoid clicks
bFadeInNewPutData = true;
bFadeOutExtrap = true;
bGetOK = false; /* return error flag */
bGetOK = false; // return error flag
}
/* copy data from internal buffer in output buffer */
// copy data from internal buffer in output buffer
int iCurPos = 0;
if ( iGetPos + iInSize > iMemSize )
{
/* remaining data size for second block */
// remaining data size for second block
const int iRemData = iGetPos + iInSize - iMemSize;
/* data must be read in two steps because of wrap around */
// data must be read in two steps because of wrap around
while ( iGetPos < iMemSize )
{
vecdData[iCurPos++] = vecdMemory[iGetPos++];
@ -184,7 +184,7 @@ bool CNetBuf::Get ( CVector<double>& vecdData )
}
else
{
/* data can be read in one step */
// data can be read in one step
const int iEnd = iGetPos + iInSize;
while ( iGetPos < iEnd )
{
@ -192,7 +192,7 @@ bool CNetBuf::Get ( CVector<double>& vecdData )
}
}
/* set buffer state flag */
// set buffer state flag
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_EMPTY;
@ -224,13 +224,13 @@ bool CNetBuf::Get ( CVector<double>& vecdData )
int CNetBuf::GetAvailSpace() const
{
/* calculate available space in buffer */
// calculate available space in buffer
int iAvSpace = iGetPos - iPutPos;
/* check for special case and wrap around */
// check for special case and wrap around
if ( iAvSpace < 0 )
{
iAvSpace += iMemSize; /* wrap around */
iAvSpace += iMemSize; // wrap around
}
else
{
@ -245,13 +245,13 @@ int CNetBuf::GetAvailSpace() const
int CNetBuf::GetAvailData() const
{
/* calculate available data in buffer */
// calculate available data in buffer
int iAvData = iPutPos - iGetPos;
/* check for special case and wrap around */
// check for special case and wrap around
if ( iAvData < 0 )
{
iAvData += iMemSize; /* wrap around */
iAvData += iMemSize; // wrap around
}
else
{
@ -285,14 +285,14 @@ void CNetBuf::Clear ( const EClearType eClearType )
#endif
/* different behaviour for get and put corrections */
// different behaviour for get and put corrections
if ( eClearType == CT_GET )
{
/* clear buffer */
// clear buffer
vecdMemory.Reset ( 0.0 );
/* correct buffer so that after the current get operation the pointer
are at maximum distance */
// correct buffer so that after the current get operation the pointer
// are at maximum distance
iPutPos = 0;
iGetPos = iMiddleOfBuffer;
@ -308,28 +308,28 @@ void CNetBuf::Clear ( const EClearType eClearType )
}
else
{
/* in case of "put" correction, do not delete old data but only shift
the pointers */
// in case of "put" correction, do not delete old data but only shift
// the pointers
iPutPos = iMiddleOfBuffer;
/* adjust put pointer relative to current get pointer, take care of
wrap around */
// adjust put pointer relative to current get pointer, take care of
// wrap around
iPutPos += iGetPos;
if ( iPutPos > iMemSize )
{
iPutPos -= iMemSize;
}
/* fade out old data right before new put pointer */
// fade out old data right before new put pointer
int iCurPos = iPutPos - iNumSamFading;
int i = iNumSamFading;
if ( iCurPos < 0 )
{
/* wrap around */
// wrap around
iCurPos += iMemSize;
/* data must be processed in two steps because of wrap around */
// data must be processed in two steps because of wrap around
while ( iCurPos < iMemSize )
{
vecdMemory[iCurPos++] *= ( (double) i / iNumSamFading );
@ -344,7 +344,7 @@ void CNetBuf::Clear ( const EClearType eClearType )
}
else
{
/* data can be processed in one step */
// data can be processed in one step
while ( iCurPos < iPutPos )
{
vecdMemory[iCurPos++] *= ( (double) i / iNumSamFading );
@ -352,7 +352,7 @@ void CNetBuf::Clear ( const EClearType eClearType )
}
}
/* check for special case */
// check for special case
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_EMPTY;
@ -366,13 +366,13 @@ void CNetBuf::Clear ( const EClearType eClearType )
void CNetBuf::FadeInAudioDataBlock ( CVector<double>& vecdData )
{
/* apply linear fading */
// apply linear fading
for ( int i = 0; i < iNumSamFading; i++ )
{
vecdData[i] *= ( (double) i / iNumSamFading );
}
/* reset flag */
// reset flag
bFadeInNewPutData = false;
}
@ -380,13 +380,13 @@ void CNetBuf::FadeOutExtrapolateAudioDataBlock ( CVector<double>& vecdData,
const double dExPDiff,
const double dExPLastV )
{
/* apply linear extrapolation and linear fading */
// apply linear extrapolation and linear fading
for ( int i = 0; i < iNumSamFadingExtra; i++ )
{
/* calculate extrapolated value */
// calculate extrapolated value
vecdData[i] = ( ( i + 1 ) * dExPDiff + dExPLastV );
/* linear fading */
// linear fading
vecdData[i] *= ( (double) ( iNumSamFadingExtra - i ) / iNumSamFadingExtra );
}
}
@ -396,10 +396,10 @@ void CNetBuf::FadeOutExtrapolateAudioDataBlock ( CVector<double>& vecdData,
/* conversion buffer implementation *******************************************/
void CConvBuf::Init ( const int iNewMemSize )
{
/* set memory size */
// set memory size
iMemSize = iNewMemSize;
/* allocate and clear memory for actual data buffer */
// allocate and clear memory for actual data buffer
vecsMemory.Init ( iMemSize );
iPutPos = 0;
@ -409,7 +409,7 @@ bool CConvBuf::Put ( const CVector<short>& vecsData )
{
const int iVecSize = vecsData.Size();
/* copy new data in internal buffer */
// copy new data in internal buffer
int iCurPos = 0;
const int iEnd = iPutPos + iVecSize;
while ( iPutPos < iEnd )

View File

@ -92,7 +92,6 @@ public:
protected:
CVector<short> vecsMemory;
int iMemSize;
int iBlockSize;
int iPutPos;
};

View File

@ -42,7 +42,7 @@
// version and application name (always use this version)
#undef VERSION
#define VERSION "1.0cvs"
#define VERSION "1.0.1cvs"
#define APP_NAME "llcon"
// file name for logging file

View File

@ -1,5 +1,5 @@
/******************************************************************************\
* Copyright (c) 2004-2006
* Copyright (c) 2004-2008
*
* Author(s):
* Volker Fischer
@ -57,17 +57,17 @@ public:
virtual ~CLlconServerDlg() {}
protected:
QTimer Timer;
CServer* pServer;
QTimer Timer;
CServer* pServer;
QPixmap BitmCubeGreen;
QPixmap BitmCubeYellow;
QPixmap BitmCubeRed;
QPixmap BitmCubeGreen;
QPixmap BitmCubeYellow;
QPixmap BitmCubeRed;
CVector<CServerListViewItem*> vecpListViewItems;
QMutex ListViewMutex;
CVector<CServerListViewItem*> vecpListViewItems;
QMutex ListViewMutex;
QMenuBar* pMenu;
QMenuBar* pMenu;
virtual void customEvent ( QCustomEvent* Event );
void UpdateSliderNetBuf();

View File

@ -28,40 +28,41 @@
/* Implementation *************************************************************/
void CSocket::Init()
{
/* allocate memory for network receive and send buffer in samples */
// allocate memory for network receive and send buffer in samples
vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF );
/* initialize the listening socket */
// initialize the listening socket
bool bSuccess = SocketDevice.bind (
QHostAddress ( (Q_UINT32) 0 ) /* INADDR_ANY */, LLCON_PORT_NUMBER );
QHostAddress ( (Q_UINT32) 0 ), // INADDR_ANY
LLCON_PORT_NUMBER );
if ( bIsClient )
{
/* if no success, try if server is on same machine (only for client) */
// if no success, try if server is on same machine (only for client)
if ( !bSuccess )
{
/* if server and client is on same machine, decrease port number by
one by definition */
// if server and client is on same machine, decrease port number by
// one by definition
bSuccess = SocketDevice.bind (
QHostAddress( (Q_UINT32) 0 ) /* INADDR_ANY */,
QHostAddress( (Q_UINT32) 0 ), // INADDR_ANY
LLCON_PORT_NUMBER - 1 );
}
}
if ( !bSuccess )
{
/* show error message */
// show error message
QMessageBox::critical ( 0, "Network Error", "Cannot bind the socket.",
QMessageBox::Ok, QMessageBox::NoButton );
/* exit application */
// exit application
exit ( 1 );
}
QSocketNotifier* pSocketNotivRead =
new QSocketNotifier ( SocketDevice.socket (), QSocketNotifier::Read );
/* connect the "activated" signal */
// connect the "activated" signal
QObject::connect ( pSocketNotivRead, SIGNAL ( activated ( int ) ),
this, SLOT ( OnDataReceived() ) );
}
@ -73,7 +74,7 @@ void CSocket::SendPacket ( const CVector<unsigned char>& vecbySendBuf,
if ( iVecSizeOut != 0 )
{
/* send packet through network */
// send packet through network
SocketDevice.writeBlock (
(const char*) &( (CVector<unsigned char>) vecbySendBuf )[0],
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
@ -82,24 +83,24 @@ void CSocket::SendPacket ( const CVector<unsigned char>& vecbySendBuf,
void CSocket::OnDataReceived()
{
/* read block from network interface */
// read block from network interface
const int iNumBytesRead = SocketDevice.readBlock ( (char*) &vecbyRecBuf[0],
MAX_SIZE_BYTES_NETW_BUF );
/* check if an error occurred */
// check if an error occurred
if ( iNumBytesRead < 0 )
{
return;
}
/* get host address of client */
// get host address of client
CHostAddress RecHostAddr ( SocketDevice.peerAddress(),
SocketDevice.peerPort() );
if ( bIsClient )
{
/* client */
/* check if packet comes from the server we want to connect */
// client
// check if packet comes from the server we want to connect
if ( ! ( pChannel->GetAddress() == RecHostAddr ) )
{
return;
@ -123,7 +124,7 @@ void CSocket::OnDataReceived()
}
else
{
/* server */
// server
if ( pChannelSet->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ) )
{
// this was an audio packet, start server