From b82952dc13b86490749cf6b8d1b94759e43beaa7 Mon Sep 17 00:00:00 2001 From: Mke Brady Date: Sat, 3 Oct 2015 20:26:06 +0100 Subject: [PATCH] Remove some scaffolding, turn off some debug messages --- audio_alsa.c | 54 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index 309a8314..7a3fe45e 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -184,6 +184,8 @@ static int init(int argc, char **argv) { if (optind < argc) die("Invalid audio argument: %s", argv[optind]); + + debug(1,"Output device name is \"%s\".",alsa_out_dev); if (!hardware_mixer) return 0; @@ -192,13 +194,14 @@ static int init(int argc, char **argv) { alsa_mix_dev = alsa_out_dev; int ret = 0; - + snd_mixer_selem_id_alloca(&alsa_mix_sid); snd_mixer_selem_id_set_index(alsa_mix_sid, alsa_mix_index); snd_mixer_selem_id_set_name(alsa_mix_sid, alsa_mix_ctrl); if ((snd_mixer_open(&alsa_mix_handle, 0)) < 0) die("Failed to open mixer"); + debug(1,"Mixer device name is \"%s\".",alsa_mix_dev); if ((snd_mixer_attach(alsa_mix_handle, alsa_mix_dev)) < 0) die("Failed to attach mixer"); if ((snd_mixer_selem_register(alsa_mix_handle, NULL, NULL)) < 0) @@ -207,44 +210,24 @@ static int init(int argc, char **argv) { ret = snd_mixer_load(alsa_mix_handle); if (ret < 0) die("Failed to load mixer element"); - alsa_mix_elem = snd_mixer_find_selem(alsa_mix_handle, alsa_mix_sid); + + debug(1,"Mixer Control name is \"%s\".",alsa_mix_ctrl); + + alsa_mix_elem = snd_mixer_find_selem(alsa_mix_handle, alsa_mix_sid); if (!alsa_mix_elem) die("Failed to find mixer element"); - // Check that the output device has two playback channels - snd_mixer_selem_channel_id_t chn; - - - if (snd_mixer_selem_has_playback_volume(alsa_mix_elem) || - snd_mixer_selem_has_playback_switch(alsa_mix_elem)) { - if (snd_mixer_selem_is_playback_mono(alsa_mix_elem)) { - debug(1,"Mono Capable Output Device Only"); - } else { - for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++){ - if (snd_mixer_selem_has_playback_channel(alsa_mix_elem, chn)) { - debug(1,"Playback channel \"%s\" discovered", snd_mixer_selem_channel_name(chn)); - // see if it's got a dB range - int64_t cmin,cmax; - if (snd_mixer_selem_get_playback_dB_range(alsa_mix_elem,&cmin,&cmax)==0) - debug(1,"Range in dB is from %ld to %ld",cmin,cmax); - else - debug(1,"Can't get dB volume range"); - } - } - } - } - - + if (snd_mixer_selem_get_playback_volume_range(alsa_mix_elem, &alsa_mix_minv, &alsa_mix_maxv) < 0) debug(1, "Can't read mixer's [linear] min and max volumes."); else { if (snd_mixer_selem_get_playback_dB_range (alsa_mix_elem, &alsa_mix_mindb, &alsa_mix_maxdb) == 0) { -// if ((snd_mixer_selem_ask_playback_vol_dB(alsa_mix_elem, alsa_mix_minv, &alsa_mix_mindb) == 0) && -// (snd_mixer_selem_ask_playback_vol_dB(alsa_mix_elem, alsa_mix_maxv, &alsa_mix_maxdb) == 0)) { + audio_alsa.volume = &volume; // insert the volume function now we know it can do dB stuff audio_alsa.parameters = ¶meters; // likewise the parameters stuff - if (alsa_mix_mindb == -9999999) { - // trying to say that the lowest vol is mute, maybe? Raspberry Pi does this + if (alsa_mix_mindb == SND_CTL_TLV_DB_GAIN_MUTE) { + // Raspberry Pi does this + debug(1, "Lowest dB value is a mute."); if (snd_mixer_selem_ask_playback_vol_dB(alsa_mix_elem, alsa_mix_minv + 1, &alsa_mix_mindb) == 0) debug(1, "Can't get dB value corresponding to a \"volume\" of 1."); @@ -253,7 +236,7 @@ static int init(int argc, char **argv) { (1.0 * alsa_mix_maxdb) / 100.0); } else { // use the linear scale and do the db conversion ourselves - inform("note: the hardware mixer specified -- \"%s\" -- does not have dB volume, so it can not be used for volume control.",alsa_mix_ctrl); + debug(1, "note: the hardware mixer specified -- \"%s\" -- does not have dB volume -- using the [hopefully] linear settings.",alsa_mix_ctrl); debug(1, "Min and max volumes are %d and %d.",alsa_mix_minv,alsa_mix_maxv); alsa_mix_maxdb = 0; if ((alsa_mix_maxv!=0) && (alsa_mix_minv!=0)) @@ -261,6 +244,7 @@ static int init(int argc, char **argv) { else if (alsa_mix_maxv!=0) alsa_mix_mindb = -20*100*log10(alsa_mix_maxv*1.0); audio_alsa.volume = &linear_volume; // insert the linear volume function + audio_alsa.parameters = ¶meters; // likewise the parameters stuff debug(1,"Max and min dB calculated are %d and %d.",alsa_mix_maxdb,alsa_mix_mindb); } } @@ -425,7 +409,6 @@ static void parameters(audio_parameters *info) { } static void volume(double vol) { - debug(1,"Setting volume in dB."); set_volume = vol; double vol_setting = vol2attn(vol, alsa_mix_maxdb, alsa_mix_mindb); // debug(1,"Setting volume db to %f, for volume input of %f.",vol_setting/100,vol); @@ -436,14 +419,13 @@ static void volume(double vol) { } static void linear_volume(double vol) { - debug(1,"Setting linear volume for %f.",vol); set_volume = vol; double vol_setting = vol2attn(vol, 0, alsa_mix_mindb)/2000; - debug(1,"Adjusted volume is %f.",vol_setting); + // debug(1,"Adjusted volume is %f.",vol_setting); double linear_volume = pow(10, vol_setting); - debug(1,"Linear volume is %f.",linear_volume); + // debug(1,"Linear volume is %f.",linear_volume); long int_vol = alsa_mix_minv + (alsa_mix_maxv - alsa_mix_minv) * linear_volume; - debug(1,"Setting volume to %ld, for volume input of %f.",int_vol,vol); + // debug(1,"Setting volume to %ld, for volume input of %f.",int_vol,vol); if (snd_mixer_selem_set_playback_volume_all(alsa_mix_elem, int_vol) != 0) die("Failed to set playback volume"); if (has_mute)