preparations for using OPUS64 in the client
This commit is contained in:
parent
9b07cbeb5f
commit
765cb7d266
2 changed files with 52 additions and 42 deletions
|
@ -51,6 +51,7 @@ CClient::CClient ( const quint16 iPortNumber,
|
||||||
CurOpusDecoder ( nullptr ),
|
CurOpusDecoder ( nullptr ),
|
||||||
eAudioCompressionType ( CT_OPUS ),
|
eAudioCompressionType ( CT_OPUS ),
|
||||||
iCeltNumCodedBytes ( OPUS_NUM_BYTES_MONO_LOW_QUALITY ),
|
iCeltNumCodedBytes ( OPUS_NUM_BYTES_MONO_LOW_QUALITY ),
|
||||||
|
iOPUSFrameSizeSamples ( SYSTEM_FRAME_SIZE_SAMPLES ),
|
||||||
eAudioQuality ( AQ_NORMAL ),
|
eAudioQuality ( AQ_NORMAL ),
|
||||||
eAudioChannelConf ( CC_MONO ),
|
eAudioChannelConf ( CC_MONO ),
|
||||||
iNumAudioChannels ( 1 ),
|
iNumAudioChannels ( 1 ),
|
||||||
|
@ -77,29 +78,39 @@ CClient::CClient ( const quint16 iPortNumber,
|
||||||
{
|
{
|
||||||
int iOpusError;
|
int iOpusError;
|
||||||
|
|
||||||
// init audio encoders and decoders
|
|
||||||
OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES,
|
DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES,
|
||||||
&iOpusError );
|
&iOpusError );
|
||||||
|
|
||||||
OpusEncoderMono = opus_custom_encoder_create ( OpusMode, 1, &iOpusError ); // mono encoder legacy
|
Opus64Mode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ,
|
||||||
OpusDecoderMono = opus_custom_decoder_create ( OpusMode, 1, &iOpusError ); // mono decoder legacy
|
SYSTEM_FRAME_SIZE_SAMPLES_SMALL,
|
||||||
OpusEncoderStereo = opus_custom_encoder_create ( OpusMode, 2, &iOpusError ); // stereo encoder legacy
|
&iOpusError );
|
||||||
OpusDecoderStereo = opus_custom_decoder_create ( OpusMode, 2, &iOpusError ); // stereo decoder legacy
|
|
||||||
|
// init audio encoders and decoders
|
||||||
|
OpusEncoderMono = opus_custom_encoder_create ( OpusMode, 1, &iOpusError ); // mono encoder legacy
|
||||||
|
OpusDecoderMono = opus_custom_decoder_create ( OpusMode, 1, &iOpusError ); // mono decoder legacy
|
||||||
|
OpusEncoderStereo = opus_custom_encoder_create ( OpusMode, 2, &iOpusError ); // stereo encoder legacy
|
||||||
|
OpusDecoderStereo = opus_custom_decoder_create ( OpusMode, 2, &iOpusError ); // stereo decoder legacy
|
||||||
|
Opus64EncoderMono = opus_custom_encoder_create ( Opus64Mode, 1, &iOpusError ); // mono encoder OPUS64
|
||||||
|
Opus64DecoderMono = opus_custom_decoder_create ( Opus64Mode, 1, &iOpusError ); // mono decoder OPUS64
|
||||||
|
Opus64EncoderStereo = opus_custom_encoder_create ( Opus64Mode, 2, &iOpusError ); // stereo encoder OPUS64
|
||||||
|
Opus64DecoderStereo = opus_custom_decoder_create ( Opus64Mode, 2, &iOpusError ); // stereo decoder OPUS64
|
||||||
|
|
||||||
// we require a constant bit rate
|
// we require a constant bit rate
|
||||||
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_VBR ( 0 ) );
|
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_VBR ( 0 ) );
|
||||||
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_VBR ( 0 ) );
|
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_VBR ( 0 ) );
|
||||||
|
opus_custom_encoder_ctl ( Opus64EncoderMono, OPUS_SET_VBR ( 0 ) );
|
||||||
|
opus_custom_encoder_ctl ( Opus64EncoderStereo, OPUS_SET_VBR ( 0 ) );
|
||||||
|
|
||||||
// we want as low delay as possible
|
// we want as low delay as possible
|
||||||
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
||||||
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
||||||
|
opus_custom_encoder_ctl ( Opus64EncoderMono, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
||||||
|
opus_custom_encoder_ctl ( Opus64EncoderStereo, OPUS_SET_APPLICATION ( OPUS_APPLICATION_RESTRICTED_LOWDELAY ) );
|
||||||
|
|
||||||
#if ( SYSTEM_FRAME_SIZE_SAMPLES == 128 )
|
|
||||||
// set encoder low complexity for legacy 128 samples frame size
|
// set encoder low complexity for legacy 128 samples frame size
|
||||||
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_COMPLEXITY ( 1 ) );
|
opus_custom_encoder_ctl ( OpusEncoderMono, OPUS_SET_COMPLEXITY ( 1 ) );
|
||||||
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_COMPLEXITY ( 1 ) );
|
opus_custom_encoder_ctl ( OpusEncoderStereo, OPUS_SET_COMPLEXITY ( 1 ) );
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Connections -------------------------------------------------------------
|
// Connections -------------------------------------------------------------
|
||||||
|
@ -610,13 +621,6 @@ void CClient::OnCLChannelLevelListReceived ( CHostAddress InetAddr,
|
||||||
|
|
||||||
void CClient::Start()
|
void CClient::Start()
|
||||||
{
|
{
|
||||||
// always use the OPUS codec
|
|
||||||
#if ( SYSTEM_FRAME_SIZE_SAMPLES == 64 )
|
|
||||||
eAudioCompressionType = CT_OPUS64;
|
|
||||||
#else
|
|
||||||
eAudioCompressionType = CT_OPUS;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// init object
|
// init object
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
|
@ -710,8 +714,7 @@ void CClient::Init()
|
||||||
|
|
||||||
// inits for conversion buffer (the size of the conversion buffer must
|
// inits for conversion buffer (the size of the conversion buffer must
|
||||||
// be the sum of input/output sizes which is the worst case fill level)
|
// be the sum of input/output sizes which is the worst case fill level)
|
||||||
const int iConBufSize =
|
const int iConBufSize = iStereoBlockSizeSam + iSndCardStereoBlockSizeSamConvBuff;
|
||||||
iStereoBlockSizeSam + iSndCardStereoBlockSizeSamConvBuff;
|
|
||||||
|
|
||||||
SndCrdConversionBufferIn.Init ( iConBufSize );
|
SndCrdConversionBufferIn.Init ( iConBufSize );
|
||||||
SndCrdConversionBufferOut.Init ( iConBufSize );
|
SndCrdConversionBufferOut.Init ( iConBufSize );
|
||||||
|
@ -734,6 +737,15 @@ void CClient::Init()
|
||||||
AudioReverbR.Init ( SYSTEM_SAMPLE_RATE_HZ );
|
AudioReverbR.Init ( SYSTEM_SAMPLE_RATE_HZ );
|
||||||
|
|
||||||
// inits for audio coding
|
// inits for audio coding
|
||||||
|
// always use the OPUS codec
|
||||||
|
#if ( SYSTEM_FRAME_SIZE_SAMPLES == 64 )
|
||||||
|
eAudioCompressionType = CT_OPUS64;
|
||||||
|
#else
|
||||||
|
eAudioCompressionType = CT_OPUS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
iOPUSFrameSizeSamples = SYSTEM_FRAME_SIZE_SAMPLES;
|
||||||
|
|
||||||
if ( eAudioChannelConf == CC_MONO )
|
if ( eAudioChannelConf == CC_MONO )
|
||||||
{
|
{
|
||||||
CurOpusEncoder = OpusEncoderMono;
|
CurOpusEncoder = OpusEncoderMono;
|
||||||
|
@ -766,7 +778,7 @@ void CClient::Init()
|
||||||
opus_custom_encoder_ctl ( CurOpusEncoder,
|
opus_custom_encoder_ctl ( CurOpusEncoder,
|
||||||
OPUS_SET_BITRATE (
|
OPUS_SET_BITRATE (
|
||||||
CalcBitRateBitsPerSecFromCodedBytes (
|
CalcBitRateBitsPerSecFromCodedBytes (
|
||||||
iCeltNumCodedBytes, SYSTEM_FRAME_SIZE_SAMPLES ) ) );
|
iCeltNumCodedBytes, iOPUSFrameSizeSamples ) ) );
|
||||||
|
|
||||||
// inits for network and channel
|
// inits for network and channel
|
||||||
vecbyNetwData.Init ( iCeltNumCodedBytes );
|
vecbyNetwData.Init ( iCeltNumCodedBytes );
|
||||||
|
@ -988,17 +1000,13 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
for ( i = 0; i < iSndCrdFrameSizeFactor; i++ )
|
for ( i = 0; i < iSndCrdFrameSizeFactor; i++ )
|
||||||
{
|
{
|
||||||
// OPUS encoding
|
// OPUS encoding
|
||||||
if ( ( eAudioCompressionType == CT_OPUS ) ||
|
if ( CurOpusEncoder != nullptr )
|
||||||
( eAudioCompressionType == CT_OPUS64 ) )
|
|
||||||
{
|
{
|
||||||
if ( CurOpusEncoder != nullptr )
|
opus_custom_encode ( CurOpusEncoder,
|
||||||
{
|
&vecsStereoSndCrd[i * iNumAudioChannels * iOPUSFrameSizeSamples],
|
||||||
opus_custom_encode ( CurOpusEncoder,
|
iOPUSFrameSizeSamples,
|
||||||
&vecsStereoSndCrd[i * iNumAudioChannels * SYSTEM_FRAME_SIZE_SAMPLES],
|
&vecCeltData[0],
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES,
|
iCeltNumCodedBytes );
|
||||||
&vecCeltData[0],
|
|
||||||
iCeltNumCodedBytes );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send coded audio through the network
|
// send coded audio through the network
|
||||||
|
@ -1033,17 +1041,13 @@ void CClient::ProcessAudioDataIntern ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPUS decoding
|
// OPUS decoding
|
||||||
if ( ( eAudioCompressionType == CT_OPUS ) ||
|
if ( CurOpusDecoder != nullptr )
|
||||||
( eAudioCompressionType == CT_OPUS64 ) )
|
|
||||||
{
|
{
|
||||||
if ( CurOpusDecoder != nullptr )
|
opus_custom_decode ( CurOpusDecoder,
|
||||||
{
|
pCurCodedData,
|
||||||
opus_custom_decode ( CurOpusDecoder,
|
iCeltNumCodedBytes,
|
||||||
pCurCodedData,
|
&vecsStereoSndCrd[i * iNumAudioChannels * iOPUSFrameSizeSamples],
|
||||||
iCeltNumCodedBytes,
|
iOPUSFrameSizeSamples );
|
||||||
&vecsStereoSndCrd[i * iNumAudioChannels * SYSTEM_FRAME_SIZE_SAMPLES],
|
|
||||||
SYSTEM_FRAME_SIZE_SAMPLES );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,6 +316,11 @@ protected:
|
||||||
CProtocol ConnLessProtocol;
|
CProtocol ConnLessProtocol;
|
||||||
|
|
||||||
// audio encoder/decoder
|
// audio encoder/decoder
|
||||||
|
OpusCustomMode* Opus64Mode;
|
||||||
|
OpusCustomEncoder* Opus64EncoderMono;
|
||||||
|
OpusCustomDecoder* Opus64DecoderMono;
|
||||||
|
OpusCustomEncoder* Opus64EncoderStereo;
|
||||||
|
OpusCustomDecoder* Opus64DecoderStereo;
|
||||||
OpusCustomMode* OpusMode;
|
OpusCustomMode* OpusMode;
|
||||||
OpusCustomEncoder* OpusEncoderMono;
|
OpusCustomEncoder* OpusEncoderMono;
|
||||||
OpusCustomDecoder* OpusDecoderMono;
|
OpusCustomDecoder* OpusDecoderMono;
|
||||||
|
@ -325,6 +330,7 @@ protected:
|
||||||
OpusCustomDecoder* CurOpusDecoder;
|
OpusCustomDecoder* CurOpusDecoder;
|
||||||
EAudComprType eAudioCompressionType;
|
EAudComprType eAudioCompressionType;
|
||||||
int iCeltNumCodedBytes;
|
int iCeltNumCodedBytes;
|
||||||
|
int iOPUSFrameSizeSamples;
|
||||||
EAudioQuality eAudioQuality;
|
EAudioQuality eAudioQuality;
|
||||||
EAudChanConf eAudioChannelConf;
|
EAudChanConf eAudioChannelConf;
|
||||||
int iNumAudioChannels;
|
int iNumAudioChannels;
|
||||||
|
|
Loading…
Reference in a new issue