From dd161ade12670c2b92105068527ae899a7e5afae Mon Sep 17 00:00:00 2001 From: Jirka Novak Date: Fri, 20 Aug 2021 22:39:01 +0200 Subject: [PATCH] RTP Player: Fix of resampling for visual waveform When capture was longer (e.g. 800s), audio was decoded correctly, but visual waveform was shown incorrectly. Reason was exceeding range of guint32 during calculation. Calculation is now made in guint64 and then put back to guint32. --- ui/qt/rtp_audio_stream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp index 27c973a06a..51e19e7b0f 100644 --- a/ui/qt/rtp_audio_stream.cpp +++ b/ui/qt/rtp_audio_stream.cpp @@ -412,7 +412,7 @@ void RtpAudioStream::decodeAudio(QAudioDeviceInfo out_device) // Buffer is in SAMPLEs spx_uint32_t in_len = (spx_uint32_t) (write_bytes / SAMPLE_BYTES); // Output is audio_out_rate_/sample_rate bigger than input - spx_uint32_t out_len = (spx_uint32_t) (in_len * audio_out_rate_ / sample_rate); + spx_uint32_t out_len = (spx_uint32_t) ((guint64)in_len * audio_out_rate_ / sample_rate); resample_buff = resizeBufferIfNeeded(resample_buff, &resample_buff_bytes, out_len * SAMPLE_BYTES); speex_resampler_process_int(audio_resampler_, 0, decode_buff, &in_len, resample_buff, &out_len); @@ -453,7 +453,7 @@ void RtpAudioStream::decodeVisual() // Loop over every frame record // readFrameSamples() maintains size of buffer for us while (audio_file_->readFrameSamples(&read_buff_bytes, &read_buff, &read_len, &frame_num, &type)) { - out_len = (spx_uint32_t)((read_len * visual_sample_rate_ ) / audio_out_rate_); + out_len = (spx_uint32_t)(((guint64)read_len * visual_sample_rate_ ) / audio_out_rate_); if (type == RTP_FRAME_AUDIO) { // We resample only audio samples