some code cleanup
This commit is contained in:
parent
e4697ac396
commit
b4069f93f9
3 changed files with 22 additions and 24 deletions
|
@ -64,7 +64,7 @@ CClient::CClient ( const quint16 iPortNumber ) :
|
||||||
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
||||||
// set encoder low complexity
|
// set encoder low complexity
|
||||||
cc6_celt_encoder_ctl ( CeltEncoderMono,
|
cc6_celt_encoder_ctl ( CeltEncoderMono,
|
||||||
cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) );
|
cc6_CELT_SET_COMPLEXITY ( 1 ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
||||||
|
@ -99,7 +99,7 @@ CClient::CClient ( const quint16 iPortNumber ) :
|
||||||
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
||||||
// set encoder low complexity
|
// set encoder low complexity
|
||||||
cc6_celt_encoder_ctl ( CeltEncoderStereo,
|
cc6_celt_encoder_ctl ( CeltEncoderStereo,
|
||||||
cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) );
|
cc6_CELT_SET_COMPLEXITY ( 1 ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OpusEncoderStereo = opus_custom_encoder_create ( OpusMode,
|
OpusEncoderStereo = opus_custom_encoder_create ( OpusMode,
|
||||||
|
@ -730,20 +730,19 @@ void CClient::Init()
|
||||||
}
|
}
|
||||||
vecCeltData.Init ( iCeltNumCodedBytes );
|
vecCeltData.Init ( iCeltNumCodedBytes );
|
||||||
|
|
||||||
// calculate and set the bit rate
|
|
||||||
const int iCeltBitRateBitsPerSec =
|
|
||||||
( SYSTEM_SAMPLE_RATE_HZ * iCeltNumCodedBytes * 8 ) /
|
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES;
|
|
||||||
|
|
||||||
if ( bUseStereo )
|
if ( bUseStereo )
|
||||||
{
|
{
|
||||||
opus_custom_encoder_ctl ( OpusEncoderStereo,
|
opus_custom_encoder_ctl ( OpusEncoderStereo,
|
||||||
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
|
OPUS_SET_BITRATE (
|
||||||
|
CalcBitRateBitsPerSecFromCodedBytes (
|
||||||
|
iCeltNumCodedBytes ) ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
opus_custom_encoder_ctl ( OpusEncoderMono,
|
opus_custom_encoder_ctl ( OpusEncoderMono,
|
||||||
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
|
OPUS_SET_BITRATE (
|
||||||
|
CalcBitRateBitsPerSecFromCodedBytes (
|
||||||
|
iCeltNumCodedBytes ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// inits for network and channel
|
// inits for network and channel
|
||||||
|
|
|
@ -204,7 +204,7 @@ CServer::CServer ( const int iNewNumChan,
|
||||||
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
||||||
// set encoder low complexity
|
// set encoder low complexity
|
||||||
cc6_celt_encoder_ctl ( CeltEncoderMono[i],
|
cc6_celt_encoder_ctl ( CeltEncoderMono[i],
|
||||||
cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) );
|
cc6_CELT_SET_COMPLEXITY ( 1 ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OpusMode[i] = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
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
|
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
|
||||||
// set encoder low complexity
|
// set encoder low complexity
|
||||||
cc6_celt_encoder_ctl ( CeltEncoderStereo[i],
|
cc6_celt_encoder_ctl ( CeltEncoderStereo[i],
|
||||||
cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) );
|
cc6_CELT_SET_COMPLEXITY ( 1 ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OpusEncoderStereo[i] = opus_custom_encoder_create ( OpusMode[i],
|
OpusEncoderStereo[i] = opus_custom_encoder_create ( OpusMode[i],
|
||||||
|
@ -752,21 +752,12 @@ void CServer::OnTimer()
|
||||||
const int iCeltNumCodedBytes =
|
const int iCeltNumCodedBytes =
|
||||||
vecChannels[iCurChanID].GetNetwFrameSize();
|
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
|
// CELT encoding
|
||||||
CVector<unsigned char> vecCeltData ( iCeltNumCodedBytes );
|
CVector<unsigned char> vecCeltData ( iCeltNumCodedBytes );
|
||||||
|
|
||||||
if ( vecChannels[iCurChanID].GetNumAudioChannels() == 1 )
|
if ( vecChannels[iCurChanID].GetNumAudioChannels() == 1 )
|
||||||
{
|
{
|
||||||
// mono
|
// mono:
|
||||||
|
|
||||||
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
|
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
|
// so for speed optimization it would be better to set it only if the network
|
||||||
// frame size is changed
|
// frame size is changed
|
||||||
opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID],
|
opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID],
|
||||||
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
|
OPUS_SET_BITRATE ( CalcBitRateBitsPerSecFromCodedBytes ( iCeltNumCodedBytes ) ) );
|
||||||
|
|
||||||
opus_custom_encode ( OpusEncoderMono[iCurChanID],
|
opus_custom_encode ( OpusEncoderMono[iCurChanID],
|
||||||
&vecsSendData[0],
|
&vecsSendData[0],
|
||||||
|
@ -794,7 +785,7 @@ opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID],
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// stereo
|
// stereo:
|
||||||
|
|
||||||
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
|
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
|
// so for speed optimization it would be better to set it only if the network
|
||||||
// frame size is changed
|
// frame size is changed
|
||||||
opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID],
|
opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID],
|
||||||
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
|
OPUS_SET_BITRATE ( CalcBitRateBitsPerSecFromCodedBytes ( iCeltNumCodedBytes ) ) );
|
||||||
|
|
||||||
opus_custom_encode ( OpusEncoderStereo[iCurChanID],
|
opus_custom_encode ( OpusEncoderStereo[iCurChanID],
|
||||||
&vecsSendData[0],
|
&vecsSendData[0],
|
||||||
|
|
|
@ -76,6 +76,14 @@ void DebugError ( const QString& pchErDescr,
|
||||||
const QString& pchPar2Descr,
|
const QString& pchPar2Descr,
|
||||||
const double dPar2 );
|
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 *
|
* CVector Base Class *
|
||||||
|
|
Loading…
Reference in a new issue