new code style

This commit is contained in:
Volker Fischer 2007-09-08 10:45:14 +00:00
parent 56f6fee1e0
commit d49a2b2731
30 changed files with 1109 additions and 912 deletions

View file

@ -90,7 +90,9 @@ CVector<short> CAudioCompression::Decode(const CVector<unsigned char>& vecbyAdpc
{
int current = vecbyAdpcm[2 * i] | ( vecbyAdpcm[2 * i + 1] << 8 );
if ( current & 0x8000 )
{
current -= 0x10000;
}
vecsOut[i] = (short) current;
}
@ -170,9 +172,13 @@ CVector<unsigned char> CImaAdpcm::Encode(const CVector<short>& vecsAudio)
}
if ( bytecode & 8 )
{
iPrevAudio -= vpdiff;
}
else
{
iPrevAudio += vpdiff;
}
/* adjust step size */
iStepindEnc += ima_indx_adjust[bytecode];
@ -210,7 +216,9 @@ CVector<short> CImaAdpcm::Decode(const CVector<unsigned char>& vecbyAdpcm)
/* read and check the block header --------------------------------------- */
int current = vecbyAdpcm[0] | ( vecbyAdpcm[1] << 8 );
if ( current & 0x8000 )
{
current -= 0x10000;
}
/* get and bound step index */
int iStepindDec = CheckBounds ( vecbyAdpcm[2], 0, IMA_STEP_SIZE_TAB_LEN - 1 );
@ -243,13 +251,21 @@ CVector<short> CImaAdpcm::Decode(const CVector<unsigned char>& vecbyAdpcm)
int diff = step >> 3;
if ( bytecode & 1 )
{
diff += step >> 2;
}
if ( bytecode & 2 )
{
diff += step >> 1;
}
if ( bytecode & 4 )
{
diff += step;
}
if ( bytecode & 8 )
{
diff = -diff;
}
current += diff;
iStepindDec += ima_indx_adjust[bytecode];

View file

