Permalink
Browse files

Calculate and report BPM

  • Loading branch information...
mlang committed Jul 27, 2017
1 parent ab0fccd commit 424678d525392164af748c2745218b54ad4308fe
Showing with 17 additions and 4 deletions.
  1. +1 −2 CMakeLists.txt
  2. +16 −2 cv2midiclock.cpp
View
@@ -13,5 +13,4 @@ target_link_libraries(stats IO Boost::boost)
add_executable(brltest brltest.cpp)
target_link_libraries(brltest IO)
add_executable(cv2midiclock cv2midiclock.cpp)
target_link_libraries(cv2midiclock IO)
target_link_libraries(cv2midiclock IO Boost::boost)
View
@@ -1,9 +1,14 @@
#include <chrono>
#include <thread>
#include <boost/lockfree/spsc_queue.hpp>
#include <jack.hpp>
#include <dsp.hpp>
boost::lockfree::spsc_queue<std::size_t, boost::lockfree::capacity<8>> FPP;
class EdgeDetect : public JACK::Client {
JACK::AudioIn CVIn;
JACK::MIDIOut MIDIOut;
@@ -35,6 +40,7 @@ class EdgeDetect : public JACK::Client {
PulseOffset = Frame;
FramesPerPulse = FramesSinceLastPulse;
FramesSinceLastPulse = 0;
FPP.push(FramesPerPulse);
}
PreviousDifference = Difference;
Frame += 1; FramesSinceLastPulse += 1;
@@ -65,10 +71,18 @@ using namespace std::literals::chrono_literals;
int main() {
EdgeDetect App;
std::string const Chars = "\\|/-";
unsigned int CurrentChar = 0;
App.activate();
while (true) {
std::this_thread::sleep_for(10ms);
std::size_t FramesPerPulse;
while (FPP.pop(FramesPerPulse)) {
auto BPM = static_cast<float>(App.sampleRate()) / FramesPerPulse * 60;
std::cout << BPM << " BPM " << Chars[CurrentChar++] << " \r";
std::flush(std::cout);
if (CurrentChar == Chars.size()) CurrentChar = 0;
}
std::this_thread::sleep_for(5ms);
}
return EXIT_SUCCESS;

0 comments on commit 424678d

Please sign in to comment.