diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-03 23:43:56 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-03 23:43:56 +0100 |
commit | 0399f008b22482c46d37fa15e6be205b85681011 (patch) | |
tree | 003060dce02839a145cf2e798d1a14e352faf212 | |
parent | 22cdfccb11679d6ae241653c9cb92c32f4fc1fde (diff) |
Buffer position compensation for PCM, added active sensing detection
-rw-r--r-- | PCM.h | 2 | ||||
-rw-r--r-- | README.md | 21 | ||||
-rw-r--r-- | UI.cpp | 15 | ||||
-rw-r--r-- | UI.h | 4 | ||||
-rw-r--r-- | main.cpp | 3 |
5 files changed, 40 insertions, 5 deletions
@@ -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 @@ -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 +} @@ -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<int> 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(); +} @@ -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<clock_type> m_main_loops_timestamp; + + std::chrono::time_point<clock_type> m_active_sensing_timestamp; }; @@ -58,9 +58,12 @@ int main(void) // Main signals boost::signals2::signal<void()> 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();}); |