@ -68,7 +68,7 @@ protected:
int iAdpcmSize;
int iStepindEnc;
/* inline functions must be declared in the header */
// inline functions must be declared in the header
inline int CheckBounds ( const int iData, const int iMin, const int iMax )
{
if ( iData > iMax )

View file

@ -46,14 +46,22 @@ void CNetBuf::Init ( const int iNewBlockSize, const int iNewNumBlocks )
/* initialize number of samples for fading effect */
if ( FADE_IN_OUT_NUM_SAM < iBlockSize )
{
iNumSamFading = iBlockSize;
}
else
{
iNumSamFading = FADE_IN_OUT_NUM_SAM;
}
if ( FADE_IN_OUT_NUM_SAM_EXTRA > iBlockSize )
{
iNumSamFadingExtra = iBlockSize;
}
else
{
iNumSamFadingExtra = FADE_IN_OUT_NUM_SAM;
}
/* init variables for extrapolation (in case a fade out is needed) */
dExPDiff = 0.0;
@ -88,7 +96,9 @@ fflush(pFileBI);
/* fade in new block if required */
if ( bFadeInNewPutData )
{
FadeInAudioDataBlock ( vecdData );
}
/* copy new data in internal buffer */
int iCurPos = 0;
@ -99,24 +109,34 @@ fflush(pFileBI);
/* data must be written in two steps because of wrap around */
while (iPutPos < iMemSize)
{
vecdMemory[iPutPos++] = vecdData[iCurPos++];
}
for ( iPutPos = 0; iPutPos < iRemSpace; iPutPos++ )
{
vecdMemory[iPutPos] = vecdData[iCurPos++];
}
}
else
{
/* data can be written in one step */
const int iEnd = iPutPos + iInSize;
while ( iPutPos < iEnd )
{
vecdMemory[iPutPos++] = vecdData[iCurPos++];
}
}
/* set buffer state flag */
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_FULL;
}
else
{
eBufState = CNetBuf::BS_OK;
}
return bPutOK;
}
@ -153,24 +173,34 @@ bool CNetBuf::Get(CVector<double>& vecdData)
/* data must be read in two steps because of wrap around */
while ( iGetPos < iMemSize )
{
vecdData[iCurPos++] = vecdMemory[iGetPos++];
}
for ( iGetPos = 0; iGetPos < iRemData; iGetPos++ )
{
vecdData[iCurPos++] = vecdMemory[iGetPos];
}
}
else
{
/* data can be read in one step */
const int iEnd = iGetPos + iInSize;
while ( iGetPos < iEnd )
{
vecdData[iCurPos++] = vecdMemory[iGetPos++];
}
}
/* set buffer state flag */
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_EMPTY;
}
else
{
eBufState = CNetBuf::BS_OK;
}
/* extrapolate data from old block to avoid "clicks"
@ -178,7 +208,9 @@ bool CNetBuf::Get(CVector<double>& vecdData)
anymore since it is already gone (processed or send through the
network) */
if ( bFadeOutExtrap )
{
FadeOutExtrapolateAudioDataBlock ( vecdData, dExPDiff, dExPLastV );
}
/* save some paramters from last block which is needed in case we do not
have enough data for next "get" operation and need to extrapolate the
@ -197,9 +229,16 @@ int CNetBuf::GetAvailSpace() const
/* check for special case and wrap around */
if ( iAvSpace < 0 )
{
iAvSpace += iMemSize; /* wrap around */
else if ((iAvSpace == 0) && (eBufState == BS_EMPTY))
}
else
{
if ( ( iAvSpace == 0 ) && ( eBufState == BS_EMPTY ) )
{
iAvSpace = iMemSize;
}
}
return iAvSpace;
}
@ -211,9 +250,16 @@ int CNetBuf::GetAvailData() const
/* check for special case and wrap around */
if ( iAvData < 0 )
{
iAvData += iMemSize; /* wrap around */
else if ((iAvData == 0) && (eBufState == BS_FULL))
}
else
{
if ( ( iAvData == 0 ) && ( eBufState == BS_FULL ) )
{
iAvData = iMemSize;
}
}
return iAvData;
}
@ -252,10 +298,14 @@ void CNetBuf::Clear(const EClearType eClearType)
/* check for special case */
if ( iPutPos == iGetPos )
{
eBufState = CNetBuf::BS_FULL;
}
else
{
eBufState = CNetBuf::BS_OK;
}
}
else
{
/* in case of "put" correction, do not delete old data but only shift
@ -266,7 +316,9 @@ void CNetBuf::Clear(const EClearType eClearType)
wrap around */
iPutPos += iGetPos;
if ( iPutPos > iMemSize )
{
iPutPos -= iMemSize;
}
/* fade out old data right before new put pointer */
int iCurPos = iPutPos - iNumSamFading;

View file

@ -30,12 +30,12 @@
/* Definitions ****************************************************************/
/* time for fading effect for masking drop outs */
#define FADE_IN_OUT_TIME ((double) 0.3) /* ms */
// time for fading effect for masking drop outs
#define FADE_IN_OUT_TIME ( (double) 0.3 ) // ms
#define FADE_IN_OUT_NUM_SAM ( (int) ( SAMPLE_RATE * FADE_IN_OUT_TIME ) / 1000 )
/* for extrapolation a shorter time for fading */
#define FADE_IN_OUT_NUM_SAM_EXTRA 5 /* samples */
// for extrapolation a shorter time for fading
#define FADE_IN_OUT_NUM_SAM_EXTRA 5 // samples
/* Classes ********************************************************************/
@ -70,13 +70,13 @@ protected:
int iNumSamFading;
int iNumSamFadingExtra;
/* extrapolation parameters */
// extrapolation parameters
double dExPDiff;
double dExPLastV;
};
/* conversion buffer (very simple buffer) */
// conversion buffer (very simple buffer)
class CConvBuf
{
public:

View file

@ -128,7 +128,7 @@ public:
protected:
virtual void run();
/* only one channel is needed for client application */
// only one channel is needed for client application
CChannel Channel;
CSocket Socket;
@ -158,13 +158,13 @@ protected:
CVector<short> vecsNetwork;
/* resample objects */
CAudioResample ResampleObjDownL; /* left channel */
CAudioResample ResampleObjDownR; /* right channel */
CAudioResample ResampleObjUpL; /* left channel */
CAudioResample ResampleObjUpR; /* right channel */
// resample objects
CAudioResample ResampleObjDownL; // left channel
CAudioResample ResampleObjDownR; // right channel
CAudioResample ResampleObjUpL; // left channel
CAudioResample ResampleObjUpR; // right channel
/* debugging, evaluating */
// debugging, evaluating
CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock;

View file

@ -44,8 +44,8 @@
/* Definitions ****************************************************************/
/* update time for GUI controls */
#define DISPLAY_UPDATE_TIME 1000 /* ms */
// update time for GUI controls
#define DISPLAY_UPDATE_TIME 1000 // ms
/* Classes ********************************************************************/

View file

@ -36,11 +36,11 @@
/* Definitions ****************************************************************/
/* define this macro to get debug output */
// define this macro to get debug output
#define _DEBUG_
#undef _DEBUG_
/* version and application name (always use this version) */
// version and application name (always use this version)
#undef VERSION
#define VERSION "1.0cvs"
#define APP_NAME "llcon"
@ -68,14 +68,14 @@
// maximum value of factor for network block size
#define MAX_NET_BLOCK_SIZE_FACTOR 8
/* default network block size factor */
// 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 */
// 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 */
// default network buffer size
#define DEF_NET_BUF_SIZE_NUM_BL 5 // number of blocks
// number of ticks of audio in/out buffer sliders
#ifdef _WIN32
@ -88,25 +88,25 @@
// if you want to change this paramter, there has to be done code modifications
// on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places
// (just search for the tag in the entire code)
#define MAX_NUM_CHANNELS 10 /* max number channels for server */
#define MAX_NUM_CHANNELS 10 // max number channels for server
/* sample rate offset estimation algorithm */
/* time interval for sample rate offset estimation */
#define TIME_INT_SAM_OFFS_EST 60 /* s */
// sample rate offset estimation algorithm
// time interval for sample rate offset estimation
#define TIME_INT_SAM_OFFS_EST 60 // s
/* time interval of taps for sample rate offset estimation (time stamps) */
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
// time interval of taps for sample rate offset estimation (time stamps)
#define INTVL_TAPS_SAM_OFF_SET 1 // s
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / MIN_BLOCK_DURATION_MS )
#define VEC_LEN_SAM_OFFS_EST ( TIME_INT_SAM_OFFS_EST / INTVL_TAPS_SAM_OFF_SET )
/* length of the moving average buffer for response time measurement */
#define TIME_MOV_AV_RESPONSE 30 /* seconds */
// length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE 30 // seconds
#define LEN_MOV_AV_RESPONSE ( TIME_MOV_AV_RESPONSE * 1000 / MIN_BLOCK_DURATION_MS )
#define _MAXSHORT 32767
#define _MAXBYTE 255 /* binary: 11111111 */
#define _MAXBYTE 255 // binary: 11111111
#define _MINSHORT ( -32768 )
#if HAVE_STDINT_H
@ -126,7 +126,7 @@ typedef unsigned char uint8_t;
/* Definitions for window message system ------------------------------------ */
typedef unsigned int _MESSAGE_IDENT;
#define MS_RESET_ALL 0 /* MS: Message */
#define MS_RESET_ALL 0 // MS: Message
#define MS_SOUND_IN 1
#define MS_SOUND_OUT 2
#define MS_JIT_BUF_PUT 3
@ -161,7 +161,7 @@ public:
/* Prototypes for global functions ********************************************/
/* Posting a window message */
// posting a window message
void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam = 0,
const int iChanNum = 0 );

View file

@ -46,20 +46,20 @@
/* Definitions ****************************************************************/
/* text strings for connection button for connect and disconnect */
// text strings for connection button for connect and disconnect
#define CON_BUT_CONNECTTEXT "C&onnect"
#define CON_BUT_DISCONNECTTEXT "D&isconnect"
/* steps for input level meter */
// steps for input level meter
#define NUM_STEPS_INP_LEV_METER 100
/* update time for GUI controls */
#define LEVELMETER_UPDATE_TIME 100 /* ms */
#define STATUSBAR_UPDATE_TIME 1000 /* ms */
// update time for GUI controls
#define LEVELMETER_UPDATE_TIME 100 // ms
#define STATUSBAR_UPDATE_TIME 1000 // ms
/* range for signal level meter */
#define LOW_BOUND_SIG_METER ( -50.0 ) /* dB */
#define UPPER_BOUND_SIG_METER ( 0.0 ) /* dB */
// range for signal level meter
#define LOW_BOUND_SIG_METER ( -50.0 ) // dB
#define UPPER_BOUND_SIG_METER ( 0.0 ) // dB
/* Classes ********************************************************************/

View file

