diff --git a/app/audio/audiovisualwaveform.cpp b/app/audio/audiovisualwaveform.cpp index fbe4d6120..0558eb600 100644 --- a/app/audio/audiovisualwaveform.cpp +++ b/app/audio/audiovisualwaveform.cpp @@ -384,6 +384,12 @@ AudioVisualWaveform::Sample AudioVisualWaveform::ReSumSamples(const SamplePerCha return summed_samples; } +template +inline int round_away_from_zero(T t) +{ + return (t < 0) ? std::floor(t) : std::ceil(t); +} + void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, int x, int y, int height, bool rectified) { if (sample.empty()) { @@ -400,7 +406,7 @@ void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, in if (rectified) { int channel_bottom = y + channel_height * (i + 1); - int diff = qRound((max - min) * channel_half_height); + int diff = round_away_from_zero((max - min) * channel_half_height); painter->drawLine(x, channel_bottom - diff, @@ -412,9 +418,9 @@ void AudioVisualWaveform::DrawSample(QPainter *painter, const Sample& sample, in // We subtract the sample so that positive Y values go up on the screen rather than down, // which is how waveforms are usually rendered painter->drawLine(x, - channel_mid - qRound(min * static_cast(channel_half_height)), + channel_mid - round_away_from_zero(min * static_cast(channel_half_height)), x, - channel_mid - qRound(max * static_cast(channel_half_height))); + channel_mid - round_away_from_zero(max * static_cast(channel_half_height))); } } }