From a1127bca74176a79caa03dd7b3bdd600954c161b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 2 Jan 2025 22:55:29 +0100 Subject: Update --- alsa.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/alsa.cpp b/alsa.cpp index d9d7cf9..2eb5662 100644 --- a/alsa.cpp +++ b/alsa.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace std::string_literals; @@ -24,6 +25,11 @@ int16_t buffer[nframes]; const unsigned int f_sample = 44100; const double pi = std::acos(-1); +double diff_timespec(const struct timespec *time1, const struct timespec *time0) { + return (time1->tv_sec - time0->tv_sec) + + (time1->tv_nsec - time0->tv_nsec) / 1000000000.0; +} + class ClickStream { public: @@ -84,7 +90,7 @@ public: printf("Playback open error: %s\n", snd_strerror(err)); exit(EXIT_FAILURE); } - + npfd = snd_pcm_poll_descriptors_count(handle); if (npfd < 0) { throw std::runtime_error("snd_pcm_poll_descriptors_count() failed"); @@ -214,7 +220,7 @@ public: snd_seq_port_subscribe_set_sender(subs, &sender); snd_seq_port_subscribe_set_dest(subs, &dest); snd_seq_port_subscribe_set_queue(subs, 1); - //snd_seq_port_subscribe_set_time_update(subs, 1); + snd_seq_port_subscribe_set_time_update(subs, 1); snd_seq_port_subscribe_set_time_real(subs, 1); // TODO: fix timestamp (currently always 0) if (0 > snd_seq_subscribe_port(seq_handle, subs)) @@ -269,6 +275,18 @@ public: { std::cerr << "snd_seq_event_input(): -EAGAIN" << std::endl; } + + // TODO: fix timestamp to be set automatically + struct timespec t; + if (TIME_UTC != timespec_get(&t, TIME_UTC)) + { + std::cerr << "Error: timespec_get()" << std::endl; + } + else + { + ev->time.time.tv_sec = t.tv_sec; + ev->time.time.tv_nsec = t.tv_nsec; + } return ev; } -- cgit v1.2.3