From dbe72ddb8eb215de6d38cd01ed201704ab315a4f Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 4 Jan 2025 18:27:21 +0100 Subject: Compensate phase --- PCM.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'PCM.cpp') diff --git a/PCM.cpp b/PCM.cpp index 218ba59..8c0e01f 100644 --- a/PCM.cpp +++ b/PCM.cpp @@ -59,13 +59,20 @@ PCM::~PCM() free(pfd); } -void PCM::click(int64_t offset_us) +// offset > 0: play earlier +// offset < 0: play later +void PCM::click(std::chrono::duration offset) { snd_pcm_sframes_t delay; if (0 > snd_pcm_delay(handle, &delay)) { } - m_phase = - click_latency_frames + delay + offset_us; + int64_t offset_frames{static_cast(offset.count() * f_sample)}; + m_phase = - click_latency_frames + delay + offset_frames; + + if (m_phase > 0) { + log_cout << fmt::format("phase = {}", m_phase) << std::endl; + } } // generate 1 buffer size -- cgit v1.2.3