some more MS ADPCM work

This commit is contained in:
Volker Fischer 2008-08-09 16:34:02 +00:00
parent 83faac5a6d
commit e727287054
2 changed files with 45 additions and 17 deletions

View file

@ -519,20 +519,36 @@ CChannel::CChannel() : sName ( "" ),
iCurNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR ) iCurNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR )
{ {
// query all possible network in buffer sizes for determining if an // query all possible network in buffer sizes for determining if an
// audio packet was received // audio packet was received (the following code only works if all
// possible network buffer sizes are different!)
vecNetwBufferInProps.Init ( 2 * MAX_NET_BLOCK_SIZE_FACTOR );
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ ) for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{ {
// network block size factor must start from 1 -> ( i + 1 ) const int iIMAIdx = 2 * i;
vecNetwInBufSizes[i] = AudioCompressionIn.Init ( const int iMSIdx = 2 * i + 1;
( i + 1 ) * MIN_BLOCK_SIZE_SAMPLES,
CAudioCompression::CT_IMAADPCM ); // network block size factor must start from 1 -> i + 1
vecNetwBufferInProps[iIMAIdx].iBlockSizeFactor = i + 1;
vecNetwBufferInProps[iMSIdx].iBlockSizeFactor = i + 1;
// IMA ADPCM
vecNetwBufferInProps[iIMAIdx].eAudComprType = CAudioCompression::CT_IMAADPCM;
vecNetwBufferInProps[iIMAIdx].iNetwInBufSize = AudioCompressionIn.Init (
vecNetwBufferInProps[iIMAIdx].iBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
vecNetwBufferInProps[iIMAIdx].eAudComprType );
// MS ADPCM
vecNetwBufferInProps[iMSIdx].eAudComprType = CAudioCompression::CT_MSADPCM;
vecNetwBufferInProps[iMSIdx].iNetwInBufSize = AudioCompressionIn.Init (
vecNetwBufferInProps[iMSIdx].iBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
vecNetwBufferInProps[iMSIdx].eAudComprType );
} }
// init the socket buffer // init the socket buffer
SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL ); SetSockBufSize ( DEF_NET_BUF_SIZE_NUM_BL );
// set initial input and output block size factors // set initial input and output block size factors
SetNetwInBlSiFact ( DEF_NET_BLOCK_SIZE_FACTOR ); SetNetwInBlSiFactAndCompr ( DEF_NET_BLOCK_SIZE_FACTOR, CAudioCompression::CT_IMAADPCM );
SetNetwBufSizeFactOut ( DEF_NET_BLOCK_SIZE_FACTOR ); SetNetwBufSizeFactOut ( DEF_NET_BLOCK_SIZE_FACTOR );
// init time-out for the buffer with zero -> no connection // init time-out for the buffer with zero -> no connection
@ -589,15 +605,15 @@ void CChannel::SetEnable ( const bool bNEnStat )
} }
} }
void CChannel::SetNetwInBlSiFact ( const int iNewBlockSizeFactor ) void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
const CAudioCompression::EAudComprType eNewAudComprType )
{ {
// store new value // store new value
iCurNetwInBlSiFact = iNewBlockSizeFactor; iCurNetwInBlSiFact = iNewBlockSizeFactor;
// init audio compression unit // init audio compression unit
AudioCompressionIn.Init ( AudioCompressionIn.Init ( iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES,
iNewBlockSizeFactor * MIN_BLOCK_SIZE_SAMPLES, eNewAudComprType );
CAudioCompression::CT_IMAADPCM );
// initial value for connection time out counter // initial value for connection time out counter
iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) / iConTimeOutStartVal = ( CON_TIME_OUT_SEC_MAX * 1000 ) /
@ -737,19 +753,24 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
if ( !bIsProtocolPacket ) if ( !bIsProtocolPacket )
{ {
// check if this is an audio packet by checking all possible lengths // check if this is an audio packet by checking all possible lengths
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ ) const int iPossNetwSizes = vecNetwBufferInProps.Size();
for ( int i = 0; i < iPossNetwSizes; i++ )
{ {
// check for low/high quality audio packets and set flags // check for low/high quality audio packets and set flags
if ( iNumBytes == vecNetwInBufSizes[i] ) if ( iNumBytes == vecNetwBufferInProps[i].iNetwInBufSize )
{ {
bIsAudioPacket = true; bIsAudioPacket = true;
// check if we are correctly initialized // check if we are correctly initialized
const int iNewNetwInBlSiFact = i + 1; const int iNewNetwInBlSiFact =
vecNetwBufferInProps[i].iBlockSizeFactor;
if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact ) if ( iNewNetwInBlSiFact != iCurNetwInBlSiFact )
{ {
// re-initialize to new value // re-initialize to new value
SetNetwInBlSiFact ( iNewNetwInBlSiFact ); SetNetwInBlSiFactAndCompr ( iNewNetwInBlSiFact,
vecNetwBufferInProps[i].eAudComprType );
} }
} }
} }

View file

@ -136,7 +136,8 @@ public:
} }
protected: protected:
void SetNetwInBlSiFact ( const int iNewBlockSizeFactor ); void SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
const CAudioCompression::EAudComprType eNewAudComprType );
// audio compression // audio compression
CAudioCompression AudioCompressionIn; CAudioCompression AudioCompressionIn;
@ -173,7 +174,13 @@ protected:
bool bIsEnabled; bool bIsEnabled;
int vecNetwInBufSizes[MAX_NET_BLOCK_SIZE_FACTOR]; struct sNetwBufferInProps
{
int iNetwInBufSize;
int iBlockSizeFactor;
CAudioCompression::EAudComprType eAudComprType;
};
CVector<sNetwBufferInProps> vecNetwBufferInProps;
int iCurNetwInBlSiFact; int iCurNetwInBlSiFact;
int iCurNetwOutBlSiFact; int iCurNetwOutBlSiFact;