Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix various AudioFileProcessor bugs #7533

Merged
merged 7 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugins/AudioFileProcessor/AudioFileProcessorWaveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,12 @@ void AudioFileProcessorWaveView::updateGraph()
m_graph.fill(Qt::transparent);
QPainter p(&m_graph);
p.setPen(QColor(255, 255, 255));

const auto dataOffset = m_reversed ? m_sample->sampleSize() - m_to : m_from;

const auto rect = QRect{0, 0, m_graph.width(), m_graph.height()};
const auto waveform = SampleWaveform::Parameters{
m_sample->data() + m_from, static_cast<size_t>(range()), m_sample->amplification(), m_sample->reversed()};
m_sample->data() + dataOffset, static_cast<size_t>(range()), m_sample->amplification(), m_sample->reversed()};
SampleWaveform::visualize(waveform, p, rect);
}

Expand Down Expand Up @@ -467,9 +469,11 @@ void AudioFileProcessorWaveView::reverse()
- m_sample->endFrame()
- m_sample->startFrame()
);

const int m_from_ = m_from;
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved

setFrom(m_sample->sampleSize() - m_to);
setTo(m_sample->sampleSize() - m_from);
setTo(m_sample->sampleSize() - m_from_);
m_reversed = ! m_reversed;
}

Expand Down
11 changes: 4 additions & 7 deletions src/gui/SampleWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ void SampleWaveform::visualize(Parameters parameters, QPainter& painter, const Q
const float resolution = std::max(1.0f, framesPerPixel / maxFramesPerPixel);
const float framesPerResolution = framesPerPixel / resolution;

const size_t numPixels = std::min<size_t>(parameters.size, width);
size_t numPixels = std::min(parameters.size, static_cast<size_t>(width));
auto min = std::vector<float>(numPixels, 1);
auto max = std::vector<float>(numPixels, -1);
auto squared = std::vector<float>(numPixels, 0);

const size_t maxFrames = numPixels * static_cast<size_t>(framesPerPixel);
const size_t maxFrames = static_cast<size_t>(static_cast<float>(numPixels) * framesPerPixel);
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved

auto pixelIndex = std::size_t{0};

Expand All @@ -67,12 +67,9 @@ void SampleWaveform::visualize(Parameters parameters, QPainter& painter, const Q
squared[pixelIndex] += value * value;
}

while (pixelIndex < numPixels)
if (pixelIndex < numPixels)
{
max[pixelIndex] = 0.0;
min[pixelIndex] = 0.0;

pixelIndex++;
numPixels = pixelIndex;
}

for (auto i = std::size_t{0}; i < numPixels; i++)
Expand Down
Loading