summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mixer.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/mixer.c b/src/mixer.c
index 3213995..4738012 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -2,6 +2,7 @@
#include <sndio.h>
#include <stdbool.h>
#include <stdio.h>
+#include <time.h>
#include "util/sysex.h"
#include "util/util.h"
@@ -15,6 +16,7 @@ struct _snd_mixer_elem {
struct _snd_mixer {
struct mio_hdl *hdl;
snd_mixer_elem_t *controls;
+ uint64_t last_pollin_time;
};
#define MIXER_MAX_CHANNELS 16
@@ -219,13 +221,31 @@ snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int
return mio_pollfd(mixer->hdl, pfds, POLLOUT | POLLIN);
}
+static uint64_t
+get_time_ns(void)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (uint64_t)ts.tv_sec * (uint64_t)1e9 + (uint64_t)ts.tv_nsec;
+}
+
int
snd_mixer_poll_descriptors_revents(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
{
if (!revents || nfds > (unsigned int)mio_nfds(mixer->hdl))
return -1;
- *revents = mio_revents(mixer->hdl, pfds) | POLLIN;
+ *revents = mio_revents(mixer->hdl, pfds);
+
+ const uint64_t time = get_time_ns();
+ if (!(*revents & POLLIN)) {
+ if (((time - mixer->last_pollin_time) / 1e6) > 20)
+ *revents |= POLLIN;
+ }
+
+ if (*revents & POLLIN)
+ mixer->last_pollin_time = time;
+
return 0;
}
@@ -291,6 +311,7 @@ int
snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir)
{
setvol(elem->mixer, elem->index, value + 0x7f);
+ elem->vol = value + 0x7f;
return 0;
}