summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-10-08 11:04:15 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-10-08 11:04:15 +0200
commitacc4b909771b4e1a1e5a341db4a10671b2bb13bd (patch)
tree72689e739cc827b98b93f4b1ca81a6c4e68fca0b
parent3e05145199e5c28e6945013251d588d0da087387 (diff)
Fix mixer level functions.HEADv1.0.1master
-rw-r--r--src/audioio.cc4
-rw-r--r--src/mixer.cc101
2 files changed, 19 insertions, 86 deletions
diff --git a/src/audioio.cc b/src/audioio.cc
index 2902b56..15cf71b 100644
--- a/src/audioio.cc
+++ b/src/audioio.cc
@@ -159,6 +159,8 @@ static int set_mixer_level(Mixer *m, unsigned int c, float l)
{
if(!m) return MISSING_MIXER_HANDLE;
+ //if((int)c > m->numberOfChannels() - 1) return NO_SUCH_CHANNEL;
+
if(m->setLevel(c, l)) return NO_SUCH_CHANNEL;
return 0;
}
@@ -179,6 +181,8 @@ static int get_mixer_level(Mixer *m, unsigned int c, float *l)
{
if(!m) return MISSING_MIXER_HANDLE;
+ //if((int)c > m->numberOfChannels() - 1) return NO_SUCH_CHANNEL;
+
float lvl = m->level(c);
if(isinf(lvl)) return INVALID_MIXER_LEVEL;
*l = lvl;
diff --git a/src/mixer.cc b/src/mixer.cc
index 3e8ecba..9450b66 100644
--- a/src/mixer.cc
+++ b/src/mixer.cc
@@ -36,72 +36,6 @@ Mixer::Mixer(snd_mixer_t *handle, snd_mixer_elem_t *elem)
{
this->handle = handle;
this->elem = elem;
-
- /*
- if (snd_mixer_selem_has_capture_volume(elem) ||
- snd_mixer_selem_has_capture_switch(elem)) {
- printf("Capture channels:\n");
- if(snd_mixer_selem_is_capture_mono(elem)) {
- printf(" Mono");
- } else {
- for(int ichn = 0; ichn <= (int)SND_MIXER_SCHN_LAST; ichn++) {
- snd_mixer_selem_channel_id_t chn = (snd_mixer_selem_channel_id_t)ichn;
- if(!snd_mixer_selem_has_capture_channel(elem, chn)) continue;
- printf(" - %s\n", snd_mixer_selem_channel_name(chn));
- }
- }
- }
- */
-
-
-
-
-
-
-
- /*
- snd_mixer_selem_id_t *mixer;
-
- // Open mixer device
- if(snd_mixer_open(&mixhnd, 0) != 0)
- throw MixerInitilisationFailed();
-
- if(snd_mixer_attach_hctl(mixhnd, hctl) != 0)
- throw MixerInitilisationFailed();
-
- if(snd_mixer_selem_register(mixhnd, NULL, NULL) < 0)
- throw MixerInitilisationFailed();
-
- if(snd_mixer_load(mixhnd) < 0)
- throw MixerInitilisationFailed();
-
- // Obtain mixer element
- snd_mixer_selem_id_alloca(&mixer);
- if(mixer == NULL) throw MixerInitilisationFailed();
- snd_mixer_selem_id_set_name(mixer, mixer_interface);
-
- elem = snd_mixer_find_selem(mixhnd, mixer);
- if(elem == NULL) throw MixerInitilisationFailed();
- */
-
- /*
- // Obtain mixer enumeration element "Input Source" and set it to 2 (line).
- snd_mixer_selem_id_set_name(mixer, "Input Source");
-
- snd_mixer_elem_t *iselem = snd_mixer_find_selem(mixhnd, mixer);
- if(iselem == NULL) return;
-
- if(snd_mixer_selem_is_enumerated(iselem)) {
- // Set to line-in
- for(int i = 0; i < 3; i++) {
- char name[16];
- snd_mixer_selem_get_enum_item_name(iselem, i, sizeof(name), name);
- if(std::string(name) == "Line") {
- snd_mixer_selem_set_enum_item(iselem, SND_MIXER_SCHN_MONO, i);
- }
- }
- }
- */
}
Mixer::~Mixer()
@@ -112,31 +46,26 @@ Mixer::~Mixer()
snd_mixer_selem_channel_id_t Mixer::chanId(int idx)
{
int num = 0;
- if(snd_mixer_selem_is_capture_mono(elem)) {
- if(idx == 0) return SND_MIXER_SCHN_MONO;
- } else {
- for(int ichn = 0; ichn <= (int)SND_MIXER_SCHN_LAST; ichn++) {
- snd_mixer_selem_channel_id_t chn = (snd_mixer_selem_channel_id_t)ichn;
- if(!snd_mixer_selem_has_capture_channel(elem, chn) &&
- !snd_mixer_selem_has_playback_channel(elem, chn)) continue;
- if(idx == num) return chn;
- num++;
- }
+
+ for(int ichn = 0; ichn <= (int)SND_MIXER_SCHN_LAST; ichn++) {
+ snd_mixer_selem_channel_id_t chn = (snd_mixer_selem_channel_id_t)ichn;
+ if(!snd_mixer_selem_has_capture_channel(elem, chn) &&
+ !snd_mixer_selem_has_playback_channel(elem, chn)) continue;
+ if(idx == num) return chn;
+ num++;
}
+
return SND_MIXER_SCHN_UNKNOWN;
}
int Mixer::numberOfChannels()
{
int num = 0;
- if(snd_mixer_selem_is_capture_mono(elem)) {
- num = 1;
- } else {
- for(int ichn = 0; ichn <= (int)SND_MIXER_SCHN_LAST; ichn++) {
- snd_mixer_selem_channel_id_t chn = (snd_mixer_selem_channel_id_t)ichn;
- if(!snd_mixer_selem_has_capture_channel(elem, chn)) continue;
- num++;
- }
+ for(int ichn = 0; ichn <= (int)SND_MIXER_SCHN_LAST; ichn++) {
+ snd_mixer_selem_channel_id_t chn = (snd_mixer_selem_channel_id_t)ichn;
+ if(!snd_mixer_selem_has_capture_channel(elem, chn) &&
+ !snd_mixer_selem_has_playback_channel(elem, chn)) continue;
+ num++;
}
return num;
@@ -165,7 +94,7 @@ void Mixer::setEnumValue(std::string value)
int i, items;
char itemname[40];
- // TODO: Alaways MONO for enums?
+ // TODO: Always MONO for enums?
snd_mixer_selem_channel_id_t channel_id = SND_MIXER_SCHN_MONO;
items = snd_mixer_selem_get_enum_items(elem);
@@ -185,7 +114,7 @@ std::string Mixer::enumValue()
unsigned int idx;
char itemname[40];
- // TODO: Alaways MONO for enums?
+ // TODO: Always 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)) {