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