summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-02 22:55:29 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-02 22:55:29 +0100
commita1127bca74176a79caa03dd7b3bdd600954c161b (patch)
tree493146e269d4bf46a453feaa0ebbd25b34dd7cce
parent125870779ffbd633b00d051ce96da912f2dd6860 (diff)
Update
-rw-r--r--alsa.cpp22
1 files 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 <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <time.h>
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;
}