Browse Source

engine: client: added support for variable voice chat quality

pull/2/head
SNMetamorph 2 years ago committed by Alibek Omarov
parent
commit
c6881a425f
  1. 2
      engine/client/cl_main.c
  2. 30
      engine/client/voice.c

2
engine/client/cl_main.c

@ -3085,7 +3085,7 @@ void CL_Init( void )
VID_Init(); // init video VID_Init(); // init video
S_Init(); // init sound S_Init(); // init sound
Voice_Init( "opus", 0 ); // init voice Voice_Init( "opus", 3 ); // init voice
// unreliable buffer. unsed for unreliable commands and voice stream // unreliable buffer. unsed for unreliable commands and voice stream
MSG_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf )); MSG_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf ));

30
engine/client/voice.c

@ -79,9 +79,37 @@ qboolean Voice_Init( const char *pszCodecName, int quality )
} }
voice.encoder = opus_encoder_create( voice.samplerate, voice.channels, OPUS_APPLICATION_VOIP, &err ); voice.encoder = opus_encoder_create( voice.samplerate, voice.channels, OPUS_APPLICATION_VOIP, &err );
if( err != OPUS_OK )
return false;
voice.decoder = opus_decoder_create( voice.samplerate, voice.channels, &err ); voice.decoder = opus_decoder_create( voice.samplerate, voice.channels, &err );
return true; switch( quality )
{
case 1: // 4800 bits per second, <4 kHz bandwidth
opus_encoder_ctl( voice.encoder, OPUS_SET_BITRATE( 4800 ));
opus_encoder_ctl( voice.encoder, OPUS_SET_BANDWIDTH( OPUS_BANDWIDTH_NARROWBAND ));
break;
case 2: // 12000 bits per second, <6 kHz bandwidth
opus_encoder_ctl( voice.encoder, OPUS_SET_BITRATE( 12000 ));
opus_encoder_ctl( voice.encoder, OPUS_SET_BANDWIDTH( OPUS_BANDWIDTH_MEDIUMBAND ));
break;
case 4: // automatic bitrate, full band (20 kHz)
opus_encoder_ctl( voice.encoder, OPUS_SET_BITRATE( OPUS_AUTO ));
opus_encoder_ctl( voice.encoder, OPUS_SET_BANDWIDTH( OPUS_BANDWIDTH_FULLBAND ));
break;
case 5: // maximum bitrate, full band (20 kHz)
opus_encoder_ctl( voice.encoder, OPUS_SET_BITRATE( OPUS_BITRATE_MAX ));
opus_encoder_ctl( voice.encoder, OPUS_SET_BANDWIDTH( OPUS_BANDWIDTH_FULLBAND ));
break;
default: // 36000 bits per second, <12 kHz bandwidth
opus_encoder_ctl( voice.encoder, OPUS_SET_BITRATE( 36000 ));
opus_encoder_ctl( voice.encoder, OPUS_SET_BANDWIDTH( OPUS_BANDWIDTH_SUPERWIDEBAND ));
break;
}
return err == OPUS_OK;
} }
void Voice_DeInit( void ) void Voice_DeInit( void )

Loading…
Cancel
Save