summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-31 09:31:14 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-31 09:31:14 +0200
commit8d9ea3103cdc4e00c50a950ba55f3daaebc55a2a (patch)
tree1efd9df6459a4becb05661860e7c4ed3f7958d11
parent64afeb7f84e686c62bb8261c40e54706569d2402 (diff)
make alsamixer more responsive
-rw-r--r--Makefile2
-rw-r--r--src/mixer.c23
2 files changed, 23 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 42b6414..c56ca40 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ all: $(libs) $(libsymlinks) $(pkgconfigs)
%.pc: %.pc.in
m4 -DINCLUDEDIR="$(PREFIX)$(includedir)" -DLIBDIR="$(PREFIX)$(libdir)" $^ > $@
-libasound.so.2.0.0: private override CPPFLAGS += -D_POSIX_SOURCE
+libasound.so.2.0.0: private override CPPFLAGS += -D_DEFAULT_SOURCE
libasound.so.2.0.0: private override CPPFLAGS += -DBYTE_ORDER=__BYTE_ORDER -DLITTLE_ENDIAN=__LITTLE_ENDIAN -DBIG_ENDIAN=__BIG_ENDIAN
libasound.so.2.0.0: private override CFLAGS += -Wno-unused-parameter -Wno-deprecated-declarations
libasound.so.2.0.0: private override LDFLAGS += -Wl,--version-script=libasound.map -Wl,-soname,libasound.so.2
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;
}