From 2f5f5ef0a6cceddb6f54703b0cfbeeabce99498d Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:07:47 +0400 Subject: [PATCH] engine: client: voice: fixed sound playback from file --- engine/client/voice.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/engine/client/voice.c b/engine/client/voice.c index 8b7c818b..1e8de7ee 100644 --- a/engine/client/voice.c +++ b/engine/client/voice.c @@ -198,27 +198,28 @@ uint Voice_GetCompressedData( byte *out, uint maxsize, uint *frames ) if ( input_file ) { uint numbytes; - double time; - - time = Sys_DoubleTime(); + double updateInterval; - numbytes = ( time - voice.start_time ) * voice.samplerate; + updateInterval = cl.mtime[0] - cl.mtime[1]; + numbytes = updateInterval * voice.samplerate * voice.width * voice.channels; numbytes = Q_min( numbytes, input_file->size - input_pos ); numbytes = Q_min( numbytes, sizeof( voice.input_buffer ) - voice.input_buffer_pos ); memcpy( voice.input_buffer + voice.input_buffer_pos, input_file->buffer + input_pos, numbytes ); voice.input_buffer_pos += numbytes; input_pos += numbytes; - - voice.start_time = time; } for ( ofs = 0; voice.input_buffer_pos - ofs >= voice.frame_size && ofs <= voice.input_buffer_pos; ofs += voice.frame_size ) { int bytes; - // adjust gain before encoding - Voice_ApplyGainAdjust((opus_int16*)voice.input_buffer + ofs, voice.frame_size); + if (!input_file) + { + // adjust gain before encoding, but only for input from voice + Voice_ApplyGainAdjust((opus_int16*)voice.input_buffer + ofs, voice.frame_size); + } + bytes = opus_encode( voice.encoder, (const opus_int16*)(voice.input_buffer + ofs), voice.frame_size / voice.width, out + size, maxsize ); memmove( voice.input_buffer, voice.input_buffer + voice.frame_size, sizeof( voice.input_buffer ) - voice.frame_size ); voice.input_buffer_pos -= voice.frame_size;