new code style
This commit is contained in:
parent
56f6fee1e0
commit
d49a2b2731
30 changed files with 1109 additions and 912 deletions
|
@ -90,7 +90,9 @@ CVector<short> CAudioCompression::Decode(const CVector<unsigned char>& vecbyAdpc
|
||||||
{
|
{
|
||||||
int current = vecbyAdpcm[2 * i] | ( vecbyAdpcm[2 * i + 1] << 8 );
|
int current = vecbyAdpcm[2 * i] | ( vecbyAdpcm[2 * i + 1] << 8 );
|
||||||
if ( current & 0x8000 )
|
if ( current & 0x8000 )
|
||||||
|
{
|
||||||
current -= 0x10000;
|
current -= 0x10000;
|
||||||
|
}
|
||||||
|
|
||||||
vecsOut[i] = (short) current;
|
vecsOut[i] = (short) current;
|
||||||
}
|
}
|
||||||
|
@ -170,9 +172,13 @@ CVector<unsigned char> CImaAdpcm::Encode(const CVector<short>& vecsAudio)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bytecode & 8 )
|
if ( bytecode & 8 )
|
||||||
|
{
|
||||||
iPrevAudio -= vpdiff;
|
iPrevAudio -= vpdiff;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
iPrevAudio += vpdiff;
|
iPrevAudio += vpdiff;
|
||||||
|
}
|
||||||
|
|
||||||
/* adjust step size */
|
/* adjust step size */
|
||||||
iStepindEnc += ima_indx_adjust[bytecode];
|
iStepindEnc += ima_indx_adjust[bytecode];
|
||||||
|
@ -210,7 +216,9 @@ CVector<short> CImaAdpcm::Decode(const CVector<unsigned char>& vecbyAdpcm)
|
||||||
/* read and check the block header --------------------------------------- */
|
/* read and check the block header --------------------------------------- */
|
||||||
int current = vecbyAdpcm[0] | ( vecbyAdpcm[1] << 8 );
|
int current = vecbyAdpcm[0] | ( vecbyAdpcm[1] << 8 );
|
||||||
if ( current & 0x8000 )
|
if ( current & 0x8000 )
|
||||||
|
{
|
||||||
current -= 0x10000;
|
current -= 0x10000;
|
||||||
|
}
|
||||||
|
|
||||||
/* get and bound step index */
|
/* get and bound step index */
|
||||||
int iStepindDec = CheckBounds ( vecbyAdpcm[2], 0, IMA_STEP_SIZE_TAB_LEN - 1 );
|
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;
|
int diff = step >> 3;
|
||||||
if ( bytecode & 1 )
|
if ( bytecode & 1 )
|
||||||
|
{
|
||||||
diff += step >> 2;
|
diff += step >> 2;
|
||||||
|
}
|
||||||
if ( bytecode & 2 )
|
if ( bytecode & 2 )
|
||||||
|
{
|
||||||
diff += step >> 1;
|
diff += step >> 1;
|
||||||
|
}
|
||||||
if ( bytecode & 4 )
|
if ( bytecode & 4 )
|
||||||
|
{
|
||||||
diff += step;
|
diff += step;
|
||||||
|
}
|
||||||
if ( bytecode & 8 )
|
if ( bytecode & 8 )
|
||||||
|
{
|
||||||
diff = -diff;
|
diff = -diff;
|
||||||
|
}
|
||||||
|
|
||||||
current += diff;
|
current += diff;
|
||||||
iStepindDec += ima_indx_adjust[bytecode];
|
iStepindDec += ima_indx_adjust[bytecode];
|
||||||
|
|
|
@ -68,7 +68,7 @@ protected:
|
||||||
int iAdpcmSize;
|
int iAdpcmSize;
|
||||||
int iStepindEnc;
|
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 )
|
inline int CheckBounds ( const int iData, const int iMin, const int iMax )
|
||||||
{
|
{
|
||||||
if ( iData > iMax )
|
if ( iData > iMax )
|
||||||
|
|
|
@ -46,14 +46,22 @@ void CNetBuf::Init ( const int iNewBlockSize, const int iNewNumBlocks )
|
||||||
|
|
||||||
/* initialize number of samples for fading effect */
|
/* initialize number of samples for fading effect */
|
||||||
if ( FADE_IN_OUT_NUM_SAM < iBlockSize )
|
if ( FADE_IN_OUT_NUM_SAM < iBlockSize )
|
||||||
|
{
|
||||||
iNumSamFading = iBlockSize;
|
iNumSamFading = iBlockSize;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
iNumSamFading = FADE_IN_OUT_NUM_SAM;
|
iNumSamFading = FADE_IN_OUT_NUM_SAM;
|
||||||
|
}
|
||||||
|
|
||||||
if ( FADE_IN_OUT_NUM_SAM_EXTRA > iBlockSize )
|
if ( FADE_IN_OUT_NUM_SAM_EXTRA > iBlockSize )
|
||||||
|
{
|
||||||
iNumSamFadingExtra = iBlockSize;
|
iNumSamFadingExtra = iBlockSize;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
iNumSamFadingExtra = FADE_IN_OUT_NUM_SAM;
|
iNumSamFadingExtra = FADE_IN_OUT_NUM_SAM;
|
||||||
|
}
|
||||||
|
|
||||||
/* init variables for extrapolation (in case a fade out is needed) */
|
/* init variables for extrapolation (in case a fade out is needed) */
|
||||||
dExPDiff = 0.0;
|
dExPDiff = 0.0;
|
||||||
|
@ -88,7 +96,9 @@ fflush(pFileBI);
|
||||||
|
|
||||||
/* fade in new block if required */
|
/* fade in new block if required */
|
||||||
if ( bFadeInNewPutData )
|
if ( bFadeInNewPutData )
|
||||||
|
{
|
||||||
FadeInAudioDataBlock ( vecdData );
|
FadeInAudioDataBlock ( vecdData );
|
||||||
|
}
|
||||||
|
|
||||||
/* copy new data in internal buffer */
|
/* copy new data in internal buffer */
|
||||||
int iCurPos = 0;
|
int iCurPos = 0;
|
||||||
|
@ -99,24 +109,34 @@ fflush(pFileBI);
|
||||||
|
|
||||||
/* 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)
|
while (iPutPos < iMemSize)
|
||||||
|
{
|
||||||
vecdMemory[iPutPos++] = vecdData[iCurPos++];
|
vecdMemory[iPutPos++] = vecdData[iCurPos++];
|
||||||
|
}
|
||||||
|
|
||||||
for ( iPutPos = 0; iPutPos < iRemSpace; iPutPos++ )
|
for ( iPutPos = 0; iPutPos < iRemSpace; iPutPos++ )
|
||||||
|
{
|
||||||
vecdMemory[iPutPos] = vecdData[iCurPos++];
|
vecdMemory[iPutPos] = vecdData[iCurPos++];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* data can be written in one step */
|
/* data can be written in one step */
|
||||||
const int iEnd = iPutPos + iInSize;
|
const int iEnd = iPutPos + iInSize;
|
||||||
while ( iPutPos < iEnd )
|
while ( iPutPos < iEnd )
|
||||||
|
{
|
||||||
vecdMemory[iPutPos++] = vecdData[iCurPos++];
|
vecdMemory[iPutPos++] = vecdData[iCurPos++];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* set buffer state flag */
|
/* set buffer state flag */
|
||||||
if ( iPutPos == iGetPos )
|
if ( iPutPos == iGetPos )
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_FULL;
|
eBufState = CNetBuf::BS_FULL;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_OK;
|
eBufState = CNetBuf::BS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
return bPutOK;
|
return bPutOK;
|
||||||
}
|
}
|
||||||
|
@ -153,24 +173,34 @@ bool CNetBuf::Get(CVector<double>& vecdData)
|
||||||
|
|
||||||
/* 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 )
|
while ( iGetPos < iMemSize )
|
||||||
|
{
|
||||||
vecdData[iCurPos++] = vecdMemory[iGetPos++];
|
vecdData[iCurPos++] = vecdMemory[iGetPos++];
|
||||||
|
}
|
||||||
|
|
||||||
for ( iGetPos = 0; iGetPos < iRemData; iGetPos++ )
|
for ( iGetPos = 0; iGetPos < iRemData; iGetPos++ )
|
||||||
|
{
|
||||||
vecdData[iCurPos++] = vecdMemory[iGetPos];
|
vecdData[iCurPos++] = vecdMemory[iGetPos];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* data can be read in one step */
|
/* data can be read in one step */
|
||||||
const int iEnd = iGetPos + iInSize;
|
const int iEnd = iGetPos + iInSize;
|
||||||
while ( iGetPos < iEnd )
|
while ( iGetPos < iEnd )
|
||||||
|
{
|
||||||
vecdData[iCurPos++] = vecdMemory[iGetPos++];
|
vecdData[iCurPos++] = vecdMemory[iGetPos++];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* set buffer state flag */
|
/* set buffer state flag */
|
||||||
if ( iPutPos == iGetPos )
|
if ( iPutPos == iGetPos )
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_EMPTY;
|
eBufState = CNetBuf::BS_EMPTY;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_OK;
|
eBufState = CNetBuf::BS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* extrapolate data from old block to avoid "clicks"
|
/* 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
|
anymore since it is already gone (processed or send through the
|
||||||
network) */
|
network) */
|
||||||
if ( bFadeOutExtrap )
|
if ( bFadeOutExtrap )
|
||||||
|
{
|
||||||
FadeOutExtrapolateAudioDataBlock ( vecdData, dExPDiff, dExPLastV );
|
FadeOutExtrapolateAudioDataBlock ( vecdData, dExPDiff, dExPLastV );
|
||||||
|
}
|
||||||
|
|
||||||
/* save some paramters from last block which is needed in case we do not
|
/* 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
|
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 */
|
/* check for special case and wrap around */
|
||||||
if ( iAvSpace < 0 )
|
if ( iAvSpace < 0 )
|
||||||
|
{
|
||||||
iAvSpace += iMemSize; /* wrap around */
|
iAvSpace += iMemSize; /* wrap around */
|
||||||
else if ((iAvSpace == 0) && (eBufState == BS_EMPTY))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( ( iAvSpace == 0 ) && ( eBufState == BS_EMPTY ) )
|
||||||
|
{
|
||||||
iAvSpace = iMemSize;
|
iAvSpace = iMemSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return iAvSpace;
|
return iAvSpace;
|
||||||
}
|
}
|
||||||
|
@ -211,9 +250,16 @@ int CNetBuf::GetAvailData() const
|
||||||
|
|
||||||
/* check for special case and wrap around */
|
/* check for special case and wrap around */
|
||||||
if ( iAvData < 0 )
|
if ( iAvData < 0 )
|
||||||
|
{
|
||||||
iAvData += iMemSize; /* wrap around */
|
iAvData += iMemSize; /* wrap around */
|
||||||
else if ((iAvData == 0) && (eBufState == BS_FULL))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( ( iAvData == 0 ) && ( eBufState == BS_FULL ) )
|
||||||
|
{
|
||||||
iAvData = iMemSize;
|
iAvData = iMemSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return iAvData;
|
return iAvData;
|
||||||
}
|
}
|
||||||
|
@ -252,10 +298,14 @@ void CNetBuf::Clear(const EClearType eClearType)
|
||||||
|
|
||||||
/* check for special case */
|
/* check for special case */
|
||||||
if ( iPutPos == iGetPos )
|
if ( iPutPos == iGetPos )
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_FULL;
|
eBufState = CNetBuf::BS_FULL;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
eBufState = CNetBuf::BS_OK;
|
eBufState = CNetBuf::BS_OK;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* in case of "put" correction, do not delete old data but only shift
|
/* 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 */
|
wrap around */
|
||||||
iPutPos += iGetPos;
|
iPutPos += iGetPos;
|
||||||
if ( iPutPos > iMemSize )
|
if ( iPutPos > iMemSize )
|
||||||
|
{
|
||||||
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 iCurPos = iPutPos - iNumSamFading;
|
||||||
|
|
12
src/buffer.h
12
src/buffer.h
|
@ -30,12 +30,12 @@
|
||||||
|
|
||||||
|
|
||||||
/* 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) ( SAMPLE_RATE * FADE_IN_OUT_TIME ) / 1000 )
|
#define FADE_IN_OUT_NUM_SAM ( (int) ( 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
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
@ -70,13 +70,13 @@ protected:
|
||||||
int iNumSamFading;
|
int iNumSamFading;
|
||||||
int iNumSamFadingExtra;
|
int iNumSamFadingExtra;
|
||||||
|
|
||||||
/* extrapolation parameters */
|
// extrapolation parameters
|
||||||
double dExPDiff;
|
double dExPDiff;
|
||||||
double dExPLastV;
|
double dExPLastV;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* conversion buffer (very simple buffer) */
|
// conversion buffer (very simple buffer)
|
||||||
class CConvBuf
|
class CConvBuf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
14
src/client.h
14
src/client.h
|
@ -128,7 +128,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
/* only one channel is needed for client application */
|
// only one channel is needed for client application
|
||||||
CChannel Channel;
|
CChannel Channel;
|
||||||
|
|
||||||
CSocket Socket;
|
CSocket Socket;
|
||||||
|
@ -158,13 +158,13 @@ protected:
|
||||||
|
|
||||||
CVector<short> vecsNetwork;
|
CVector<short> vecsNetwork;
|
||||||
|
|
||||||
/* resample objects */
|
// resample objects
|
||||||
CAudioResample ResampleObjDownL; /* left channel */
|
CAudioResample ResampleObjDownL; // left channel
|
||||||
CAudioResample ResampleObjDownR; /* right channel */
|
CAudioResample ResampleObjDownR; // right channel
|
||||||
CAudioResample ResampleObjUpL; /* left channel */
|
CAudioResample ResampleObjUpL; // left channel
|
||||||
CAudioResample ResampleObjUpR; /* right channel */
|
CAudioResample ResampleObjUpR; // right channel
|
||||||
|
|
||||||
/* debugging, evaluating */
|
// debugging, evaluating
|
||||||
CMovingAv<double> RespTimeMoAvBuf;
|
CMovingAv<double> RespTimeMoAvBuf;
|
||||||
QTime TimeLastBlock;
|
QTime TimeLastBlock;
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
/* update time for GUI controls */
|
// update time for GUI controls
|
||||||
#define DISPLAY_UPDATE_TIME 1000 /* ms */
|
#define DISPLAY_UPDATE_TIME 1000 // ms
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
|
36
src/global.h
36
src/global.h
|
@ -36,11 +36,11 @@
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
/* define this macro to get debug output */
|
// define this macro to get debug output
|
||||||
#define _DEBUG_
|
#define _DEBUG_
|
||||||
#undef _DEBUG_
|
#undef _DEBUG_
|
||||||
|
|
||||||
/* version and application name (always use this version) */
|
// version and application name (always use this version)
|
||||||
#undef VERSION
|
#undef VERSION
|
||||||
#define VERSION "1.0cvs"
|
#define VERSION "1.0cvs"
|
||||||
#define APP_NAME "llcon"
|
#define APP_NAME "llcon"
|
||||||
|
@ -68,14 +68,14 @@
|
||||||
// maximum value of factor for network block size
|
// maximum value of factor for network block size
|
||||||
#define MAX_NET_BLOCK_SIZE_FACTOR 8
|
#define MAX_NET_BLOCK_SIZE_FACTOR 8
|
||||||
|
|
||||||
/* default network block size factor */
|
// default network block size factor
|
||||||
#define DEF_NET_BLOCK_SIZE_FACTOR 3
|
#define DEF_NET_BLOCK_SIZE_FACTOR 3
|
||||||
|
|
||||||
/* maximum network buffer size (which can be chosen by slider) */
|
// maximum network buffer size (which can be chosen by slider)
|
||||||
#define MAX_NET_BUF_SIZE_NUM_BL 10 /* number of blocks */
|
#define MAX_NET_BUF_SIZE_NUM_BL 10 // number of blocks
|
||||||
|
|
||||||
/* default network buffer size */
|
// default network buffer size
|
||||||
#define DEF_NET_BUF_SIZE_NUM_BL 5 /* number of blocks */
|
#define DEF_NET_BUF_SIZE_NUM_BL 5 // number of blocks
|
||||||
|
|
||||||
// number of ticks of audio in/out buffer sliders
|
// number of ticks of audio in/out buffer sliders
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -88,25 +88,25 @@
|
||||||
// if you want to change this paramter, there has to be done code modifications
|
// 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
|
// on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places
|
||||||
// (just search for the tag in the entire code)
|
// (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 */
|
// sample rate offset estimation algorithm
|
||||||
/* time interval for sample rate offset estimation */
|
// time interval for sample rate offset estimation
|
||||||
#define TIME_INT_SAM_OFFS_EST 60 /* s */
|
#define TIME_INT_SAM_OFFS_EST 60 // s
|
||||||
|
|
||||||
/* time interval of taps for sample rate offset estimation (time stamps) */
|
// time interval of taps for sample rate offset estimation (time stamps)
|
||||||
#define INTVL_TAPS_SAM_OFF_SET 1 /* s */
|
#define INTVL_TAPS_SAM_OFF_SET 1 // s
|
||||||
|
|
||||||
#define NUM_BL_TIME_STAMPS ( ( INTVL_TAPS_SAM_OFF_SET * 1000 ) / MIN_BLOCK_DURATION_MS )
|
#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 )
|
#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 */
|
// length of the moving average buffer for response time measurement
|
||||||
#define TIME_MOV_AV_RESPONSE 30 /* seconds */
|
#define TIME_MOV_AV_RESPONSE 30 // seconds
|
||||||
#define LEN_MOV_AV_RESPONSE ( TIME_MOV_AV_RESPONSE * 1000 / MIN_BLOCK_DURATION_MS )
|
#define LEN_MOV_AV_RESPONSE ( TIME_MOV_AV_RESPONSE * 1000 / MIN_BLOCK_DURATION_MS )
|
||||||
|
|
||||||
|
|
||||||
#define _MAXSHORT 32767
|
#define _MAXSHORT 32767
|
||||||
#define _MAXBYTE 255 /* binary: 11111111 */
|
#define _MAXBYTE 255 // binary: 11111111
|
||||||
#define _MINSHORT ( -32768 )
|
#define _MINSHORT ( -32768 )
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
|
@ -126,7 +126,7 @@ typedef unsigned char uint8_t;
|
||||||
|
|
||||||
/* Definitions for window message system ------------------------------------ */
|
/* Definitions for window message system ------------------------------------ */
|
||||||
typedef unsigned int _MESSAGE_IDENT;
|
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_IN 1
|
||||||
#define MS_SOUND_OUT 2
|
#define MS_SOUND_OUT 2
|
||||||
#define MS_JIT_BUF_PUT 3
|
#define MS_JIT_BUF_PUT 3
|
||||||
|
@ -161,7 +161,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* Prototypes for global functions ********************************************/
|
/* Prototypes for global functions ********************************************/
|
||||||
/* Posting a window message */
|
// posting a window message
|
||||||
void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam = 0,
|
void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam = 0,
|
||||||
const int iChanNum = 0 );
|
const int iChanNum = 0 );
|
||||||
|
|
||||||
|
|
|
@ -46,20 +46,20 @@
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* 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_CONNECTTEXT "C&onnect"
|
||||||
#define CON_BUT_DISCONNECTTEXT "D&isconnect"
|
#define CON_BUT_DISCONNECTTEXT "D&isconnect"
|
||||||
|
|
||||||
/* steps for input level meter */
|
// steps for input level meter
|
||||||
#define NUM_STEPS_INP_LEV_METER 100
|
#define NUM_STEPS_INP_LEV_METER 100
|
||||||
|
|
||||||
/* update time for GUI controls */
|
// update time for GUI controls
|
||||||
#define LEVELMETER_UPDATE_TIME 100 /* ms */
|
#define LEVELMETER_UPDATE_TIME 100 // ms
|
||||||
#define STATUSBAR_UPDATE_TIME 1000 /* ms */
|
#define STATUSBAR_UPDATE_TIME 1000 // ms
|
||||||
|
|
||||||
/* range for signal level meter */
|
// range for signal level meter
|
||||||
#define LOW_BOUND_SIG_METER ( -50.0 ) /* dB */
|
#define LOW_BOUND_SIG_METER ( -50.0 ) // dB
|
||||||
#define UPPER_BOUND_SIG_METER ( 0.0 ) /* dB */
|
#define UPPER_BOUND_SIG_METER ( 0.0 ) // dB
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
|
|
@ -41,8 +41,8 @@
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
/* update time for GUI controls */
|
// update time for GUI controls
|
||||||
#define GUI_CONTRL_UPDATE_TIME 1000 /* ms */
|
#define GUI_CONTRL_UPDATE_TIME 1000 // ms
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
|
|
@ -166,10 +166,14 @@ void CMultiColorLEDbase::SetUpdateTime(int iNUTi)
|
||||||
{
|
{
|
||||||
/* Avoid too short intervals */
|
/* Avoid too short intervals */
|
||||||
if ( iNUTi < MIN_TIME_FOR_RED_LIGHT )
|
if ( iNUTi < MIN_TIME_FOR_RED_LIGHT )
|
||||||
|
{
|
||||||
iUpdateTime = MIN_TIME_FOR_RED_LIGHT;
|
iUpdateTime = MIN_TIME_FOR_RED_LIGHT;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
iUpdateTime = iNUTi;
|
iUpdateTime = iNUTi;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CMultiColorLED::CMultiColorLED ( QWidget* parent, const char* name, WFlags f ) :
|
CMultiColorLED::CMultiColorLED ( QWidget* parent, const char* name, WFlags f ) :
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
#define DEFAULT_UPDATE_TIME 300
|
#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
|
#define MIN_TIME_FOR_RED_LIGHT 100
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ protected:
|
||||||
enum ELightColor { RL_GREY, RL_RED, RL_GREEN, RL_YELLOW };
|
enum ELightColor { RL_GREY, RL_RED, RL_GREEN, RL_YELLOW };
|
||||||
ELightColor eColorFlag;
|
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();
|
void UpdateColor();
|
||||||
|
|
||||||
QPixmap BitmCubeGreen;
|
QPixmap BitmCubeGreen;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
|
#define PROTMESSID_CHANNEL_NAME 18 // set channel name for fader tag
|
||||||
|
|
||||||
// lengths of message as defined in protocol.cpp file
|
// 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) */ )
|
#define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ )
|
||||||
|
|
||||||
// time out for message re-send if no acknowledgement was received
|
// time out for message re-send if no acknowledgement was received
|
||||||
|
|
|
@ -71,11 +71,11 @@ protected:
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
CVector<short> vecsSendData;
|
CVector<short> vecsSendData;
|
||||||
|
|
||||||
/* actual working objects */
|
// actual working objects
|
||||||
CChannelSet ChannelSet;
|
CChannelSet ChannelSet;
|
||||||
CSocket Socket;
|
CSocket Socket;
|
||||||
|
|
||||||
/* debugging, evaluating */
|
// debugging, evaluating
|
||||||
CMovingAv<double> RespTimeMoAvBuf;
|
CMovingAv<double> RespTimeMoAvBuf;
|
||||||
QTime TimeLastBlock;
|
QTime TimeLastBlock;
|
||||||
|
|
||||||
|
|
|
@ -56,42 +56,50 @@ void CSettings::ReadIniFile()
|
||||||
pClient->strName = GetIniSetting ( ini, "Client", "name" );
|
pClient->strName = GetIniSetting ( ini, "Client", "name" );
|
||||||
|
|
||||||
// audio fader
|
// 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 );
|
pClient->SetAudioInFader ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverberation level
|
// 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 );
|
pClient->SetReverbLevel ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverberation channel assignment
|
// reverberation channel assignment
|
||||||
if ( GetFlagIniSet(ini, "Client", "reverblchan", bValue ) == TRUE ) {
|
if ( GetFlagIniSet ( ini, "Client", "reverblchan", bValue ) == TRUE )
|
||||||
|
{
|
||||||
pClient->SetReverbOnLeftChan ( bValue );
|
pClient->SetReverbOnLeftChan ( bValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// sound card in number of buffers
|
// 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 );
|
pClient->GetSndInterface()->SetInNumBuf( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// sound card out number of buffers
|
// 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 );
|
pClient->GetSndInterface()->SetOutNumBuf ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network jitter buffer size
|
// 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 );
|
pClient->SetSockBufSize ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network buffer size factor in
|
// 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 );
|
pClient->SetNetwBufSizeFactIn ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network buffer size factor out
|
// 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 );
|
pClient->SetNetwBufSizeFactOut ( iValue );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,8 +243,10 @@ string CSettings::GetIniSetting(CSettings::INIFile& theINI, const char* section,
|
||||||
INISection::iterator apair = iSection->second.find ( string ( key ) );
|
INISection::iterator apair = iSection->second.find ( string ( key ) );
|
||||||
|
|
||||||
if ( apair != iSection->second.end() )
|
if ( apair != iSection->second.end() )
|
||||||
|
{
|
||||||
result = apair->second;
|
result = apair->second;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -260,18 +270,23 @@ void CSettings::PutIniSetting(CSettings::INIFile &theINI, const char *section,
|
||||||
theINI.insert (
|
theINI.insert (
|
||||||
std::pair<string, INISection> ( string ( section ), newsection ) );
|
std::pair<string, INISection> ( string ( section ), newsection ) );
|
||||||
}
|
}
|
||||||
else if (key)
|
else
|
||||||
|
{
|
||||||
|
if ( key )
|
||||||
{
|
{
|
||||||
/* Found section, make sure key isn't in there already,
|
/* Found section, make sure key isn't in there already,
|
||||||
if it is, just drop and re-add */
|
if it is, just drop and re-add */
|
||||||
apair = iniSection->second.find ( string ( key ) );
|
apair = iniSection->second.find ( string ( key ) );
|
||||||
if ( apair != iniSection->second.end() )
|
if ( apair != iniSection->second.end() )
|
||||||
|
{
|
||||||
iniSection->second.erase(apair);
|
iniSection->second.erase(apair);
|
||||||
|
}
|
||||||
|
|
||||||
iniSection->second.insert (
|
iniSection->second.insert (
|
||||||
std::pair<string, string> ( string ( key ), string ( value ) ) );
|
std::pair<string, string> ( string ( key ), string ( value ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSettings::INIFile CSettings::LoadIni ( const char* filename )
|
CSettings::INIFile CSettings::LoadIni ( const char* filename )
|
||||||
{
|
{
|
||||||
|
@ -287,10 +302,14 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
|
||||||
file.getline ( buffer, sizeof ( buffer ) );
|
file.getline ( buffer, sizeof ( buffer ) );
|
||||||
|
|
||||||
if ( ( temp = strchr ( buffer, '\n' ) ) )
|
if ( ( temp = strchr ( buffer, '\n' ) ) )
|
||||||
|
{
|
||||||
*temp = '\0'; /* Cut off at newline */
|
*temp = '\0'; /* Cut off at newline */
|
||||||
|
}
|
||||||
|
|
||||||
if ( ( temp = strchr ( buffer, '\r' ) ) )
|
if ( ( temp = strchr ( buffer, '\r' ) ) )
|
||||||
|
{
|
||||||
*temp = '\0'; /* Cut off at linefeeds */
|
*temp = '\0'; /* Cut off at linefeeds */
|
||||||
|
}
|
||||||
|
|
||||||
if ( ( buffer[0] == '[' ) && ( temp = strrchr ( buffer, ']' ) ) )
|
if ( ( buffer[0] == '[' ) && ( temp = strrchr ( buffer, ']' ) ) )
|
||||||
{ /* if line is like --> [section name] */
|
{ /* if line is like --> [section name] */
|
||||||
|
@ -298,7 +317,9 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
|
||||||
section = &buffer[1];
|
section = &buffer[1];
|
||||||
PutIniSetting ( theINI, &buffer[1] ); /* Start new section */
|
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 "=" */
|
/* Assign whatever follows = sign to value, chop at "=" */
|
||||||
*value++ = '\0';
|
*value++ = '\0';
|
||||||
|
@ -306,12 +327,17 @@ CSettings::INIFile CSettings::LoadIni(const char* filename)
|
||||||
/* And add both sides to INISection */
|
/* And add both sides to INISection */
|
||||||
PutIniSetting ( theINI, section.c_str(), buffer, value );
|
PutIniSetting ( theINI, section.c_str(), buffer, value );
|
||||||
}
|
}
|
||||||
else if (buffer[0])
|
else
|
||||||
|
{
|
||||||
|
if ( buffer[0] )
|
||||||
{
|
{
|
||||||
/* Must be a comment or something */
|
/* Must be a comment or something */
|
||||||
PutIniSetting ( theINI, section.c_str(), buffer, "" );
|
PutIniSetting ( theINI, section.c_str(), buffer, "" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return theINI;
|
return theINI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +347,9 @@ void CSettings::SaveIni(CSettings::INIFile &theINI, const char* filename)
|
||||||
|
|
||||||
std::fstream file ( filename, std::ios::out );
|
std::fstream file ( filename, std::ios::out );
|
||||||
if ( !file.good() )
|
if ( !file.good() )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Just iterate the hashes and values and dump them to a file */
|
/* Just iterate the hashes and values and dump them to a file */
|
||||||
INIFile::iterator section = theINI.begin();
|
INIFile::iterator section = theINI.begin();
|
||||||
|
@ -338,17 +366,23 @@ void CSettings::SaveIni(CSettings::INIFile &theINI, const char* filename)
|
||||||
bFirstSection = FALSE;
|
bFirstSection = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
file << std::endl << "[" << section->first << "]" << std::endl;
|
file << std::endl << "[" << section->first << "]" << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
INISection::iterator pair = section->second.begin();
|
INISection::iterator pair = section->second.begin();
|
||||||
|
|
||||||
while ( pair != section->second.end() )
|
while ( pair != section->second.end() )
|
||||||
{
|
{
|
||||||
if ( pair->second > "" )
|
if ( pair->second > "" )
|
||||||
|
{
|
||||||
file << pair->first << "=" << pair->second << std::endl;
|
file << pair->first << "=" << pair->second << std::endl;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
file << pair->first << "=" << std::endl;
|
file << pair->first << "=" << std::endl;
|
||||||
|
}
|
||||||
pair++;
|
pair++;
|
||||||
}
|
}
|
||||||
section++;
|
section++;
|
||||||
|
@ -376,7 +410,9 @@ bool CSettings::StlIniCompareStringNoCase::operator()(const string& x,
|
||||||
{
|
{
|
||||||
nResult = toupper ( *p1 ) - toupper ( *p2 );
|
nResult = toupper ( *p1 ) - toupper ( *p2 );
|
||||||
if ( nResult != 0 )
|
if ( nResult != 0 )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
p1++;
|
p1++;
|
||||||
p2++;
|
p2++;
|
||||||
nCount++;
|
nCount++;
|
||||||
|
@ -384,12 +420,18 @@ bool CSettings::StlIniCompareStringNoCase::operator()(const string& x,
|
||||||
if ( nResult == 0 )
|
if ( nResult == 0 )
|
||||||
{
|
{
|
||||||
if ( *p1 && !*p2 )
|
if ( *p1 && !*p2 )
|
||||||
|
{
|
||||||
nResult = -1;
|
nResult = -1;
|
||||||
|
}
|
||||||
if ( !*p1 && *p2 )
|
if ( !*p1 && *p2 )
|
||||||
|
{
|
||||||
nResult = 1;
|
nResult = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( nResult < 0 )
|
if ( nResult < 0 )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
#endif /* strcasecmp */
|
#endif /* strcasecmp */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,13 +54,13 @@ protected:
|
||||||
void ReadIniFile();
|
void ReadIniFile();
|
||||||
void WriteIniFile();
|
void WriteIniFile();
|
||||||
|
|
||||||
/* Function declarations for stlini code written by Robert Kesterson */
|
// function declarations for stlini code written by Robert Kesterson
|
||||||
struct StlIniCompareStringNoCase
|
struct StlIniCompareStringNoCase
|
||||||
{
|
{
|
||||||
bool operator() ( const std::string& x, const std::string& y ) const;
|
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, string, StlIniCompareStringNoCase > INISection;
|
||||||
typedef std::map<string, INISection , StlIniCompareStringNoCase > INIFile;
|
typedef std::map<string, INISection , StlIniCompareStringNoCase > INIFile;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ protected:
|
||||||
bool GetFlagIniSet ( INIFile& theINI, string strSection, string strKey,
|
bool GetFlagIniSet ( INIFile& theINI, string strSection, string strKey,
|
||||||
bool& bValue );
|
bool& bValue );
|
||||||
|
|
||||||
/* Pointer to the client object needed for the various settings */
|
// pointer to the client object needed for the various settings
|
||||||
CClient* pClient;
|
CClient* pClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* 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 )
|
#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;
|
CVector<unsigned char> vecbyRecBuf;
|
||||||
CHostAddress RecHostAddr;
|
CHostAddress RecHostAddr;
|
||||||
|
|
||||||
CChannel* pChannel; /* for client */
|
CChannel* pChannel; // for client
|
||||||
CChannelSet* pChannelSet; /* for server */
|
CChannelSet* pChannelSet; // for server
|
||||||
|
|
||||||
QObject* pServer;
|
QObject* pServer;
|
||||||
bool bIsClient;
|
bool bIsClient;
|
||||||
|
|
38
src/util.cpp
38
src/util.cpp
|
@ -29,16 +29,16 @@
|
||||||
/* Input level meter implementation ------------------------------------------ */
|
/* Input level meter implementation ------------------------------------------ */
|
||||||
void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
|
void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
|
||||||
{
|
{
|
||||||
/* Do the update for entire vector */
|
// do the update for entire vector
|
||||||
const int iVecSize = vecdAudio.Size();
|
const int iVecSize = vecdAudio.Size();
|
||||||
|
|
||||||
for ( int i = 0; i < iVecSize; i++ )
|
for ( int i = 0; i < iVecSize; i++ )
|
||||||
{
|
{
|
||||||
/* norm of current audio sample */
|
// norm of current audio sample
|
||||||
const double dCurSig = fabs ( vecdAudio[i] );
|
const double dCurSig = fabs ( vecdAudio[i] );
|
||||||
|
|
||||||
/* search for maximum. Decrease this max with time */
|
// search for maximum. Decrease this max with time
|
||||||
/* decrease max with time */
|
// decrease max with time
|
||||||
if ( dCurLevel >= METER_FLY_BACK )
|
if ( dCurLevel >= METER_FLY_BACK )
|
||||||
{
|
{
|
||||||
dCurLevel *= 0.9999;
|
dCurLevel *= 0.9999;
|
||||||
|
@ -48,7 +48,7 @@ void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
|
||||||
dCurLevel = 0;
|
dCurLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* search for max */
|
// search for max
|
||||||
if ( dCurSig > dCurLevel )
|
if ( dCurSig > dCurLevel )
|
||||||
{
|
{
|
||||||
dCurLevel = dCurSig;
|
dCurLevel = dCurSig;
|
||||||
|
@ -60,14 +60,14 @@ double CSignalLevelMeter::MicLevel ()
|
||||||
{
|
{
|
||||||
const double dNormMicLevel = dCurLevel / _MAXSHORT;
|
const double dNormMicLevel = dCurLevel / _MAXSHORT;
|
||||||
|
|
||||||
/* logarithmic measure */
|
// logarithmic measure
|
||||||
if ( dNormMicLevel > 0 )
|
if ( dNormMicLevel > 0 )
|
||||||
{
|
{
|
||||||
return 20.0 * log10 ( dNormMicLevel );
|
return 20.0 * log10 ( dNormMicLevel );
|
||||||
}
|
}
|
||||||
else
|
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++ )
|
for ( int i = 0; i < 8; i++ )
|
||||||
{
|
{
|
||||||
/* Shift bits in shift-register for transistion */
|
// shift bits in shift-register for transistion
|
||||||
iStateShiftReg <<= 1;
|
iStateShiftReg <<= 1;
|
||||||
|
|
||||||
/* Take bit, which was shifted out of the register-size and place it
|
/* 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;
|
iStateShiftReg |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add new data bit to the LSB */
|
// add new data bit to the LSB
|
||||||
if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 )
|
if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 )
|
||||||
{
|
{
|
||||||
iStateShiftReg ^= 1;
|
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 )
|
if ( iStateShiftReg & 1 )
|
||||||
{
|
{
|
||||||
iStateShiftReg ^= iPoly;
|
iStateShiftReg ^= iPoly;
|
||||||
|
@ -111,10 +111,10 @@ void CCRC::AddByte ( const uint8_t byNewInput )
|
||||||
|
|
||||||
uint32_t CCRC::GetCRC()
|
uint32_t CCRC::GetCRC()
|
||||||
{
|
{
|
||||||
/* Return inverted shift-register (1's complement) */
|
// return inverted shift-register (1's complement)
|
||||||
iStateShiftReg = ~iStateShiftReg;
|
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 );
|
return iStateShiftReg & ( iBitOutMask - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ CAudioReverb::CAudioReverb ( const double rT60 )
|
||||||
{
|
{
|
||||||
int delay, i;
|
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 };
|
int lengths[9] = { 1777, 1847, 1993, 2137, 389, 127, 43, 211, 179 };
|
||||||
const double scaler = (double) SAMPLE_RATE / 44100.0;
|
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 )
|
CAboutDlg::CAboutDlg ( QWidget* parent, const char* name, bool modal, WFlags f )
|
||||||
: CAboutDlgBase ( parent, name, modal, 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 (
|
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 "
|
"<big><b>llcon</b> " + tr("Client/Server communication tool to enable "
|
||||||
"musician to play together through a conventional broadband internet "
|
"musician to play together through a conventional broadband internet "
|
||||||
"connection (like DSL).") + "</big>"
|
"connection (like DSL).") + "</big>"
|
||||||
"</p><br>"
|
"</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 "
|
"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 "
|
"it under the terms of the GNU General Public License as published by "
|
||||||
"the Free Software Foundation; either version 2 of the License, or "
|
"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 "
|
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 "
|
||||||
"USA"
|
"USA"
|
||||||
"</font></p><br>"
|
"</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>" + tr("llcon uses the following libraries or code snippets:") +
|
||||||
"</b></p>"
|
"</b></p>"
|
||||||
"<ul>"
|
"<ul>"
|
||||||
|
@ -305,7 +305,7 @@ CAboutDlg::CAboutDlg(QWidget* parent, const char* name, bool modal, WFlags f)
|
||||||
"</ul>"
|
"</ul>"
|
||||||
"</center><br>");
|
"</center><br>");
|
||||||
|
|
||||||
/* Set version number in about dialog */
|
// set version number in about dialog
|
||||||
TextLabelVersion->setText ( GetVersionAndNameStr() );
|
TextLabelVersion->setText ( GetVersionAndNameStr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ QString CAboutDlg::GetVersionAndNameStr ( const bool bWithHtml )
|
||||||
/* Help menu ---------------------------------------------------------------- */
|
/* Help menu ---------------------------------------------------------------- */
|
||||||
CLlconHelpMenu::CLlconHelpMenu ( QWidget* parent ) : QPopupMenu ( parent )
|
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,
|
insertItem ( tr ( "What's &This" ), this,
|
||||||
SLOT ( OnHelpWhatsThis () ), SHIFT+Key_F1 );
|
SLOT ( OnHelpWhatsThis () ), SHIFT+Key_F1 );
|
||||||
insertSeparator();
|
insertSeparator();
|
||||||
|
|
56
src/util.h
56
src/util.h
|
@ -33,7 +33,7 @@
|
||||||
#include <qdatetime.h>
|
#include <qdatetime.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
using namespace std; /* Because of the library: "vector" */
|
using namespace std; // because of the library: "vector"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include "../windows/moc/aboutdlgbase.h"
|
# include "../windows/moc/aboutdlgbase.h"
|
||||||
#else
|
#else
|
||||||
|
@ -46,21 +46,25 @@ using namespace std; /* Because of the library: "vector" */
|
||||||
|
|
||||||
|
|
||||||
/* Global functions ***********************************************************/
|
/* Global functions ***********************************************************/
|
||||||
/* Converting double to short */
|
// converting double to short
|
||||||
inline short Double2Short ( const double dInput )
|
inline short Double2Short ( const double dInput )
|
||||||
{
|
{
|
||||||
/* Lower bound */
|
// lower bound
|
||||||
if ( dInput < _MINSHORT )
|
if ( dInput < _MINSHORT )
|
||||||
|
{
|
||||||
return _MINSHORT;
|
return _MINSHORT;
|
||||||
|
}
|
||||||
|
|
||||||
/* Upper bound */
|
// upper bound
|
||||||
if ( dInput > _MAXSHORT )
|
if ( dInput > _MAXSHORT )
|
||||||
|
{
|
||||||
return _MAXSHORT;
|
return _MAXSHORT;
|
||||||
|
}
|
||||||
|
|
||||||
return (short) dInput;
|
return (short) dInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Debug error handling */
|
// debug error handling
|
||||||
void DebugError ( const char* pchErDescr, const char* pchPar1Descr,
|
void DebugError ( const char* pchErDescr, const char* pchPar1Descr,
|
||||||
const double dPar1, const char* pchPar2Descr,
|
const double dPar1, const char* pchPar2Descr,
|
||||||
const double dPar2 );
|
const double dPar2 );
|
||||||
|
@ -87,7 +91,7 @@ public:
|
||||||
|
|
||||||
void Init ( const int iNewSize );
|
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 Init ( const int iNewSize, const TData tIniVal );
|
||||||
void Reset ( const TData tResetVal );
|
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,
|
template<class TData> void CVector<TData>::Init ( const int iNewSize,
|
||||||
const TData tIniVal )
|
const TData tIniVal )
|
||||||
{
|
{
|
||||||
/* Call actual init routine */
|
// call actual init routine
|
||||||
Init ( iNewSize );
|
Init ( iNewSize );
|
||||||
|
|
||||||
/* Set values */
|
// set values
|
||||||
Reset ( tIniVal );
|
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 )
|
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++ )
|
for ( int i = 0; i < iVectorSize; i++ )
|
||||||
|
{
|
||||||
pData[i] = tResetVal;
|
pData[i] = tResetVal;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
|
@ -222,11 +228,13 @@ template<class TData> void CFIFO<TData>::Add(const TData tNewD)
|
||||||
{
|
{
|
||||||
this->pData[iCurIdx] = tNewD;
|
this->pData[iCurIdx] = tNewD;
|
||||||
|
|
||||||
/* Increment index */
|
// increment index
|
||||||
iCurIdx++;
|
iCurIdx++;
|
||||||
if ( iCurIdx >= this->iVectorSize )
|
if ( iCurIdx >= this->iVectorSize )
|
||||||
|
{
|
||||||
iCurIdx = 0;
|
iCurIdx = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
|
@ -246,8 +254,14 @@ public:
|
||||||
void Add ( const TData tNewD );
|
void Add ( const TData tNewD );
|
||||||
inline TData GetAverage()
|
inline TData GetAverage()
|
||||||
{
|
{
|
||||||
if (this->iNorm == 0) return TData(0);
|
if ( this->iNorm == 0 )
|
||||||
else return tCurAvResult / this->iNorm;
|
{
|
||||||
|
return TData ( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return tCurAvResult / this->iNorm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Init ( const int iNewSize );
|
virtual void Init ( const int iNewSize );
|
||||||
|
@ -263,7 +277,7 @@ template<class TData> void CMovingAv<TData>::Init(const int iNewSize)
|
||||||
{
|
{
|
||||||
iNorm = 0;
|
iNorm = 0;
|
||||||
iCurIdx = 0;
|
iCurIdx = 0;
|
||||||
tCurAvResult = TData(0); /* Only for scalars! */
|
tCurAvResult = TData ( 0 ); // only for scalars!
|
||||||
CVector<TData>::Init ( iNewSize );
|
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
|
subtract the old value from the result. We only need one addition and a
|
||||||
history buffer
|
history buffer
|
||||||
*/
|
*/
|
||||||
/* Subtract oldest value */
|
// subtract oldest value
|
||||||
tCurAvResult -= this->pData[iCurIdx];
|
tCurAvResult -= this->pData[iCurIdx];
|
||||||
|
|
||||||
/* Add new value and write in memory */
|
// add new value and write in memory
|
||||||
tCurAvResult += tNewD;
|
tCurAvResult += tNewD;
|
||||||
this->pData[iCurIdx] = tNewD;
|
this->pData[iCurIdx] = tNewD;
|
||||||
|
|
||||||
/* Increase position pointer and test if wrap */
|
// increase position pointer and test if wrap
|
||||||
iCurIdx++;
|
iCurIdx++;
|
||||||
if ( iCurIdx >= this->iVectorSize )
|
if ( iCurIdx >= this->iVectorSize )
|
||||||
|
{
|
||||||
iCurIdx = 0;
|
iCurIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* take care of norm */
|
// take care of norm
|
||||||
if ( this->iNorm < this->iVectorSize )
|
if ( this->iNorm < this->iVectorSize )
|
||||||
|
{
|
||||||
this->iNorm++;
|
this->iNorm++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
|
@ -350,10 +368,10 @@ public:
|
||||||
CHostAddress ( const CHostAddress& NHAddr ) :
|
CHostAddress ( const CHostAddress& NHAddr ) :
|
||||||
InetAddr ( NHAddr.InetAddr ), iPort ( NHAddr.iPort ) {}
|
InetAddr ( NHAddr.InetAddr ), iPort ( NHAddr.iPort ) {}
|
||||||
|
|
||||||
/* copy and compare operators */
|
// copy and compare operators
|
||||||
CHostAddress& operator= ( const CHostAddress& NHAddr )
|
CHostAddress& operator= ( const CHostAddress& NHAddr )
|
||||||
{ InetAddr = NHAddr.InetAddr; iPort = NHAddr.iPort; return *this; }
|
{ 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 ) ); }
|
{ return ( ( CompAddr.InetAddr == InetAddr ) && ( CompAddr.iPort == iPort ) ); }
|
||||||
|
|
||||||
QHostAddress InetAddr;
|
QHostAddress InetAddr;
|
||||||
|
|
|
@ -37,50 +37,62 @@ bool CSound::Read(CVector<short>& psData)
|
||||||
int i;
|
int i;
|
||||||
bool bError;
|
bool bError;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
// check if device must be opened or reinitialized
|
||||||
if ( bChangParamIn == TRUE )
|
if ( bChangParamIn == TRUE )
|
||||||
{
|
{
|
||||||
OpenInDevice();
|
OpenInDevice();
|
||||||
|
|
||||||
/* Reinit sound interface */
|
// Reinit sound interface
|
||||||
InitRecording ( iBufferSizeIn, bBlockingRec );
|
InitRecording ( iBufferSizeIn, bBlockingRec );
|
||||||
|
|
||||||
/* Reset flag */
|
// Reset flag
|
||||||
bChangParamIn = FALSE;
|
bChangParamIn = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait until data is available */
|
// wait until data is available
|
||||||
if ( ! ( m_WaveInHeader[iWhichBufferIn].dwFlags & WHDR_DONE ) )
|
if ( ! ( m_WaveInHeader[iWhichBufferIn].dwFlags & WHDR_DONE ) )
|
||||||
{
|
{
|
||||||
if ( bBlockingRec == TRUE )
|
if ( bBlockingRec == TRUE )
|
||||||
|
{
|
||||||
WaitForSingleObject ( m_WaveInEvent, INFINITE );
|
WaitForSingleObject ( m_WaveInEvent, INFINITE );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if buffers got lost */
|
// check if buffers got lost
|
||||||
int iNumInBufDone = 0;
|
int iNumInBufDone = 0;
|
||||||
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
||||||
{
|
{
|
||||||
if ( m_WaveInHeader[i].dwFlags & WHDR_DONE )
|
if ( m_WaveInHeader[i].dwFlags & WHDR_DONE )
|
||||||
|
{
|
||||||
iNumInBufDone++;
|
iNumInBufDone++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If the number of done buffers equals the total number of buffers, it is
|
/* If the number of done buffers equals the total number of buffers, it is
|
||||||
very likely that a buffer got lost -> set error flag */
|
very likely that a buffer got lost -> set error flag */
|
||||||
if ( iNumInBufDone == iCurNumSndBufIn )
|
if ( iNumInBufDone == iCurNumSndBufIn )
|
||||||
|
{
|
||||||
bError = TRUE;
|
bError = TRUE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
bError = FALSE;
|
bError = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy data from sound card in output buffer */
|
// copy data from sound card in output buffer
|
||||||
for ( i = 0; i < iBufferSizeIn; i++ )
|
for ( i = 0; i < iBufferSizeIn; i++ )
|
||||||
|
{
|
||||||
psData[i] = psSoundcardBuffer[iWhichBufferIn][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();
|
AddInBuffer();
|
||||||
|
|
||||||
/* In case more than one buffer was ready, reset event */
|
// in case more than one buffer was ready, reset event
|
||||||
ResetEvent ( m_WaveInEvent );
|
ResetEvent ( m_WaveInEvent );
|
||||||
|
|
||||||
return bError;
|
return bError;
|
||||||
|
@ -88,57 +100,59 @@ bool CSound::Read(CVector<short>& psData)
|
||||||
|
|
||||||
void CSound::AddInBuffer()
|
void CSound::AddInBuffer()
|
||||||
{
|
{
|
||||||
/* Unprepare old wave-header */
|
// unprepare old wave-header
|
||||||
waveInUnprepareHeader (
|
waveInUnprepareHeader (
|
||||||
m_WaveIn, &m_WaveInHeader[iWhichBufferIn], sizeof ( WAVEHDR ) );
|
m_WaveIn, &m_WaveInHeader[iWhichBufferIn], sizeof ( WAVEHDR ) );
|
||||||
|
|
||||||
/* Prepare buffers for sending to sound interface */
|
// prepare buffers for sending to sound interface
|
||||||
PrepareInBuffer ( iWhichBufferIn );
|
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 ) );
|
waveInAddBuffer ( m_WaveIn, &m_WaveInHeader[iWhichBufferIn], sizeof ( WAVEHDR ) );
|
||||||
|
|
||||||
/* Toggle buffers */
|
// toggle buffers
|
||||||
iWhichBufferIn++;
|
iWhichBufferIn++;
|
||||||
if ( iWhichBufferIn == iCurNumSndBufIn )
|
if ( iWhichBufferIn == iCurNumSndBufIn )
|
||||||
|
{
|
||||||
iWhichBufferIn = 0;
|
iWhichBufferIn = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSound::PrepareInBuffer ( int iBufNum )
|
void CSound::PrepareInBuffer ( int iBufNum )
|
||||||
{
|
{
|
||||||
/* Set struct entries */
|
// set struct entries
|
||||||
m_WaveInHeader[iBufNum].lpData = (LPSTR) &psSoundcardBuffer[iBufNum][0];
|
m_WaveInHeader[iBufNum].lpData = (LPSTR) &psSoundcardBuffer[iBufNum][0];
|
||||||
m_WaveInHeader[iBufNum].dwBufferLength = iBufferSizeIn * BYTES_PER_SAMPLE;
|
m_WaveInHeader[iBufNum].dwBufferLength = iBufferSizeIn * BYTES_PER_SAMPLE;
|
||||||
m_WaveInHeader[iBufNum].dwFlags = 0;
|
m_WaveInHeader[iBufNum].dwFlags = 0;
|
||||||
|
|
||||||
/* Prepare wave-header */
|
// prepare wave-header
|
||||||
waveInPrepareHeader ( m_WaveIn, &m_WaveInHeader[iBufNum], sizeof ( WAVEHDR ) );
|
waveInPrepareHeader ( m_WaveIn, &m_WaveInHeader[iBufNum], sizeof ( WAVEHDR ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::InitRecording ( int iNewBufferSize, bool bNewBlocking )
|
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 )
|
if ( bChangParamIn == TRUE )
|
||||||
{
|
{
|
||||||
OpenInDevice();
|
OpenInDevice();
|
||||||
|
|
||||||
/* Reset flag */
|
// reset flag
|
||||||
bChangParamIn = FALSE;
|
bChangParamIn = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set internal parameter */
|
// set internal parameter
|
||||||
iBufferSizeIn = iNewBufferSize;
|
iBufferSizeIn = iNewBufferSize;
|
||||||
bBlockingRec = bNewBlocking;
|
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 );
|
waveInReset ( m_WaveIn );
|
||||||
waveInStop ( 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()" */
|
"AddInBuffer()" */
|
||||||
iWhichBufferIn = 0;
|
iWhichBufferIn = 0;
|
||||||
|
|
||||||
/* Create memory for sound card buffer */
|
// create memory for sound card buffer
|
||||||
for ( int i = 0; i < iCurNumSndBufIn; i++ )
|
for ( int i = 0; i < iCurNumSndBufIn; i++ )
|
||||||
{
|
{
|
||||||
/* Unprepare old wave-header in case that we "re-initialized" this
|
/* 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 ) );
|
waveInUnprepareHeader ( m_WaveIn, &m_WaveInHeader[i], sizeof ( WAVEHDR ) );
|
||||||
|
|
||||||
if ( psSoundcardBuffer[i] != NULL )
|
if ( psSoundcardBuffer[i] != NULL )
|
||||||
|
{
|
||||||
delete[] psSoundcardBuffer[i];
|
delete[] psSoundcardBuffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
psSoundcardBuffer[i] = new short[iBufferSizeIn];
|
psSoundcardBuffer[i] = new short[iBufferSizeIn];
|
||||||
|
|
||||||
|
|
||||||
/* Send all buffers to driver for filling the queue ----------------- */
|
/* 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 );
|
PrepareInBuffer ( i );
|
||||||
|
|
||||||
AddInBuffer();
|
AddInBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify that sound capturing can start now */
|
// notify that sound capturing can start now
|
||||||
waveInStart ( m_WaveIn );
|
waveInStart ( m_WaveIn );
|
||||||
|
|
||||||
/* This reset event is very important for initialization, otherwise we will
|
/* 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()
|
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 )
|
if ( m_WaveIn != NULL )
|
||||||
{
|
{
|
||||||
waveInReset ( m_WaveIn );
|
waveInReset ( m_WaveIn );
|
||||||
|
@ -189,11 +205,13 @@ void CSound::OpenInDevice()
|
||||||
|
|
||||||
void CSound::SetInDev ( int iNewDev )
|
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 ) )
|
if ( ( iNewDev >= iNumDevs ) || ( iNewDev < 0 ) )
|
||||||
|
{
|
||||||
iNewDev = WAVE_MAPPER;
|
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 )
|
if ( iNewDev != iCurInDev )
|
||||||
{
|
{
|
||||||
iCurInDev = iNewDev;
|
iCurInDev = iNewDev;
|
||||||
|
@ -203,11 +221,13 @@ void CSound::SetInDev(int iNewDev)
|
||||||
|
|
||||||
void CSound::SetInNumBuf ( int iNewNum )
|
void CSound::SetInNumBuf ( int iNewNum )
|
||||||
{
|
{
|
||||||
/* check new parameter */
|
// check new parameter
|
||||||
if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) )
|
if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) )
|
||||||
|
{
|
||||||
iNewNum = NUM_SOUND_BUFFERS_IN;
|
iNewNum = NUM_SOUND_BUFFERS_IN;
|
||||||
|
}
|
||||||
|
|
||||||
/* Change only if parameter is different */
|
// change only if parameter is different
|
||||||
if ( iNewNum != iCurNumSndBufIn )
|
if ( iNewNum != iCurNumSndBufIn )
|
||||||
{
|
{
|
||||||
iCurNumSndBufIn = iNewNum;
|
iCurNumSndBufIn = iNewNum;
|
||||||
|
@ -226,22 +246,22 @@ bool CSound::Write(CVector<short>& psData)
|
||||||
int iIndexDoneBuf;
|
int iIndexDoneBuf;
|
||||||
bool bError;
|
bool bError;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
// check if device must be opened or reinitialized
|
||||||
if ( bChangParamOut == TRUE )
|
if ( bChangParamOut == TRUE )
|
||||||
{
|
{
|
||||||
OpenOutDevice();
|
OpenOutDevice();
|
||||||
|
|
||||||
/* Reinit sound interface */
|
// reinit sound interface
|
||||||
InitPlayback ( iBufferSizeOut, bBlockingPlay );
|
InitPlayback ( iBufferSizeOut, bBlockingPlay );
|
||||||
|
|
||||||
/* Reset flag */
|
// reset flag
|
||||||
bChangParamOut = FALSE;
|
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 );
|
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 ( iCntPrepBuf == 0 )
|
||||||
{
|
{
|
||||||
if ( bBlockingPlay == TRUE )
|
if ( bBlockingPlay == TRUE )
|
||||||
|
@ -261,38 +281,47 @@ bool CSound::Write(CVector<short>& psData)
|
||||||
/* All buffers are filled, dump new block ----------------------- */
|
/* All buffers are filled, dump new block ----------------------- */
|
||||||
// It would be better to kill half of the buffer blocks to set the start
|
// It would be better to kill half of the buffer blocks to set the start
|
||||||
// back to the middle: TODO
|
// 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-
|
Buffer is empty -> send as many cleared blocks to the sound-
|
||||||
interface until half of the buffer size is reached */
|
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++ )
|
for ( j = 0; j < iCurNumSndBufOut / 2; j++ )
|
||||||
{
|
{
|
||||||
/* First, clear these buffers */
|
// first, clear these buffers
|
||||||
for ( i = 0; i < iBufferSizeOut; i++ )
|
for ( i = 0; i < iBufferSizeOut; i++ )
|
||||||
|
{
|
||||||
psPlaybackBuffer[j][i] = 0;
|
psPlaybackBuffer[j][i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Then send them to the interface */
|
// then send them to the interface
|
||||||
AddOutBuffer ( j );
|
AddOutBuffer ( j );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set index for done buffer */
|
// set index for done buffer
|
||||||
iIndexDoneBuf = iCurNumSndBufOut / 2;
|
iIndexDoneBuf = iCurNumSndBufOut / 2;
|
||||||
|
|
||||||
bError = TRUE;
|
bError = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
bError = FALSE;
|
bError = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy stereo data from input in soundcard buffer */
|
// copy stereo data from input in soundcard buffer
|
||||||
for ( i = 0; i < iBufferSizeOut; i++ )
|
for ( i = 0; i < iBufferSizeOut; i++ )
|
||||||
|
{
|
||||||
psPlaybackBuffer[iIndexDoneBuf][i] = psData[i];
|
psPlaybackBuffer[iIndexDoneBuf][i] = psData[i];
|
||||||
|
}
|
||||||
|
|
||||||
/* Now, send the current block */
|
// now, send the current block
|
||||||
AddOutBuffer ( iIndexDoneBuf );
|
AddOutBuffer ( iIndexDoneBuf );
|
||||||
|
|
||||||
return bError;
|
return bError;
|
||||||
|
@ -300,7 +329,7 @@ bool CSound::Write(CVector<short>& psData)
|
||||||
|
|
||||||
void CSound::GetDoneBuffer ( int& iCntPrepBuf, int& iIndexDoneBuf )
|
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;
|
iCntPrepBuf = 0;
|
||||||
for ( int i = 0; i < iCurNumSndBufOut; i++ )
|
for ( int i = 0; i < iCurNumSndBufOut; i++ )
|
||||||
{
|
{
|
||||||
|
@ -314,25 +343,25 @@ void CSound::GetDoneBuffer(int& iCntPrepBuf, int& iIndexDoneBuf)
|
||||||
|
|
||||||
void CSound::AddOutBuffer ( int iBufNum )
|
void CSound::AddOutBuffer ( int iBufNum )
|
||||||
{
|
{
|
||||||
/* Unprepare old wave-header */
|
// Unprepare old wave-header
|
||||||
waveOutUnprepareHeader (
|
waveOutUnprepareHeader (
|
||||||
m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
|
m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
|
||||||
|
|
||||||
/* Prepare buffers for sending to sound interface */
|
// Prepare buffers for sending to sound interface
|
||||||
PrepareOutBuffer ( iBufNum );
|
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 ) );
|
waveOutWrite ( m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::PrepareOutBuffer ( int iBufNum )
|
void CSound::PrepareOutBuffer ( int iBufNum )
|
||||||
{
|
{
|
||||||
/* Set Header data */
|
// Set Header data
|
||||||
m_WaveOutHeader[iBufNum].lpData = (LPSTR) &psPlaybackBuffer[iBufNum][0];
|
m_WaveOutHeader[iBufNum].lpData = (LPSTR) &psPlaybackBuffer[iBufNum][0];
|
||||||
m_WaveOutHeader[iBufNum].dwBufferLength = iBufferSizeOut * BYTES_PER_SAMPLE;
|
m_WaveOutHeader[iBufNum].dwBufferLength = iBufferSizeOut * BYTES_PER_SAMPLE;
|
||||||
m_WaveOutHeader[iBufNum].dwFlags = 0;
|
m_WaveOutHeader[iBufNum].dwFlags = 0;
|
||||||
|
|
||||||
/* Prepare wave-header */
|
// Prepare wave-header
|
||||||
waveOutPrepareHeader ( m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
|
waveOutPrepareHeader ( m_WaveOut, &m_WaveOutHeader[iBufNum], sizeof ( WAVEHDR ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,20 +369,20 @@ void CSound::InitPlayback(int iNewBufferSize, bool bNewBlocking)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
// check if device must be opened or reinitialized
|
||||||
if ( bChangParamOut == TRUE )
|
if ( bChangParamOut == TRUE )
|
||||||
{
|
{
|
||||||
OpenOutDevice();
|
OpenOutDevice();
|
||||||
|
|
||||||
/* Reset flag */
|
// reset flag
|
||||||
bChangParamOut = FALSE;
|
bChangParamOut = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set internal parameters */
|
// set internal parameters
|
||||||
iBufferSizeOut = iNewBufferSize;
|
iBufferSizeOut = iNewBufferSize;
|
||||||
bBlockingPlay = bNewBlocking;
|
bBlockingPlay = bNewBlocking;
|
||||||
|
|
||||||
/* Reset interface */
|
// reset interface
|
||||||
waveOutReset ( m_WaveOut );
|
waveOutReset ( m_WaveOut );
|
||||||
|
|
||||||
for ( j = 0; j < iCurNumSndBufOut; j++ )
|
for ( j = 0; j < iCurNumSndBufOut; j++ )
|
||||||
|
@ -362,20 +391,24 @@ void CSound::InitPlayback(int iNewBufferSize, bool bNewBlocking)
|
||||||
simply nothing happens with this function call */
|
simply nothing happens with this function call */
|
||||||
waveOutUnprepareHeader ( m_WaveOut, &m_WaveOutHeader[j], sizeof ( WAVEHDR ) );
|
waveOutUnprepareHeader ( m_WaveOut, &m_WaveOutHeader[j], sizeof ( WAVEHDR ) );
|
||||||
|
|
||||||
/* Create memory for playback buffer */
|
// create memory for playback buffer
|
||||||
if ( psPlaybackBuffer[j] != NULL )
|
if ( psPlaybackBuffer[j] != NULL )
|
||||||
|
{
|
||||||
delete[] psPlaybackBuffer[j];
|
delete[] psPlaybackBuffer[j];
|
||||||
|
}
|
||||||
|
|
||||||
psPlaybackBuffer[j] = new short[iBufferSizeOut];
|
psPlaybackBuffer[j] = new short[iBufferSizeOut];
|
||||||
|
|
||||||
/* Clear new buffer */
|
// clear new buffer
|
||||||
for ( i = 0; i < iBufferSizeOut; i++ )
|
for ( i = 0; i < iBufferSizeOut; i++ )
|
||||||
|
{
|
||||||
psPlaybackBuffer[j][i] = 0;
|
psPlaybackBuffer[j][i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare buffer for sending to the sound interface */
|
// prepare buffer for sending to the sound interface
|
||||||
PrepareOutBuffer ( j );
|
PrepareOutBuffer ( j );
|
||||||
|
|
||||||
/* Initially, send all buffers to the interface */
|
// initially, send all buffers to the interface
|
||||||
AddOutBuffer ( j );
|
AddOutBuffer ( j );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,16 +425,20 @@ void CSound::OpenOutDevice()
|
||||||
(DWORD) m_WaveOutEvent, NULL, CALLBACK_EVENT );
|
(DWORD) m_WaveOutEvent, NULL, CALLBACK_EVENT );
|
||||||
|
|
||||||
if ( result != MMSYSERR_NOERROR )
|
if ( result != MMSYSERR_NOERROR )
|
||||||
|
{
|
||||||
throw CGenErr ( "Sound Interface Start, waveOutOpen() failed." );
|
throw CGenErr ( "Sound Interface Start, waveOutOpen() failed." );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSound::SetOutDev ( int iNewDev )
|
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 ) )
|
if ( ( iNewDev >= iNumDevs ) || ( iNewDev < 0 ) )
|
||||||
|
{
|
||||||
iNewDev = WAVE_MAPPER;
|
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 )
|
if ( iNewDev != iCurOutDev )
|
||||||
{
|
{
|
||||||
iCurOutDev = iNewDev;
|
iCurOutDev = iNewDev;
|
||||||
|
@ -411,11 +448,13 @@ void CSound::SetOutDev(int iNewDev)
|
||||||
|
|
||||||
void CSound::SetOutNumBuf ( int iNewNum )
|
void CSound::SetOutNumBuf ( int iNewNum )
|
||||||
{
|
{
|
||||||
/* check new parameter */
|
// check new parameter
|
||||||
if ( ( iNewNum >= MAX_SND_BUF_OUT ) || ( iNewNum < 1 ) )
|
if ( ( iNewNum >= MAX_SND_BUF_OUT ) || ( iNewNum < 1 ) )
|
||||||
|
{
|
||||||
iNewNum = NUM_SOUND_BUFFERS_OUT;
|
iNewNum = NUM_SOUND_BUFFERS_OUT;
|
||||||
|
}
|
||||||
|
|
||||||
/* Change only if parameter is different */
|
// change only if parameter is different
|
||||||
if ( iNewNum != iCurNumSndBufOut )
|
if ( iNewNum != iCurNumSndBufOut )
|
||||||
{
|
{
|
||||||
iCurNumSndBufOut = iNewNum;
|
iCurNumSndBufOut = iNewNum;
|
||||||
|
@ -432,29 +471,37 @@ void CSound::Close()
|
||||||
int i;
|
int i;
|
||||||
MMRESULT result;
|
MMRESULT result;
|
||||||
|
|
||||||
/* Reset audio driver */
|
// reset audio driver
|
||||||
if ( m_WaveOut != NULL )
|
if ( m_WaveOut != NULL )
|
||||||
{
|
{
|
||||||
result = waveOutReset ( m_WaveOut );
|
result = waveOutReset ( m_WaveOut );
|
||||||
|
|
||||||
if ( result != MMSYSERR_NOERROR )
|
if ( result != MMSYSERR_NOERROR )
|
||||||
|
{
|
||||||
throw CGenErr ( "Sound Interface, waveOutReset() failed." );
|
throw CGenErr ( "Sound Interface, waveOutReset() failed." );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_WaveIn != NULL )
|
if ( m_WaveIn != NULL )
|
||||||
{
|
{
|
||||||
result = waveInReset ( m_WaveIn );
|
result = waveInReset ( m_WaveIn );
|
||||||
|
|
||||||
if ( result != MMSYSERR_NOERROR )
|
if ( result != MMSYSERR_NOERROR )
|
||||||
|
{
|
||||||
throw CGenErr ( "Sound Interface, waveInReset() failed." );
|
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 )
|
if ( m_WaveInEvent != NULL )
|
||||||
|
{
|
||||||
SetEvent(m_WaveInEvent);
|
SetEvent(m_WaveInEvent);
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait for the thread to terminate */
|
// wait for the thread to terminate
|
||||||
Sleep ( 500 );
|
Sleep ( 500 );
|
||||||
|
|
||||||
/* Unprepare wave-headers */
|
// unprepare wave-headers
|
||||||
if ( m_WaveIn != NULL )
|
if ( m_WaveIn != NULL )
|
||||||
{
|
{
|
||||||
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
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 );
|
result = waveInClose ( m_WaveIn );
|
||||||
if ( result != MMSYSERR_NOERROR )
|
if ( result != MMSYSERR_NOERROR )
|
||||||
|
{
|
||||||
throw CGenErr ( "Sound Interface, waveInClose() failed." );
|
throw CGenErr ( "Sound Interface, waveInClose() failed." );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_WaveOut != NULL )
|
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 );
|
result = waveOutClose ( m_WaveOut );
|
||||||
if ( result != MMSYSERR_NOERROR )
|
if ( result != MMSYSERR_NOERROR )
|
||||||
|
{
|
||||||
throw CGenErr ( "Sound Interface, waveOutClose() failed." );
|
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;
|
bChangParamIn = TRUE;
|
||||||
bChangParamOut = TRUE;
|
bChangParamOut = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -504,17 +555,17 @@ CSound::CSound()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* init number of sound buffers */
|
// init number of sound buffers
|
||||||
iCurNumSndBufIn = NUM_SOUND_BUFFERS_IN;
|
iCurNumSndBufIn = NUM_SOUND_BUFFERS_IN;
|
||||||
iCurNumSndBufOut = NUM_SOUND_BUFFERS_OUT;
|
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_WaveInEvent = NULL;
|
||||||
m_WaveOutEvent = NULL;
|
m_WaveOutEvent = NULL;
|
||||||
m_WaveIn = NULL;
|
m_WaveIn = NULL;
|
||||||
m_WaveOut = NULL;
|
m_WaveOut = NULL;
|
||||||
|
|
||||||
/* Init buffer pointer to zero */
|
// init buffer pointer to zero
|
||||||
for ( i = 0; i < MAX_SND_BUF_IN; i++ )
|
for ( i = 0; i < MAX_SND_BUF_IN; i++ )
|
||||||
{
|
{
|
||||||
memset ( &m_WaveInHeader[i], 0, sizeof ( WAVEHDR ) );
|
memset ( &m_WaveInHeader[i], 0, sizeof ( WAVEHDR ) );
|
||||||
|
@ -527,7 +578,7 @@ CSound::CSound()
|
||||||
psPlaybackBuffer[i] = NULL;
|
psPlaybackBuffer[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init wave-format structure */
|
// init wave-format structure
|
||||||
sWaveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
|
sWaveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
|
||||||
sWaveFormatEx.nChannels = NUM_IN_OUT_CHANNELS;
|
sWaveFormatEx.nChannels = NUM_IN_OUT_CHANNELS;
|
||||||
sWaveFormatEx.wBitsPerSample = BITS_PER_SAMPLE;
|
sWaveFormatEx.wBitsPerSample = BITS_PER_SAMPLE;
|
||||||
|
@ -538,40 +589,46 @@ CSound::CSound()
|
||||||
sWaveFormatEx.nSamplesPerSec;
|
sWaveFormatEx.nSamplesPerSec;
|
||||||
sWaveFormatEx.cbSize = 0;
|
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();
|
iNumDevs = waveInGetNumDevs();
|
||||||
|
|
||||||
if ( iNumDevs > MAX_NUMBER_SOUND_CARDS )
|
if ( iNumDevs > MAX_NUMBER_SOUND_CARDS )
|
||||||
|
{
|
||||||
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 )
|
if ( iNumDevs == 0 )
|
||||||
|
{
|
||||||
throw CGenErr ( "No audio device found." );
|
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++ )
|
for ( i = 0; i < iNumDevs; i++ )
|
||||||
{
|
{
|
||||||
if ( !waveInGetDevCaps ( i, &m_WaveInDevCaps, sizeof ( WAVEINCAPS ) ) )
|
if ( !waveInGetDevCaps ( i, &m_WaveInDevCaps, sizeof ( WAVEINCAPS ) ) )
|
||||||
|
{
|
||||||
pstrDevices[i] = m_WaveInDevCaps.szPname;
|
pstrDevices[i] = m_WaveInDevCaps.szPname;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* We use an event controlled wave-in (wave-out) structure */
|
// we use an event controlled wave-in (wave-out) structure
|
||||||
/* Create events */
|
// create events
|
||||||
m_WaveInEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
|
m_WaveInEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
|
||||||
m_WaveOutEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
|
m_WaveOutEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
|
||||||
|
|
||||||
/* Set flag to open devices */
|
// set flag to open devices
|
||||||
bChangParamIn = TRUE;
|
bChangParamIn = TRUE;
|
||||||
bChangParamOut = TRUE;
|
bChangParamOut = TRUE;
|
||||||
|
|
||||||
/* Default device number, "wave mapper" */
|
// default device number, "wave mapper"
|
||||||
iCurInDev = WAVE_MAPPER;
|
iCurInDev = WAVE_MAPPER;
|
||||||
iCurOutDev = WAVE_MAPPER;
|
iCurOutDev = WAVE_MAPPER;
|
||||||
|
|
||||||
/* Non-blocking wave out is default */
|
// non-blocking wave out is default
|
||||||
bBlockingPlay = FALSE;
|
bBlockingPlay = FALSE;
|
||||||
|
|
||||||
/* Blocking wave in is default */
|
// blocking wave in is default
|
||||||
bBlockingRec = TRUE;
|
bBlockingRec = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,23 +636,31 @@ CSound::~CSound()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Delete allocated memory */
|
// delete allocated memory
|
||||||
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
||||||
{
|
{
|
||||||
if ( psSoundcardBuffer[i] != NULL )
|
if ( psSoundcardBuffer[i] != NULL )
|
||||||
|
{
|
||||||
delete[] psSoundcardBuffer[i];
|
delete[] psSoundcardBuffer[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( i = 0; i < iCurNumSndBufOut; i++ )
|
for ( i = 0; i < iCurNumSndBufOut; i++ )
|
||||||
{
|
{
|
||||||
if ( psPlaybackBuffer[i] != NULL )
|
if ( psPlaybackBuffer[i] != NULL )
|
||||||
|
{
|
||||||
delete[] psPlaybackBuffer[i];
|
delete[] psPlaybackBuffer[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the handle for the events */
|
// close the handle for the events
|
||||||
if ( m_WaveInEvent != NULL )
|
if ( m_WaveInEvent != NULL )
|
||||||
|
{
|
||||||
CloseHandle ( m_WaveInEvent );
|
CloseHandle ( m_WaveInEvent );
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_WaveOutEvent != NULL )
|
if ( m_WaveOutEvent != NULL )
|
||||||
|
{
|
||||||
CloseHandle ( m_WaveOutEvent );
|
CloseHandle ( m_WaveOutEvent );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
#define NUM_IN_OUT_CHANNELS 2 /* Stereo recording (but we only
|
#define NUM_IN_OUT_CHANNELS 2 /* Stereo recording (but we only
|
||||||
use one channel for recording) */
|
use one channel for recording) */
|
||||||
#define BITS_PER_SAMPLE 16 /* Use all bits of the D/A-converter */
|
#define BITS_PER_SAMPLE 16 // use all bits of the D/A-converter
|
||||||
#define BYTES_PER_SAMPLE 2 /* Number of bytes per sample */
|
#define BYTES_PER_SAMPLE 2 // number of bytes per sample
|
||||||
|
|
||||||
#define MAX_SND_BUF_IN 200
|
#define MAX_SND_BUF_IN 200
|
||||||
#define MAX_SND_BUF_OUT 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_IN ( 70 / MIN_BLOCK_DURATION_MS )
|
||||||
#define NUM_SOUND_BUFFERS_OUT ( 80 / 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
|
#define MAX_NUMBER_SOUND_CARDS 10
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ protected:
|
||||||
int iCurNumSndBufIn;
|
int iCurNumSndBufIn;
|
||||||
int iCurNumSndBufOut;
|
int iCurNumSndBufOut;
|
||||||
|
|
||||||
/* Wave in */
|
// wave in
|
||||||
WAVEINCAPS m_WaveInDevCaps;
|
WAVEINCAPS m_WaveInDevCaps;
|
||||||
HWAVEIN m_WaveIn;
|
HWAVEIN m_WaveIn;
|
||||||
HANDLE m_WaveInEvent;
|
HANDLE m_WaveInEvent;
|
||||||
|
@ -103,7 +103,7 @@ protected:
|
||||||
short* psSoundcardBuffer[MAX_SND_BUF_IN];
|
short* psSoundcardBuffer[MAX_SND_BUF_IN];
|
||||||
bool bBlockingRec;
|
bool bBlockingRec;
|
||||||
|
|
||||||
/* Wave out */
|
// wave out
|
||||||
int iBufferSizeOut;
|
int iBufferSizeOut;
|
||||||
HWAVEOUT m_WaveOut;
|
HWAVEOUT m_WaveOut;
|
||||||
short* psPlaybackBuffer[MAX_SND_BUF_OUT];
|
short* psPlaybackBuffer[MAX_SND_BUF_OUT];
|
||||||
|
|
Loading…
Add table
Reference in a new issue