support for OPUS codec

This commit is contained in:
Volker Fischer 2013-02-16 18:16:12 +00:00
parent 0c4f22eaa2
commit eb277e3a96

View file

@ -216,6 +216,10 @@ CServer::CServer ( const int iNewNumChan,
1,
&iOpusError );
// we require a constant bit rate
opus_encoder_ctl ( OpusEncoderMono[i],
OPUS_SET_VBR ( 0 ) );
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
// set encoder low complexity
opus_encoder_ctl ( OpusEncoderMono[i],
@ -244,6 +248,10 @@ CServer::CServer ( const int iNewNumChan,
2,
&iOpusError );
// we require a constant bit rate
opus_encoder_ctl ( OpusEncoderStereo[i],
OPUS_SET_VBR ( 0 ) );
#ifdef USE_LOW_COMPLEXITY_CELT_ENC
// set encoder low complexity
opus_encoder_ctl ( OpusEncoderStereo[i],
@ -615,19 +623,45 @@ void CServer::OnTimer()
if ( iCurNumAudChan == 1 )
{
// mono
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_decode ( CeltDecoderMono[iCurChanID],
&vecbyData[0],
iCeltNumCodedBytes,
&vecvecsData[i][0] );
}
else
{
opus_decode ( OpusDecoderMono[iCurChanID],
&vecbyData[0],
iCeltNumCodedBytes,
&vecvecsData[i][0],
SYSTEM_FRAME_SIZE_SAMPLES,
0 );
}
}
else
{
// stereo
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_decode ( CeltDecoderStereo[iCurChanID],
&vecbyData[0],
iCeltNumCodedBytes,
&vecvecsData[i][0] );
}
else
{
opus_decode ( OpusDecoderStereo[iCurChanID],
&vecbyData[0],
iCeltNumCodedBytes,
&vecvecsData[i][0],
SYSTEM_FRAME_SIZE_SAMPLES,
0 );
}
}
}
else
{
@ -635,19 +669,45 @@ void CServer::OnTimer()
if ( iCurNumAudChan == 1 )
{
// mono
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_decode ( CeltDecoderMono[iCurChanID],
NULL,
0,
&vecvecsData[i][0] );
}
else
{
opus_decode ( OpusDecoderMono[iCurChanID],
NULL,
iCeltNumCodedBytes,
&vecvecsData[i][0],
SYSTEM_FRAME_SIZE_SAMPLES,
0 );
}
}
else
{
// stereo
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_decode ( CeltDecoderStereo[iCurChanID],
NULL,
0,
&vecvecsData[i][0] );
}
else
{
opus_decode ( OpusDecoderStereo[iCurChanID],
NULL,
iCeltNumCodedBytes,
&vecvecsData[i][0],
SYSTEM_FRAME_SIZE_SAMPLES,
0 );
}
}
}
// send message for get status (for GUI)
@ -694,12 +754,24 @@ 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<unsigned char> vecCeltData ( iCeltNumCodedBytes );
if ( vecChannels[iCurChanID].GetNumAudioChannels() == 1 )
{
// mono
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_encode ( CeltEncoderMono[iCurChanID],
&vecsSendData[0],
NULL,
@ -708,13 +780,47 @@ void CServer::OnTimer()
}
else
{
// 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
opus_encoder_ctl ( OpusEncoderMono[iCurChanID],
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
opus_encode ( OpusEncoderMono[iCurChanID],
&vecsSendData[0],
SYSTEM_FRAME_SIZE_SAMPLES,
&vecCeltData[0],
iCeltNumCodedBytes );
}
}
else
{
// stereo
if ( vecChannels[iCurChanID].GetAudioCompressionType() == CT_CELT )
{
cc6_celt_encode ( CeltEncoderStereo[iCurChanID],
&vecsSendData[0],
NULL,
&vecCeltData[0],
iCeltNumCodedBytes );
}
else
{
// 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
opus_encoder_ctl ( OpusEncoderStereo[iCurChanID],
OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) );
opus_encode ( OpusEncoderStereo[iCurChanID],
&vecsSendData[0],
SYSTEM_FRAME_SIZE_SAMPLES,
&vecCeltData[0],
iCeltNumCodedBytes );
}
}
// send separate mix to current clients
Socket.SendPacket (