diff options
Diffstat (limited to 'alsa.cpp')
-rw-r--r-- | alsa.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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; } |