Skip to content

Commit

Permalink
fixup! refactor: use higher-level std::span based logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Oct 11, 2024
1 parent b10d4b1 commit 060ab9d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/effects/backends/builtin/metronomeeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ std::span<T> subspan_clamped(std::span<T> in, typename std::span<T>::size_type o
return in.subspan(std::min(offset, in.size()));
}

std::size_t samplesPerBeat(mixxx::audio::SampleRate sampleRate, double bpm) {
double samplesPerMinute = sampleRate * 60;
return static_cast<std::size_t>(samplesPerMinute / bpm);
constexpr std::size_t framesPerBeat(
mixxx::audio::SampleRate framesPerSecond, double beatsPerMinute) {
double framesPerMinute = framesPerSecond * 60;
return static_cast<std::size_t>(framesPerMinute / beatsPerMinute);
}

std::span<CSAMPLE> syncedClickOutput(double beatFractionBufferEnd,
Expand Down Expand Up @@ -166,12 +167,12 @@ void MetronomeEffect::processChannel(
groupFeatures.beat_length,
output);
} else {
std::size_t samplesSinceLastClick =
gs->framesSinceLastClick * mixxx::kEngineChannelOutputCount;
std::size_t offset = samplesSinceLastClick %
samplesPerBeat(engineParameters.sampleRate(),
// EngineParameters::sampleRate in reality returns the framerate.
mixxx::audio::SampleRate framesPerSecond = engineParameters.sampleRate();
std::size_t offset = gs->framesSinceLastClick %
framesPerBeat(framesPerSecond,
m_pBpmParameter->value());
return subspan_clamped(output, offset);
return subspan_clamped(output, offset * mixxx::kEngineChannelOutputCount);
}
}();

Expand Down

0 comments on commit 060ab9d

Please sign in to comment.