@ -41,8 +41,8 @@
/* Definitions ****************************************************************/
/* update time for GUI controls */
#define GUI_CONTRL_UPDATE_TIME 1000 /* ms */
// update time for GUI controls
#define GUI_CONTRL_UPDATE_TIME 1000 // ms
/* Classes ********************************************************************/

View file

@ -166,10 +166,14 @@ void CMultiColorLEDbase::SetUpdateTime(int iNUTi)
{
/* Avoid too short intervals */
if ( iNUTi < MIN_TIME_FOR_RED_LIGHT )
{
iUpdateTime = MIN_TIME_FOR_RED_LIGHT;
}
else
{
iUpdateTime = iNUTi;
}
}
CMultiColorLED::CMultiColorLED ( QWidget* parent, const char* name, WFlags f ) :

View file

@ -43,7 +43,7 @@
/* Definitions ****************************************************************/
#define DEFAULT_UPDATE_TIME 300
/* The red and yellow light should be on at least this interval */
// the red and yellow light should be on at least this interval
#define MIN_TIME_FOR_RED_LIGHT 100
@ -63,7 +63,7 @@ protected:
enum ELightColor { RL_GREY, RL_RED, RL_GREEN, RL_YELLOW };
ELightColor eColorFlag;
virtual void SetPixmap(QPixmap& NewBitmap) {} /* must be implemented in derived class! */
virtual void SetPixmap ( QPixmap& NewBitmap ) {} // must be implemented in derived class!
void UpdateColor();
QPixmap BitmCubeGreen;

View file

@ -48,7 +48,7 @@
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
// lengths of message as defined in protocol.cpp file
#define MESS_HEADER_LENGTH_BYTE 7 /* TAG (2), ID (2), cnt (1), length (2) */
#define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2)
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
// time out for message re-send if no acknowledgement was received

View file

@ -71,11 +71,11 @@ protected:
QTimer Timer;
CVector<short> vecsSendData;
/* actual working objects */
// actual working objects
CChannelSet ChannelSet;
CSocket Socket;
/* debugging, evaluating */
// debugging, evaluating
CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock;

View file

