From 0399f008b22482c46d37fa15e6be205b85681011 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 3 Jan 2025 23:43:56 +0100 Subject: Buffer position compensation for PCM, added active sensing detection --- PCM.h | 2 +- README.md | 21 +++++++++++++++++++++ UI.cpp | 15 +++++++++++---- UI.h | 4 ++++ main.cpp | 3 +++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/PCM.h b/PCM.h index 3e9b41d..a74b2ea 100644 --- a/PCM.h +++ b/PCM.h @@ -82,7 +82,7 @@ public: if (0 > snd_pcm_delay(handle, &delay)) { } - m_phase = 0; // - click_latency_frames + delay + m_phase = - click_latency_frames + delay; } // generate 1 buffer size diff --git a/README.md b/README.md index 190d9a2..5e91c1f 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,24 @@ Features: - Display: - set/detected tempo (from clock/click) - detected notes + +Configure device: + +Find your card with: +$ cat /proc/asound/cards + +To get valid ALSA card names, use aplay: + +$ aplay -l + +and then create /etc/asound.conf with following: + +pcm.!default { + type hw + card 1 +} + +ctl.!default { + type hw + card 1 +} diff --git a/UI.cpp b/UI.cpp index 8baf4db..c083d53 100644 --- a/UI.cpp +++ b/UI.cpp @@ -12,7 +12,7 @@ using namespace std::chrono_literals; -UI::UI(): m_main_loops{}, m_main_loops_checkpoint{}, m_main_loops_timestamp{} +UI::UI(): m_main_loops{}, m_main_loops_checkpoint{}, m_main_loops_timestamp{}, m_active_sensing_timestamp{} { } @@ -35,14 +35,16 @@ void UI::draw() std::vector cpuloads = get_cpu_loads(); int main_loops_per_second = get_main_loops_per_second(); + bool active_sensing_detected = (clock_type::now() - m_active_sensing_timestamp) < 2s; + // clear screen std::cout << "\x1B[2J\x1B[H"; - std::cout << std::endl; + //std::cout << std::endl; + std::cout << "- -- BPM +" << std::endl; std::cout << "Mode: Click __/__ (Clock Internal)" << std::endl; std::cout << std::endl; std::cout << "Status:" << std::endl; - std::cout << " Alive/not alive" << std::endl; std::cout << " CPU:"; for (auto& i: cpuloads) { @@ -53,9 +55,10 @@ void UI::draw() std::cout << " Notes/Channels: -- -- -- ... (Choose)" << std::endl; std::cout << " Timestamp: ------" << std::endl; - std::cout << " Active sensing: ---" << std::endl; + std::cout << fmt::format(" Active sensing: {}", active_sensing_detected) << std::endl; std::cout << " Clock: ____ BPM" << std::endl; std::cout << " Click: ____ BPM" << std::endl; + std::cout << " Internal: ____ BPM" << std::endl; std::cout << fmt::format(" Main loops/s: {}", main_loops_per_second) << std::endl; @@ -69,3 +72,7 @@ void UI::count_main_loops() debug_cout << "DEBUG:" << m_main_loops << std::endl; } +void UI::slot_active_sensing() +{ + m_active_sensing_timestamp = clock_type::now(); +} diff --git a/UI.h b/UI.h index 077e3a9..3041566 100644 --- a/UI.h +++ b/UI.h @@ -11,7 +11,9 @@ public: void draw(); + // slots void count_main_loops(); + void slot_active_sensing(); private: @@ -20,4 +22,6 @@ private: uint64_t m_main_loops; uint64_t m_main_loops_checkpoint; std::chrono::time_point m_main_loops_timestamp; + + std::chrono::time_point m_active_sensing_timestamp; }; diff --git a/main.cpp b/main.cpp index a58f7cd..7d423f6 100644 --- a/main.cpp +++ b/main.cpp @@ -58,9 +58,12 @@ int main(void) // Main signals boost::signals2::signal signal_count_loops; + // // Signal-Slot Connections: + // midi.signal_note.connect([&](int channel, int note){note_click->receive_note(channel, note);}); note_click->signal_click.connect([&](){pcm.click();}); + midi.signal_active_sensing.connect([&](){ui.slot_active_sensing();}); timer_500ms.elapsed.connect([&](){ui.draw();}); signal_count_loops.connect([&](){ui.count_main_loops();}); -- cgit v1.2.3