summaryrefslogtreecommitdiffhomepage
path: root/PCM.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-04 18:27:21 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-04 18:27:21 +0100
commitdbe72ddb8eb215de6d38cd01ed201704ab315a4f (patch)
tree8fda403192090d8560bca9fe5a2e9f9e4e1a7e41 /PCM.cpp
parent2e793141e5434043205763c70d3a597cf2d78eeb (diff)
Compensate phase
Diffstat (limited to 'PCM.cpp')
-rw-r--r--PCM.cpp11
1 files changed, 9 insertions, 2 deletions
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<double> 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<int64_t>(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