@ -56,42 +56,50 @@ void CSettings::ReadIniFile()
pClient->strName = GetIniSetting ( ini, "Client", "name" );
// audio fader
if ( GetNumericIniSet(ini, "Client", "audfad", 0, AUD_FADER_IN_MAX, iValue ) == TRUE ) {
if ( GetNumericIniSet ( ini, "Client", "audfad", 0, AUD_FADER_IN_MAX, iValue ) == TRUE )
{
pClient->SetAudioInFader ( iValue );
}
// reverberation level
if ( GetNumericIniSet(ini, "Client", "revlev", 0, AUD_REVERB_MAX, iValue ) == TRUE ) {
if ( GetNumericIniSet(ini, "Client", "revlev", 0, AUD_REVERB_MAX, iValue ) == TRUE )
{
pClient->SetReverbLevel ( iValue );
}
// reverberation channel assignment
if ( GetFlagIniSet(ini, "Client", "reverblchan", bValue ) == TRUE ) {
if ( GetFlagIniSet ( ini, "Client", "reverblchan", bValue ) == TRUE )
{
pClient->SetReverbOnLeftChan ( bValue );
}
// sound card in number of buffers
if ( GetNumericIniSet(ini, "Client", "audinbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE ) {
if ( GetNumericIniSet ( ini, "Client", "audinbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE )
{
pClient->GetSndInterface()->SetInNumBuf( iValue );
}
// sound card out number of buffers
if ( GetNumericIniSet(ini, "Client", "audoutbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE ) {
if ( GetNumericIniSet ( ini, "Client", "audoutbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE )
{
pClient->GetSndInterface()->SetOutNumBuf ( iValue );
}
// network jitter buffer size
if ( GetNumericIniSet(ini, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) == TRUE ) {
if ( GetNumericIniSet ( ini, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) == TRUE )
{
pClient->SetSockBufSize ( iValue );
}
// network buffer size factor in
if ( GetNumericIniSet(ini, "Client", "netwbusifactin", 1, MAX_NET_BLOCK_SIZE_FACTOR, 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, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE ) {
if ( GetNumericIniSet ( ini, "Client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE )
{
pClient->SetNetwBufSizeFactOut ( iValue );
}
}
@ -235,8 +243,10 @@ string CSettings::GetIniSetting(CSettings::INIFile& theINI, const char* section,
INISection::iterator apair = iSection->second.find ( string ( key ) );
if ( apair != iSection->second.end() )
{
result = apair->second;
}
}
return result;
}
@ -260,18 +270,23 @@ void CSettings::PutIniSetting(CSettings::INIFile &theINI, const char *section,
theINI.insert (
std::pair<string, INISection> ( string ( section ), newsection ) );
}
else if (key)
else
{
if ( key )
{
/* Found section, make sure key isn't in there already,
if it is, just drop and re-add */
apair = iniSection->second.find ( string ( key ) );
if ( apair != iniSection->second.end() )
{
iniSection->second.erase(apair);
}
iniSection->second.insert (
std::pair<string, string> ( string ( key ), string ( value ) ) );
}
}
}
CSettings::INIFile CSettings::LoadIni ( const char* filename )
{
@ -287,10 +302,14 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
file.getline ( buffer, sizeof ( buffer ) );
if ( ( temp = strchr ( buffer, '\n' ) ) )
{
*temp = '\0'; /* Cut off at newline */
}
if ( ( temp = strchr ( buffer, '\r' ) ) )
{
*temp = '\0'; /* Cut off at linefeeds */
}
if ( ( buffer[0] == '[' ) && ( temp = strrchr ( buffer, ']' ) ) )
{ /* if line is like --> [section name] */
@ -298,7 +317,9 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
section = &buffer[1];
PutIniSetting ( theINI, &buffer[1] ); /* Start new section */
}
else if (buffer[0] && (value = strchr(buffer, '=')))
else
{
if ( buffer[0] && ( value = strchr ( buffer, '=' ) ) )
{
/* Assign whatever follows = sign to value, chop at "=" */
*value++ = '\0';
@ -306,12 +327,17 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
/* And add both sides to INISection */
PutIniSetting ( theINI, section.c_str(), buffer, value );
}
else if (buffer[0])
else
{
if ( buffer[0] )
{
/* Must be a comment or something */
PutIniSetting ( theINI, section.c_str(), buffer, "" );
}
}
}
}
return theINI;
}
@ -321,7 +347,9 @@ void CSettings::SaveIni(CSettings::INIFile &theINI, const char* filename)
std::fstream file ( filename, std::ios::out );
if ( !file.good() )
{
return;
}
/* Just iterate the hashes and values and dump them to a file */
INIFile::iterator section = theINI.begin();
@ -338,17 +366,23 @@ void CSettings::SaveIni(CSettings::INIFile &theINI, const char* filename)
bFirstSection = FALSE;
}
else
{
file << std::endl << "[" << section->first << "]" << std::endl;
}
}
INISection::iterator pair = section->second.begin();
while ( pair != section->second.end() )
{
if ( pair->second > "" )
{
file << pair->first << "=" << pair->second << std::endl;
}
else
{
file << pair->first << "=" << std::endl;
}
pair++;
}
section++;
@ -376,7 +410,9 @@ bool CSettings::StlIniCompareStringNoCase::operator()(const string& x,
{
nResult = toupper ( *p1 ) - toupper ( *p2 );
if ( nResult != 0 )
{
break;
}
p1++;
p2++;
nCount++;
@ -384,12 +420,18 @@ bool CSettings::StlIniCompareStringNoCase::operator()(const string& x,
if ( nResult == 0 )
{
if ( *p1 && !*p2 )
{
nResult = -1;
}
if ( !*p1 && *p2 )
{
nResult = 1;
}
}
if ( nResult < 0 )
{
return true;
}
return false;
#endif /* strcasecmp */
#endif

View file

@ -54,13 +54,13 @@ protected:
void ReadIniFile();
void WriteIniFile();
/* Function declarations for stlini code written by Robert Kesterson */
// function declarations for stlini code written by Robert Kesterson
struct StlIniCompareStringNoCase
{
bool operator() ( const std::string& x, const std::string& y ) const;
};
/* These typedefs just make the code a bit more readable */
// these typedefs just make the code a bit more readable
typedef std::map<string, string, StlIniCompareStringNoCase > INISection;
typedef std::map<string, INISection , StlIniCompareStringNoCase > INIFile;
@ -81,7 +81,7 @@ protected:
bool GetFlagIniSet ( INIFile& theINI, string strSection, string strKey,
bool& bValue );
/* Pointer to the client object needed for the various settings */
// pointer to the client object needed for the various settings
CClient* pClient;
};

View file

@ -37,7 +37,7 @@
/* Definitions ****************************************************************/
/* maximum block size for network input buffer. Consider two bytes per sample */
// maximum block size for network input buffer. Consider two bytes per sample
#define MAX_SIZE_BYTES_NETW_BUF ( MAX_NET_BLOCK_SIZE_FACTOR * MIN_BLOCK_SIZE_SAMPLES * 2 )
@ -67,8 +67,8 @@ protected:
CVector<unsigned char> vecbyRecBuf;
CHostAddress RecHostAddr;
CChannel* pChannel; /* for client */
CChannelSet* pChannelSet; /* for server */
CChannel* pChannel; // for client
CChannelSet* pChannelSet; // for server
QObject* pServer;
bool bIsClient;

View file

@ -29,16 +29,16 @@
/* Input level meter implementation ------------------------------------------ */
void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
{
/* Do the update for entire vector */
// do the update for entire vector
const int iVecSize = vecdAudio.Size();
for ( int i = 0; i < iVecSize; i++ )
{
/* norm of current audio sample */
// norm of current audio sample
const double dCurSig = fabs ( vecdAudio[i] );
/* search for maximum. Decrease this max with time */
/* decrease max with time */
// search for maximum. Decrease this max with time
// decrease max with time
if ( dCurLevel >= METER_FLY_BACK )
{
dCurLevel *= 0.9999;
@ -48,7 +48,7 @@ void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
dCurLevel = 0;
}
/* search for max */
// search for max
if ( dCurSig > dCurLevel )
{
dCurLevel = dCurSig;
@ -60,14 +60,14 @@ double CSignalLevelMeter::MicLevel ()
{
const double dNormMicLevel = dCurLevel / _MAXSHORT;
/* logarithmic measure */
// logarithmic measure
if ( dNormMicLevel > 0 )
{
return 20.0 * log10 ( dNormMicLevel );
}
else
{
return -100000.0; /* large negative value */
return -100000.0; // large negative value
}
}
@ -84,7 +84,7 @@ void CCRC::AddByte ( const uint8_t byNewInput )
{
for ( int i = 0; i < 8; i++ )
{
/* Shift bits in shift-register for transistion */
// shift bits in shift-register for transistion
iStateShiftReg <<= 1;
/* Take bit, which was shifted out of the register-size and place it
@ -95,13 +95,13 @@ void CCRC::AddByte ( const uint8_t byNewInput )
iStateShiftReg |= 1;
}
/* Add new data bit to the LSB */
// add new data bit to the LSB
if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 )
{
iStateShiftReg ^= 1;
}
/* Add mask to shift-register if first bit is true */
// add mask to shift-register if first bit is true
if ( iStateShiftReg & 1 )
{
iStateShiftReg ^= iPoly;
@ -111,10 +111,10 @@ void CCRC::AddByte ( const uint8_t byNewInput )
uint32_t CCRC::GetCRC()
{
/* Return inverted shift-register (1's complement) */
// return inverted shift-register (1's complement)
iStateShiftReg = ~iStateShiftReg;
/* Remove bit which where shifted out of the shift-register frame */
// remove bit which where shifted out of the shift-register frame
return iStateShiftReg & ( iBitOutMask - 1 );
}
@ -138,7 +138,7 @@ CAudioReverb::CAudioReverb ( const double rT60 )
{
int delay, i;
/* 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 };
const double scaler = (double) SAMPLE_RATE / 44100.0;
@ -272,14 +272,14 @@ double CAudioReverb::ProcessSample ( const double input )
CAboutDlg::CAboutDlg ( QWidget* parent, const char* name, bool modal, WFlags f )
: CAboutDlgBase ( parent, name, modal, f )
{
/* Set the text for the about dialog html text control */
// set the text for the about dialog html text control
TextViewCredits->setText (
"<p>" /* General description of llcon software */
"<p>" // general description of llcon software
"<big><b>llcon</b> " + tr("Client/Server communication tool to enable "
"musician to play together through a conventional broadband internet "
"connection (like DSL).") + "</big>"
"</p><br>"
"<p><font face=\"courier\">" /* GPL header text */
"<p><font face=\"courier\">" // GPL header text
"This program is free software; you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation; either version 2 of the License, or "
@ -292,7 +292,7 @@ CAboutDlg::CAboutDlg(QWidget* parent, const char* name, bool modal, WFlags f)
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 "
"USA"
"</font></p><br>"
"<p>" /* Libraries used by this compilation of Dream */
"<p>" // libraries used by this compilation of Dream
"<b>" + tr("llcon uses the following libraries or code snippets:") +
"</b></p>"
"<ul>"
@ -305,7 +305,7 @@ CAboutDlg::CAboutDlg(QWidget* parent, const char* name, bool modal, WFlags f)
"</ul>"
"</center><br>");
/* Set version number in about dialog */
// set version number in about dialog
TextLabelVersion->setText ( GetVersionAndNameStr() );
}
@ -355,7 +355,7 @@ QString CAboutDlg::GetVersionAndNameStr ( const bool bWithHtml )
/* Help menu ---------------------------------------------------------------- */
CLlconHelpMenu::CLlconHelpMenu ( QWidget* parent ) : QPopupMenu ( parent )
{
/* Standard help menu consists of about and what's this help */
// standard help menu consists of about and what's this help
insertItem ( tr ( "What's &This" ), this,
SLOT ( OnHelpWhatsThis () ), SHIFT+Key_F1 );
insertSeparator();

View file

@ -33,7 +33,7 @@
#include <qdatetime.h>
#include <vector>
#include "global.h"
using namespace std; /* Because of the library: "vector" */
using namespace std; // because of the library: "vector"
#ifdef _WIN32
# include "../windows/moc/aboutdlgbase.h"
#else
@ -46,21 +46,25 @@ using namespace std; /* Because of the library: "vector" */
/* Global functions ***********************************************************/
/* Converting double to short */
// converting double to short
inline short Double2Short ( const double dInput )
{
/* Lower bound */
// lower bound
if ( dInput < _MINSHORT )
{
return _MINSHORT;
}
/* Upper bound */
// upper bound
if ( dInput > _MAXSHORT )
{
return _MAXSHORT;
}
return (short) dInput;
}
/* Debug error handling */
// debug error handling
void DebugError ( const char* pchErDescr, const char* pchPar1Descr,
const double dPar1, const char* pchPar2Descr,
const double dPar2 );
@ -87,7 +91,7 @@ public:
void Init ( const int iNewSize );
/* Use this init to give all elements a defined value */
// use this init to give all elements a defined value
void Init ( const int iNewSize, const TData tIniVal );
void Reset ( const TData tResetVal );
@ -159,10 +163,10 @@ template<class TData> void CVector<TData>::Init(const int iNewSize)
template<class TData> void CVector<TData>::Init ( const int iNewSize,
const TData tIniVal )
{
/* Call actual init routine */
// call actual init routine
Init ( iNewSize );
/* Set values */
// set values
Reset ( tIniVal );
}
@ -178,10 +182,12 @@ template<class TData> void CVector<TData>::Enlarge(const int iAddedSize)
template<class TData> void CVector<TData>::Reset ( const TData tResetVal )
{
/* Set all values to reset value */
// set all values to reset value
for ( int i = 0; i < iVectorSize; i++ )
{
pData[i] = tResetVal;
}
}
/******************************************************************************\
@ -222,11 +228,13 @@ template<class TData> void CFIFO<TData>::Add(const TData tNewD)
{
this->pData[iCurIdx] = tNewD;
/* Increment index */
// increment index
iCurIdx++;
if ( iCurIdx >= this->iVectorSize )
{
iCurIdx = 0;
}
}
/******************************************************************************\
@ -246,8 +254,14 @@ public:
void Add ( const TData tNewD );
inline TData GetAverage()
{
if (this->iNorm == 0) return TData(0);
else return tCurAvResult / this->iNorm;
if ( this->iNorm == 0 )
{
return TData ( 0 );
}
else
{
return tCurAvResult / this->iNorm;
}
}
virtual void Init ( const int iNewSize );
@ -263,7 +277,7 @@ template<class TData> void CMovingAv<TData>::Init(const int iNewSize)
{
iNorm = 0;
iCurIdx = 0;
tCurAvResult = TData(0); /* Only for scalars! */
tCurAvResult = TData ( 0 ); // only for scalars!
CVector<TData>::Init ( iNewSize );
}
@ -274,22 +288,26 @@ template<class TData> void CMovingAv<TData>::Add(const TData tNewD)
subtract the old value from the result. We only need one addition and a
history buffer
*/
/* Subtract oldest value */
// subtract oldest value
tCurAvResult -= this->pData[iCurIdx];
/* Add new value and write in memory */
// add new value and write in memory
tCurAvResult += tNewD;
this->pData[iCurIdx] = tNewD;
/* Increase position pointer and test if wrap */
// increase position pointer and test if wrap
iCurIdx++;
if ( iCurIdx >= this->iVectorSize )
{
iCurIdx = 0;
}
/* take care of norm */
// take care of norm
if ( this->iNorm < this->iVectorSize )
{
this->iNorm++;
}
}
/******************************************************************************\
@ -350,10 +368,10 @@ public:
CHostAddress ( const CHostAddress& NHAddr ) :
InetAddr ( NHAddr.InetAddr ), iPort ( NHAddr.iPort ) {}
/* copy and compare operators */
// copy and compare operators
CHostAddress& operator= ( const CHostAddress& NHAddr )
{ InetAddr = NHAddr.InetAddr; iPort = NHAddr.iPort; return *this; }
bool operator==(const CHostAddress& CompAddr) /* oompare operator */
bool operator== ( const CHostAddress& CompAddr ) // compare operator
{ return ( ( CompAddr.InetAddr == InetAddr ) && ( CompAddr.iPort == iPort ) ); }
QHostAddress InetAddr;

View file

@ -37,50 +37,62 @@ bool CSound::Read(CVector<short>& psData)
int i;
bool bError;
/* Check if device must be opened or reinitialized */
// check if device must be opened or reinitialized
if ( bChangParamIn == TRUE )
{
OpenInDevice();
/* Reinit sound interface */
// Reinit sound interface
InitRecording ( iBufferSizeIn, bBlockingRec );
/* Reset flag */
// Reset flag
bChangParamIn = FALSE;
}
/* Wait until data is available */
// wait until data is available
if ( ! ( m_WaveInHeader[iWhichBufferIn].dwFlags & WHDR_DONE ) )
{
if ( bBlockingRec == TRUE )
{
WaitForSingleObject ( m_WaveInEvent, INFINITE );
}
else
{
return FALSE;
}
}
/* Check if buffers got lost */
// check if buffers got lost
int iNumInBufDone = 0;
for ( i = 0; i < iCurNumSndBufIn; i++ )
{
if ( m_WaveInHeader[i].dwFlags & WHDR_DONE )
{
iNumInBufDone++;
}
}
/* If the number of done buffers equals the total number of buffers, it is
very likely that a buffer got lost -> set error flag */
if ( iNumInBufDone == iCurNumSndBufIn )
{
bError = TRUE;
}
else
{
bError = FALSE;
}
/* Copy data from sound card in output buffer */
// copy data from sound card in output buffer
for ( i = 0; i < iBufferSizeIn; i++ )
{
psData[i] = psSoundcardBuffer[iWhichBufferIn][i];
}
/* Add the buffer so that it can be filled with new samples */
// add the buffer so that it can be filled with new samples
AddInBuffer();
/* In case more than one buffer was ready, reset event */
// in case more than one buffer was ready, reset event
ResetEvent ( m_WaveInEvent );
return bError;
@ -88,57 +100,59 @@ bool CSound::Read(CVector<short>& psData)
void CSound::AddInBuffer()
{
/* Unprepare old wave-header */
// unprepare old wave-header
waveInUnprepareHeader (
m_WaveIn, &m_WaveInHeader[iWhichBufferIn], sizeof ( WAVEHDR ) );
/* Prepare buffers for sending to sound interface */
// prepare buffers for sending to sound interface
PrepareInBuffer ( iWhichBufferIn );
/* Send buffer to driver for filling with new data */
// send buffer to driver for filling with new data
waveInAddBuffer ( m_WaveIn, &m_WaveInHeader[iWhichBufferIn], sizeof ( WAVEHDR ) );
/* Toggle buffers */
// toggle buffers
iWhichBufferIn++;
if ( iWhichBufferIn == iCurNumSndBufIn )
{
iWhichBufferIn = 0;
}
}
void CSound::PrepareInBuffer ( int iBufNum )
{
/* Set struct entries */
// set struct entries
m_WaveInHeader[iBufNum].lpData = (LPSTR) &psSoundcardBuffer[iBufNum][0];
m_WaveInHeader[iBufNum].dwBufferLength = iBufferSizeIn * BYTES_PER_SAMPLE;
m_WaveInHeader[iBufNum].dwFlags = 0;
/* Prepare wave-header */
// prepare wave-header
waveInPrepareHeader ( m_WaveIn, &m_WaveInHeader[iBufNum], sizeof ( WAVEHDR ) );
}
void CSound::InitRecording ( int iNewBufferSize, bool bNewBlocking )
{
/* Check if device must be opened or reinitialized */
// check if device must be opened or reinitialized
if ( bChangParamIn == TRUE )
{
OpenInDevice();
/* Reset flag */
// reset flag
bChangParamIn = FALSE;
}
/* Set internal parameter */
// set internal parameter
iBufferSizeIn = iNewBufferSize;
bBlockingRec = bNewBlocking;
/* Reset interface so that all buffers are returned from the interface */
// reset interface so that all buffers are returned from the interface
waveInReset ( m_WaveIn );
waveInStop ( m_WaveIn );
/* Reset current buffer ID (it is important to do this BEFORE calling
/* reset current buffer ID (it is important to do this BEFORE calling
"AddInBuffer()" */
iWhichBufferIn = 0;
/* Create memory for sound card buffer */
// create memory for sound card buffer
for ( int i = 0; i < iCurNumSndBufIn; i++ )
{
/* Unprepare old wave-header in case that we "re-initialized" this
@ -148,19 +162,21 @@ void CSound::InitRecording(int iNewBufferSize, bool bNewBlocking)
waveInUnprepareHeader ( m_WaveIn, &m_WaveInHeader[i], sizeof ( WAVEHDR ) );
if ( psSoundcardBuffer[i] != NULL )
{
delete[] psSoundcardBuffer[i];
}
psSoundcardBuffer[i] = new short[iBufferSizeIn];
/* Send all buffers to driver for filling the queue ----------------- */
/* Prepare buffers before sending them to the sound interface */
// prepare buffers before sending them to the sound interface
PrepareInBuffer ( i );
AddInBuffer();
}
/* Notify that sound capturing can start now */
// notify that sound capturing can start now
waveInStart ( m_WaveIn );
/* This reset event is very important for initialization, otherwise we will
@ -170,7 +186,7 @@ void CSound::InitRecording(int iNewBufferSize, bool bNewBlocking)
void CSound::OpenInDevice()
{
/* Open wave-input and set call-back mechanism to event handle */
// open wave-input and set call-back mechanism to event handle
if ( m_WaveIn != NULL )
{
waveInReset ( m_WaveIn );
@ -189,11 +205,13 @@ void CSound::OpenInDevice()
void CSound::SetInDev ( int iNewDev )
{
/* Set device to wave mapper if iNewDev is invalid */
// set device to wave mapper if iNewDev is invalid
if ( ( iNewDev >= iNumDevs ) || ( iNewDev < 0 ) )
{
iNewDev = WAVE_MAPPER;
}
/* Change only in case new device id is not already active */
// change only in case new device id is not already active
if ( iNewDev != iCurInDev )
{
iCurInDev = iNewDev;
@ -203,11 +221,13 @@ void CSound::SetInDev(int iNewDev)
void CSound::SetInNumBuf ( int iNewNum )
{
/* check new parameter */
// check new parameter
if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) )
{
iNewNum = NUM_SOUND_BUFFERS_IN;
}
/* Change only if parameter is different */
// change only if parameter is different
if ( iNewNum != iCurNumSndBufIn )
{
iCurNumSndBufIn = iNewNum;
@ -226,22 +246,22 @@ bool CSound::Write(CVector<short>& psData)
int iIndexDoneBuf;
bool bError;
/* Check if device must be opened or reinitialized */
// check if device must be opened or reinitialized
if ( bChangParamOut == TRUE )
{
OpenOutDevice();
/* Reinit sound interface */
// reinit sound interface
InitPlayback ( iBufferSizeOut, bBlockingPlay );
/* Reset flag */
// reset flag
bChangParamOut = FALSE;
}
/* Get number of "done"-buffers and position of one of them */
// get number of "done"-buffers and position of one of them
GetDoneBuffer ( iCntPrepBuf, iIndexDoneBuf );
/* Now check special cases (Buffer is full or empty) */
// now check special cases (Buffer is full or empty)
if ( iCntPrepBuf == 0 )
{
if ( bBlockingPlay == TRUE )
@ -261,38 +281,47 @@ bool CSound::Write(CVector<short>& psData)
/* All buffers are filled, dump new block ----------------------- */
// It would be better to kill half of the buffer blocks to set the start
// back to the middle: TODO
return TRUE; /* An error occurred */
return TRUE; // an error occurred
}
}
else if (iCntPrepBuf == iCurNumSndBufOut)
else
{
/* ---------------------------------------------------------------------
if ( iCntPrepBuf == iCurNumSndBufOut )
{
/* -----------------------------------------------------------------
Buffer is empty -> send as many cleared blocks to the sound-
interface until half of the buffer size is reached */
/* Send half of the buffer size blocks to the sound-interface */
// send half of the buffer size blocks to the sound-interface
for ( j = 0; j < iCurNumSndBufOut / 2; j++ )
{
/* First, clear these buffers */
// first, clear these buffers
for ( i = 0; i < iBufferSizeOut; i++ )
{
psPlaybackBuffer[j][i] = 0;
}
/* Then send them to the interface */
// then send them to the interface
AddOutBuffer ( j );
}
/* Set index for done buffer */
// set index for done buffer
iIndexDoneBuf = iCurNumSndBufOut / 2;
bError = TRUE;
}
else
{
bError = FALSE;
}
}
/* Copy stereo data from input in soundcard buffer */
// copy stereo data from input in soundcard buffer
for ( i = 0; i < iBufferSizeOut; i++ )
{
psPlaybackBuffer[iIndexDoneBuf][i] = psData[i];
}
/* Now, send the current block */
// now, send the current block
AddOutBuffer ( iIndexDoneBuf );
return bError;
@ -300,7 +329,7 @@ bool CSound::Write(CVector<short>& psData)
void CSound::GetDoneBuffer ( int& iCntPrepBuf, int& iIndexDoneBuf )
{
/* Get number of "done"-buffers and position of one of them */
// get number of "done"-buffers and position of one of them
iCntPrepBuf = 0;
for ( int i = 0; i < iCurNumSndBufOut; i++ )
{
@ -314,25 +343,25 @@ void CSound::GetDoneBuffer(int& iCntPrepBuf, int& iIndexDoneBuf)
void CSound::AddOutBuffer ( int iBufNum )
{
/* Unprepare old wave-header */
// Unprepare old wave-header
waveOutUnprepareHeader (
m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
/* Prepare buffers for sending to sound interface */
// Prepare buffers for sending to sound interface
PrepareOutBuffer ( iBufNum );
/* Send buffer to driver for filling with new data */
// Send buffer to driver for filling with new data
waveOutWrite ( m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
}
void CSound::PrepareOutBuffer ( int iBufNum )
{
/* Set Header data */
// Set Header data
m_WaveOutHeader[iBufNum].lpData = (LPSTR) &psPlaybackBuffer[iBufNum][0];
m_WaveOutHeader[iBufNum].dwBufferLength = iBufferSizeOut * BYTES_PER_SAMPLE;
m_WaveOutHeader[iBufNum].dwFlags = 0;
/* Prepare wave-header */
// Prepare wave-header
waveOutPrepareHeader ( m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
}
@ -340,20 +369,20 @@ void CSound::InitPlayback(int iNewBufferSize, bool bNewBlocking)
{
int i, j;
/* Check if device must be opened or reinitialized */
// check if device must be opened or reinitialized
if ( bChangParamOut == TRUE )
{
OpenOutDevice();
/* Reset flag */
// reset flag
bChangParamOut = FALSE;
}
/* Set internal parameters */
// set internal parameters
iBufferSizeOut = iNewBufferSize;
bBlockingPlay = bNewBlocking;
/* Reset interface */
// reset interface
waveOutReset ( m_WaveOut );
for ( j = 0; j < iCurNumSndBufOut; j++ )
@ -362,20 +391,24 @@ void CSound::InitPlayback(int iNewBufferSize, bool bNewBlocking)
simply nothing happens with this function call */
waveOutUnprepareHeader ( m_WaveOut, &m_WaveOutHeader[j], sizeof ( WAVEHDR ) );
/* Create memory for playback buffer */
// create memory for playback buffer
if ( psPlaybackBuffer[j] != NULL )
{
delete[] psPlaybackBuffer[j];
}
psPlaybackBuffer[j] = new short[iBufferSizeOut];
/* Clear new buffer */
// clear new buffer
for ( i = 0; i < iBufferSizeOut; i++ )
{
psPlaybackBuffer[j][i] = 0;
}
/* Prepare buffer for sending to the sound interface */
// prepare buffer for sending to the sound interface
PrepareOutBuffer ( j );
/* Initially, send all buffers to the interface */
// initially, send all buffers to the interface
AddOutBuffer ( j );
}
}
@ -392,16 +425,20 @@ void CSound::OpenOutDevice()
(DWORD) m_WaveOutEvent, NULL, CALLBACK_EVENT );
if ( result != MMSYSERR_NOERROR )
{
throw CGenErr ( "Sound Interface Start, waveOutOpen() failed." );
}
}
void CSound::SetOutDev ( int iNewDev )
{
/* Set device to wave mapper if iNewDev is invalid */
// set device to wave mapper if iNewDev is invalid
if ( ( iNewDev >= iNumDevs ) || ( iNewDev < 0 ) )
{
iNewDev = WAVE_MAPPER;
}
/* Change only in case new device id is not already active */
// change only in case new device id is not already active
if ( iNewDev != iCurOutDev )
{
iCurOutDev = iNewDev;
@ -411,11 +448,13 @@ void CSound::SetOutDev(int iNewDev)
void CSound::SetOutNumBuf ( int iNewNum )
{
/* check new parameter */
// check new parameter
if ( ( iNewNum >= MAX_SND_BUF_OUT ) || ( iNewNum < 1 ) )
{
iNewNum = NUM_SOUND_BUFFERS_OUT;
}
/* Change only if parameter is different */
// change only if parameter is different
if ( iNewNum != iCurNumSndBufOut )
{
iCurNumSndBufOut = iNewNum;
@ -432,29 +471,37 @@ void CSound::Close()
int i;
MMRESULT result;
/* Reset audio driver */
// reset audio driver
if ( m_WaveOut != NULL )
{
result = waveOutReset ( m_WaveOut );
if ( result != MMSYSERR_NOERROR )
{
throw CGenErr ( "Sound Interface, waveOutReset() failed." );
}
}
if ( m_WaveIn != NULL )
{
result = waveInReset ( m_WaveIn );
if ( result != MMSYSERR_NOERROR )
{
throw CGenErr ( "Sound Interface, waveInReset() failed." );
}
}
/* Set event to ensure that thread leaves the waiting function */
// set event to ensure that thread leaves the waiting function
if ( m_WaveInEvent != NULL )
{
SetEvent(m_WaveInEvent);
}
/* Wait for the thread to terminate */
// wait for the thread to terminate
Sleep ( 500 );
/* Unprepare wave-headers */
// unprepare wave-headers
if ( m_WaveIn != NULL )
{
for ( i = 0; i < iCurNumSndBufIn; i++ )
@ -469,11 +516,13 @@ void CSound::Close()
}
}
/* Close the sound in device */
// close the sound in device
result = waveInClose ( m_WaveIn );
if ( result != MMSYSERR_NOERROR )
{
throw CGenErr ( "Sound Interface, waveInClose() failed." );
}
}
if ( m_WaveOut != NULL )
{
@ -489,13 +538,15 @@ void CSound::Close()
}
}
/* Close the sound out device */
// close the sound out device
result = waveOutClose ( m_WaveOut );
if ( result != MMSYSERR_NOERROR )
{
throw CGenErr ( "Sound Interface, waveOutClose() failed." );
}
}
/* Set flag to open devices the next time it is initialized */
// set flag to open devices the next time it is initialized
bChangParamIn = TRUE;
bChangParamOut = TRUE;
}
@ -504,17 +555,17 @@ CSound::CSound()
{
int i;
/* init number of sound buffers */
// init number of sound buffers
iCurNumSndBufIn = NUM_SOUND_BUFFERS_IN;
iCurNumSndBufOut = NUM_SOUND_BUFFERS_OUT;
/* Should be initialized because an error can occur during init */
// should be initialized because an error can occur during init
m_WaveInEvent = NULL;
m_WaveOutEvent = NULL;
m_WaveIn = NULL;
m_WaveOut = NULL;
/* Init buffer pointer to zero */
// init buffer pointer to zero
for ( i = 0; i < MAX_SND_BUF_IN; i++ )
{
memset ( &m_WaveInHeader[i], 0, sizeof ( WAVEHDR ) );
@ -527,7 +578,7 @@ CSound::CSound()
psPlaybackBuffer[i] = NULL;
}
/* Init wave-format structure */
// init wave-format structure
sWaveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
sWaveFormatEx.nChannels = NUM_IN_OUT_CHANNELS;
sWaveFormatEx.wBitsPerSample = BITS_PER_SAMPLE;
@ -538,40 +589,46 @@ CSound::CSound()
sWaveFormatEx.nSamplesPerSec;
sWaveFormatEx.cbSize = 0;
/* Get the number of digital audio devices in this computer, check range */
// get the number of digital audio devices in this computer, check range
iNumDevs = waveInGetNumDevs();
if ( iNumDevs > MAX_NUMBER_SOUND_CARDS )
{
iNumDevs = MAX_NUMBER_SOUND_CARDS;
}
/* At least one device must exist in the system */
// at least one device must exist in the system
if ( iNumDevs == 0 )
{
throw CGenErr ( "No audio device found." );
}
/* Get info about the devices and store the names */
// get info about the devices and store the names
for ( i = 0; i < iNumDevs; i++ )
{
if ( !waveInGetDevCaps ( i, &m_WaveInDevCaps, sizeof ( WAVEINCAPS ) ) )
{
pstrDevices[i] = m_WaveInDevCaps.szPname;
}
}
/* We use an event controlled wave-in (wave-out) structure */
/* Create events */
// we use an event controlled wave-in (wave-out) structure
// create events
m_WaveInEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
m_WaveOutEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
/* Set flag to open devices */
// set flag to open devices
bChangParamIn = TRUE;
bChangParamOut = TRUE;
/* Default device number, "wave mapper" */
// default device number, "wave mapper"
iCurInDev = WAVE_MAPPER;
iCurOutDev = WAVE_MAPPER;
/* Non-blocking wave out is default */
// non-blocking wave out is default
bBlockingPlay = FALSE;
/* Blocking wave in is default */
// blocking wave in is default
bBlockingRec = TRUE;
}
@ -579,23 +636,31 @@ CSound::~CSound()
{
int i;
/* Delete allocated memory */
// delete allocated memory
for ( i = 0; i < iCurNumSndBufIn; i++ )
{
if ( psSoundcardBuffer[i] != NULL )
{
delete[] psSoundcardBuffer[i];
}
}
for ( i = 0; i < iCurNumSndBufOut; i++ )
{
if ( psPlaybackBuffer[i] != NULL )
{
delete[] psPlaybackBuffer[i];
}
}
/* Close the handle for the events */
// close the handle for the events
if ( m_WaveInEvent != NULL )
{
CloseHandle ( m_WaveInEvent );
}
if ( m_WaveOutEvent != NULL )
{
CloseHandle ( m_WaveOutEvent );
}
}

View file

@ -36,8 +36,8 @@
/* Definitions ****************************************************************/
#define NUM_IN_OUT_CHANNELS 2 /* Stereo recording (but we only
use one channel for recording) */
#define BITS_PER_SAMPLE 16 /* Use all bits of the D/A-converter */
#define BYTES_PER_SAMPLE 2 /* Number of bytes per sample */
#define BITS_PER_SAMPLE 16 // use all bits of the D/A-converter
#define BYTES_PER_SAMPLE 2 // number of bytes per sample
#define MAX_SND_BUF_IN 200
#define MAX_SND_BUF_OUT 200
@ -45,7 +45,7 @@
#define NUM_SOUND_BUFFERS_IN ( 70 / MIN_BLOCK_DURATION_MS )
#define NUM_SOUND_BUFFERS_OUT ( 80 / MIN_BLOCK_DURATION_MS )
/* Maximum number of recognized sound cards installed in the system */
// maximum number of recognized sound cards installed in the system
#define MAX_NUMBER_SOUND_CARDS 10
@ -93,7 +93,7 @@ protected:
int iCurNumSndBufIn;
int iCurNumSndBufOut;
/* Wave in */
// wave in
WAVEINCAPS m_WaveInDevCaps;
HWAVEIN m_WaveIn;
HANDLE m_WaveInEvent;
@ -103,7 +103,7 @@ protected:
short* psSoundcardBuffer[MAX_SND_BUF_IN];
bool bBlockingRec;
/* Wave out */
// wave out
int iBufferSizeOut;
HWAVEOUT m_WaveOut;
short* psPlaybackBuffer[MAX_SND_BUF_OUT];