diff options
author | Simon Wilson <ksattic@gmail.com> | 2012-11-09 13:52:03 -0800 |
---|---|---|
committer | Simon Wilson <ksattic@gmail.com> | 2012-11-09 13:52:03 -0800 |
commit | 9bb806603cb687e54b4376f00e679f17c6be0049 (patch) | |
tree | 33ff25bd90b378c03ea94e45949cf7b0731e641e | |
parent | bad2b79b02708be69b65faae88f5be331bdf49b6 (diff) | |
parent | 1d934cfd511ef34cc687416812382f4657b936ab (diff) |
Merge pull request #15 from quantumdream/master
Add mixer_ctl_{get,set}_data()
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | include/tinyalsa/asoundlib.h | 3 | ||||
-rw-r--r-- | mixer.c | 37 |
3 files changed, 47 insertions, 6 deletions
@@ -2,24 +2,25 @@ CFLAGS = -c -fPIC INC = include OBJECTS = mixer.o pcm.o LIB = libtinyalsa.so +CROSS_COMPILE = all: $(LIB) tinyplay tinycap tinymix tinyplay: $(LIB) tinyplay.o - gcc tinyplay.o -L. -ltinyalsa -o tinyplay + $(CROSS_COMPILE)gcc tinyplay.o -L. -ltinyalsa -o tinyplay tinycap: $(LIB) tinycap.o - gcc tinycap.o -L. -ltinyalsa -o tinycap + $(CROSS_COMPILE)gcc tinycap.o -L. -ltinyalsa -o tinycap tinymix: $(LIB) tinymix.o - gcc tinymix.o -L. -ltinyalsa -o tinymix + $(CROSS_COMPILE)gcc tinymix.o -L. -ltinyalsa -o tinymix $(LIB): $(OBJECTS) - gcc -shared $(OBJECTS) -o $(LIB) + $(CROSS_COMPILE)gcc -shared $(OBJECTS) -o $(LIB) .c.o: - gcc $(CFLAGS) $< -I$(INC) - + $(CROSS_COMPILE)gcc $(CFLAGS) $< -I$(INC) + clean: -rm $(LIB) $(OBJECTS) tinyplay.o tinyplay tinycap.o tinycap \ tinymix.o tinymix diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h index 5894257..bdb4b7a 100644 --- a/include/tinyalsa/asoundlib.h +++ b/include/tinyalsa/asoundlib.h @@ -30,6 +30,7 @@ #define ASOUNDLIB_H #include <sys/time.h> +#include <stddef.h> #if defined(__cplusplus) extern "C" { @@ -193,7 +194,9 @@ int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id); int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent); int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id); +int mixer_ctl_get_bytes(struct mixer_ctl *ctl, void *data, size_t len); int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value); +int mixer_ctl_set_bytes(struct mixer_ctl *ctl, const void *data, size_t len); int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string); /* Determe range of integer mixer controls */ @@ -317,6 +317,27 @@ int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id) return 0; } +int mixer_ctl_get_bytes(struct mixer_ctl *ctl, void *data, size_t len) +{ + struct snd_ctl_elem_value ev; + int ret; + + if (!ctl || (len > ctl->info->count) || !len || !data || + (ctl->info->type != SNDRV_CTL_ELEM_TYPE_BYTES)) + return -EINVAL; + + memset(&ev, 0, sizeof(ev)); + ev.id.numid = ctl->info->id.numid; + + ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev); + if (ret < 0) + return ret; + + memcpy(data, ev.value.bytes.data, len); + + return 0; +} + int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value) { struct snd_ctl_elem_value ev; @@ -351,6 +372,22 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value) return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev); } +int mixer_ctl_set_bytes(struct mixer_ctl *ctl, const void *data, size_t len) +{ + struct snd_ctl_elem_value ev; + + if (!ctl || (len > ctl->info->count) || !len || !data || + (ctl->info->type != SNDRV_CTL_ELEM_TYPE_BYTES)) + return -EINVAL; + + memset(&ev, 0, sizeof(ev)); + ev.id.numid = ctl->info->id.numid; + + memcpy(ev.value.bytes.data, data, len); + + return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev); +} + int mixer_ctl_get_range_min(struct mixer_ctl *ctl) { if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER)) |