diff --git a/src/client.cpp b/src/client.cpp index 836a856d..d94939f6 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -64,7 +64,7 @@ CClient::CClient ( const quint16 iPortNumber ) : #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity cc6_celt_encoder_ctl ( CeltEncoderMono, - cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); + cc6_CELT_SET_COMPLEXITY ( 1 ) ); #endif OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ, @@ -99,7 +99,7 @@ CClient::CClient ( const quint16 iPortNumber ) : #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity cc6_celt_encoder_ctl ( CeltEncoderStereo, - cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); + cc6_CELT_SET_COMPLEXITY ( 1 ) ); #endif OpusEncoderStereo = opus_custom_encoder_create ( OpusMode, @@ -730,20 +730,19 @@ void CClient::Init() } vecCeltData.Init ( iCeltNumCodedBytes ); - // calculate and set the bit rate - const int iCeltBitRateBitsPerSec = - ( SYSTEM_SAMPLE_RATE_HZ * iCeltNumCodedBytes * 8 ) / - SYSTEM_FRAME_SIZE_SAMPLES; - if ( bUseStereo ) { opus_custom_encoder_ctl ( OpusEncoderStereo, - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + OPUS_SET_BITRATE ( + CalcBitRateBitsPerSecFromCodedBytes ( + iCeltNumCodedBytes ) ) ); } else { opus_custom_encoder_ctl ( OpusEncoderMono, - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + OPUS_SET_BITRATE ( + CalcBitRateBitsPerSecFromCodedBytes ( + iCeltNumCodedBytes ) ) ); } // inits for network and channel diff --git a/src/server.cpp b/src/server.cpp index 461e0a1d..0c1acd15 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -204,7 +204,7 @@ CServer::CServer ( const int iNewNumChan, #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity cc6_celt_encoder_ctl ( CeltEncoderMono[i], - cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); + cc6_CELT_SET_COMPLEXITY ( 1 ) ); #endif OpusMode[i] = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ, @@ -239,7 +239,7 @@ CServer::CServer ( const int iNewNumChan, #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity cc6_celt_encoder_ctl ( CeltEncoderStereo[i], - cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); + cc6_CELT_SET_COMPLEXITY ( 1 ) ); #endif OpusEncoderStereo[i] = opus_custom_encoder_create ( OpusMode[i], @@ -752,21 +752,12 @@ void CServer::OnTimer() const int iCeltNumCodedBytes = vecChannels[iCurChanID].GetNetwFrameSize(); - -// TODO find a better place than this: the setting does not change all the time -// so for speed optimization it would be better to set it only if the network -// frame size is changed -const int iCeltBitRateBitsPerSec = - ( SYSTEM_SAMPLE_RATE_HZ * iCeltNumCodedBytes * 8 ) / - SYSTEM_FRAME_SIZE_SAMPLES; - - // CELT encoding CVector vecCeltData ( iCeltNumCodedBytes ); if ( vecChannels[iCurChanID].GetNumAudioChannels() == 1 ) { - // mono + // mono: if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT ) { @@ -783,7 +774,7 @@ const int iCeltBitRateBitsPerSec = // so for speed optimization it would be better to set it only if the network // frame size is changed opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID], - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + OPUS_SET_BITRATE ( CalcBitRateBitsPerSecFromCodedBytes ( iCeltNumCodedBytes ) ) ); opus_custom_encode ( OpusEncoderMono[iCurChanID], &vecsSendData[0], @@ -794,7 +785,7 @@ opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID], } else { - // stereo + // stereo: if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT ) { @@ -810,7 +801,7 @@ opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID], // so for speed optimization it would be better to set it only if the network // frame size is changed opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID], - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + OPUS_SET_BITRATE ( CalcBitRateBitsPerSecFromCodedBytes ( iCeltNumCodedBytes ) ) ); opus_custom_encode ( OpusEncoderStereo[iCurChanID], &vecsSendData[0], diff --git a/src/util.h b/src/util.h index 163b6893..b2012dcd 100755 --- a/src/util.h +++ b/src/util.h @@ -76,6 +76,14 @@ void DebugError ( const QString& pchErDescr, const QString& pchPar2Descr, const double dPar2 ); +// calculate the bit rate in bits per second from the number of coded bytes +inline int CalcBitRateBitsPerSecFromCodedBytes ( const int iCeltNumCodedBytes ) +{ + return ( SYSTEM_SAMPLE_RATE_HZ * iCeltNumCodedBytes * 8 ) / + SYSTEM_FRAME_SIZE_SAMPLES; +} + + /******************************************************************************\ * CVector Base Class *