audiovisualwaveform: ceil rather than round when drawing samples
This may help with waveform visibility when tracks are set to smaller heights
This commit is contained in:
@@ -384,6 +384,12 @@ AudioVisualWaveform::Sample AudioVisualWaveform::ReSumSamples(const SamplePerCha
|
||||
return summed_samples;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
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<float>(channel_half_height)),
|
||||
channel_mid - round_away_from_zero(min * static_cast<float>(channel_half_height)),
|
||||
x,
|
||||
channel_mid - qRound(max * static_cast<float>(channel_half_height)));
|
||||
channel_mid - round_away_from_zero(max * static_cast<float>(channel_half_height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user