From 2915e6672c88b0887ee028eb6d6ea14b1a364518 Mon Sep 17 00:00:00 2001 From: Jakub Nabaglo Date: Tue, 26 Sep 2017 17:24:55 +1000 Subject: [PATCH 1/2] Attempt to fix hardware volume bug on devices without a linear scale --- audio_alsa.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index 3288b85d..8a3c8b65 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -43,11 +43,14 @@ static void play(short buf[], int samples); static void stop(void); static void flush(void); int delay(long *the_delay); -static void volume(double vol); -void do_volume(double vol); void do_mute(int request); +static void volume(double vol); +void do_volume(double vol); + static void linear_volume(double vol); +void do_linear_volume(double vol); + static void parameters(audio_parameters *info); static void mute(int do_mute); static double set_volume; @@ -376,8 +379,7 @@ static int init(int argc, char **argv) { } else { // use the linear scale and do the db conversion ourselves debug(1, "note: the hardware mixer specified -- \"%s\" -- does not have " - "a dB volume scale, so it can't be used. Trying software " - "volume control.", + "a dB volume scale.", alsa_mix_ctrl); if (snd_ctl_open(&ctl, alsa_mix_dev, 0) < 0) { @@ -395,10 +397,14 @@ static int init(int argc, char **argv) { debug(1, "Volume control \"%s\" has dB volume from %f to %f.", alsa_mix_ctrl, (1.0 * alsa_mix_mindb) / 100.0, (1.0 * alsa_mix_maxdb) / 100.0); has_softvol = 1; + audio_alsa.volume = &volume; // insert the volume function now we know it can do dB stuff + audio_alsa.parameters = ¶meters; // likewise the parameters stuff } else { debug(1, "Cannot get the dB range from the volume control \"%s\"", alsa_mix_ctrl); } + + /* debug(1, "Min and max volumes are %d and %d.",alsa_mix_minv,alsa_mix_maxv); From 90f779dc74b6bd87b392d912665e1a2b677c7c16 Mon Sep 17 00:00:00 2001 From: Jakub Nabaglo Date: Tue, 26 Sep 2017 21:37:01 +1000 Subject: [PATCH 2/2] Minor cleanup --- audio_alsa.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index 8a3c8b65..6326d9cb 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -48,9 +48,6 @@ void do_mute(int request); static void volume(double vol); void do_volume(double vol); -static void linear_volume(double vol); -void do_linear_volume(double vol); - static void parameters(audio_parameters *info); static void mute(int do_mute); static double set_volume; @@ -397,7 +394,7 @@ static int init(int argc, char **argv) { debug(1, "Volume control \"%s\" has dB volume from %f to %f.", alsa_mix_ctrl, (1.0 * alsa_mix_mindb) / 100.0, (1.0 * alsa_mix_maxdb) / 100.0); has_softvol = 1; - audio_alsa.volume = &volume; // insert the volume function now we know it can do dB stuff + audio_alsa.volume = &volume; audio_alsa.parameters = ¶meters; // likewise the parameters stuff } else { debug(1, "Cannot get the dB range from the volume control \"%s\"", alsa_mix_ctrl); @@ -941,7 +938,7 @@ void do_volume(double vol) { // caller is assumed to have the alsa_mutex when us snd_ctl_elem_value_t *value; long raw; - if (snd_ctl_convert_from_dB(ctl, elem_id, (long)vol, &raw, 0) < 0) + if (snd_ctl_convert_from_dB(ctl, elem_id, vol, &raw, 0) < 0) debug(1, "Failed converting dB gain to raw volume value for the " "software volume control.");