engine: client: voice: fixed sound playback from file

This commit is contained in:
SNMetamorph 2022-08-18 13:07:47 +04:00 committed by Alibek Omarov
parent f7dc9d8e72
commit 2f5f5ef0a6
1 changed files with 9 additions and 8 deletions

View File

@ -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;