From 54281f481fe0549ff80829476674aa994bfff8bd Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 1 Oct 2014 09:01:01 +0200 Subject: Add enum swicth functions. Bump version to 1.0.1 --- configure.ac | 2 +- src/aiomixer.cc | 2 +- src/audioio.cc | 36 ++++++++++++++++++++++++++++++++++++ src/audioio.h | 27 +++++++++++++++++++++++++++ src/mixer.cc | 27 ++++++++++++++++++++++----- 5 files changed, 87 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 933c83a..bbffeba 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([libaudioio], 1.0.0) +AC_INIT([libaudioio], 1.0.1) AC_CONFIG_SRCDIR([src/audioio.cc]) diff --git a/src/aiomixer.cc b/src/aiomixer.cc index 30f721b..14d2e8a 100644 --- a/src/aiomixer.cc +++ b/src/aiomixer.cc @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) break; case 'e': - show_enum = true; + show_enum = !optarg; if(optarg) enum_value = optarg; break; diff --git a/src/audioio.cc b/src/audioio.cc index f3dd449..5da202a 100644 --- a/src/audioio.cc +++ b/src/audioio.cc @@ -219,6 +219,42 @@ int aio_get_capture_mixer_level_range(struct aio_t *h, float *min, float *max) return get_mixer_level_range(h->source_mixer, min, max); } +int aio_get_enum_value(struct aio_t *h, const char *name, char *value, + size_t maxsize) +{ + CHECK_HANDLE(h); + + Mixer *m = h->device->getMixer(name); + if(!m) return NO_SUCH_ENUM; + + if(!m->isEnum()) { + delete m; + return NO_SUCH_ENUM; + } + + std::string e = m->enumValue(); + snprintf(value, maxsize, "%s", e.c_str()); + + return 0; +} + +int aio_set_enum_value(struct aio_t *h, const char *name, const char *value) +{ + CHECK_HANDLE(h); + + Mixer *m = h->device->getMixer(name); + if(!m) return NO_SUCH_ENUM; + + if(!m->isEnum()) { + delete m; + return NO_SUCH_ENUM; + } + + m->setEnumValue(value); + + return 0; +} + int aio_get_samplerate(struct aio_t *h) { CHECK_HANDLE(h); diff --git a/src/audioio.h b/src/audioio.h index 7866751..e78813b 100644 --- a/src/audioio.h +++ b/src/audioio.h @@ -45,6 +45,7 @@ extern "C" { #define MIXER_ERROR -109 #define COULD_NOT_OPEN_DEVICE -110 #define INVALID_MIXER_LEVEL -111 +#define NO_SUCH_ENUM -112 struct aio_t; @@ -163,6 +164,27 @@ int aio_get_capture_mixer_level(struct aio_t *handle, unsigned int channel, int aio_get_capture_mixer_level_range(struct aio_t *handle, float *min, float *max); +/** + * Get value of enum switch on a specific channel. + * @param handle A pointer to the handle to be used. + * @param name The name of the enum swicth. + * @param value The buffer in which the switch enum value will be written. + * @param maxsize The size fo the value buffer. + * @return Returns error code. + */ +int aio_get_enum_value(struct aio_t *handle, const char *name, + char *value, unsigned int maxsize); + +/** + * Set value of enum switch on a specific channel. + * @param handle A pointer to the handle to be used. + * @param name The name of the enum swicth. + * @param value The buffer containing the string value of the enum switch. + * @return Returns error code. + */ +int aio_set_enum_value(struct aio_t *handle, + const char *name, const char *value); + /** * Get actual samplerate. * The samplerate set in ai_init may or may not match a possible samplerate for @@ -176,6 +198,11 @@ int aio_get_capture_mixer_level_range(struct aio_t *handle, */ int aio_get_samplerate(struct aio_t *handle); +/** + * Get the buffer size used by the underlying hardware/software. + * @param handle A pointer to the handle to be used. + * @return The buffer size in bytes. + */ int aio_get_buffer_size(struct aio_t *handle); /** diff --git a/src/mixer.cc b/src/mixer.cc index 5a6efb7..00cf156 100644 --- a/src/mixer.cc +++ b/src/mixer.cc @@ -161,6 +161,22 @@ bool Mixer::isEnum() void Mixer::setEnumValue(std::string value) { if(!isEnum()) return; + + int i, items; + unsigned int idx; + char itemname[40]; + + // TODO: Alaways MONO for enums? + snd_mixer_selem_channel_id_t channel_id = SND_MIXER_SCHN_MONO; + + items = snd_mixer_selem_get_enum_items(elem); + for (i = 0; i < items; i++) { + snd_mixer_selem_get_enum_item_name(elem, i, sizeof(itemname) - 1, itemname); + if(value == itemname) { + snd_mixer_selem_set_enum_item(elem, channel_id, i); + return; + } + } } std::string Mixer::enumValue() @@ -170,9 +186,11 @@ std::string Mixer::enumValue() int i; unsigned int idx; char itemname[40]; - for(i = 0; !snd_mixer_selem_get_enum_item(elem, - (snd_mixer_selem_channel_id_t)i, - &idx); i++) { + + // TODO: Alaways MONO for enums? + snd_mixer_selem_channel_id_t channel_id = SND_MIXER_SCHN_MONO; + + if(!snd_mixer_selem_get_enum_item(elem, channel_id, &idx)) { snd_mixer_selem_get_enum_item_name(elem, idx, sizeof(itemname) - 1, itemname); return itemname; @@ -190,8 +208,7 @@ std::vector Mixer::enumValues() char itemname[40]; items = snd_mixer_selem_get_enum_items(elem); for (i = 0; i < items; i++) { - snd_mixer_selem_get_enum_item_name(elem, (snd_mixer_selem_channel_id_t)i, - sizeof(itemname) - 1, itemname); + snd_mixer_selem_get_enum_item_name(elem, i, sizeof(itemname) - 1, itemname); values.push_back(itemname); } -- cgit v1.2.3