]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Functional volume_range_db setting in the general stanza
authorMke Brady <mikebrady@eircom.net>
Wed, 7 Oct 2015 21:33:20 +0000 (22:33 +0100)
committerMke Brady <mikebrady@eircom.net>
Wed, 7 Oct 2015 21:33:20 +0000 (22:33 +0100)
audio_alsa.c
player.c
scripts/shairport-sync.conf
shairport.c

index e050e88a7028c903a62101e6ce9b8733a2922a41..3cfacea1da9b7d112dd43fa428740244f8b52bad 100644 (file)
@@ -234,6 +234,13 @@ static int init(int argc, char **argv) {
       }
       debug(1, "Hardware mixer has dB volume from %f to %f.", (1.0 * alsa_mix_mindb) / 100.0,
             (1.0 * alsa_mix_maxdb) / 100.0);
+      if (config.volume_range_db) {
+        long suggested_alsa_min_db = alsa_mix_maxdb - (long)trunc(config.volume_range_db*100);
+        if (suggested_alsa_min_db > alsa_mix_mindb)
+          alsa_mix_mindb = suggested_alsa_min_db;
+        else
+          inform("The volume_range_db setting, %f is greater than the native range of the mixer %f, so it is ignored.",config.volume_range_db,(alsa_mix_maxdb-alsa_mix_mindb)/100.0);
+      }
     } 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.",alsa_mix_ctrl);
index 557eb52a326ec5b40dc2ec4391ca941bdfb04028..52a93f5f0953b22bb256495ca885ed8747d840a2 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1219,11 +1219,7 @@ void player_volume(double f) {
   // Thus, we ask our vol2attn function for an appropriate dB between -96.3 and 0 dB and translate
   // it back to a number.
 
-  double scaled_volume = vol2attn(f, 0, -9630);
-  double linear_volume = pow(10, scaled_volume / 2000);
-
-  if (f == -144.0)
-    linear_volume = 0.0;
+  double linear_volume = 0.0;
 
   if (config.output->volume) {
     // debug(1,"Set volume to %f.",f);
@@ -1234,12 +1230,23 @@ void player_volume(double f) {
   if (config.output->parameters)
     config.output->parameters(&audio_information);
   else {
+    long mindb = -9630;
+    if (config.volume_range_db) {
+      long suggested_alsa_min_db = -(long)trunc(config.volume_range_db*100);
+      if (suggested_alsa_min_db > mindb)
+        mindb = suggested_alsa_min_db;
+      else
+        inform("The volume_range_db setting, %f is greater than the native range of the mixer %f, so it is ignored.",config.volume_range_db,mindb/100.0);
+    }
+    double scaled_volume = vol2attn(f, 0, mindb);
+    linear_volume = pow(10, scaled_volume / 2000);
     audio_information.airplay_volume = f;
-    audio_information.minimum_volume_dB = -9630;
+    audio_information.minimum_volume_dB = mindb;
     audio_information.maximum_volume_dB = 0;
     audio_information.current_volume_dB = scaled_volume;
     audio_information.has_true_mute = 0;
     audio_information.is_muted = 0;
+    // debug(1,"Minimum software volume set to %d centi-dB",f,mindb);
   }
   audio_information.valid = 1;
   // debug(1,"Software volume set to %f on scale with a %f dB",f,linear_volume);
index 0a9be12aed671683bdf86b0941fbc64e1786ee17..28eca89e9f952f114d863eb4618f22779df67993 100644 (file)
@@ -17,7 +17,7 @@ general =
 //     resync_threshold = 2205; // a synchronisation error greater than this will cause resynchronisation; 0 disables it
 //     log_verbosity = 0; // "0" means no debug verbosity, "3" is most verbose.
 //  ignore_volume_control = "no"; // set this to "yes" if you want the volume to be at 100% no matter what the source's volume control is set to.
-//  volume_range_db = 0; // set this to the range, in dB, you want between the maximum volume and the minimum volume. Zero means use the mixer's native range. Default is 0.
+//  volume_range_db = 60 ; // use this to set the range, in dB, you want between the maximum volume and the minimum volume. Range is 30 to 150 dB. Omit to use mixer's native range.
 };
 
 // How to deal with metadata, including artwork
index a17fa86bbfaa1d4bd83b3f6125651f480661dc7f..91f2fb85df4104acb51fd10befa5cb9b8fca8a14 100644 (file)
@@ -400,9 +400,9 @@ int parse_options(int argc, char **argv) {
       }
 
       /* Get the volume range, in dB, that should be used If not set, it means you just use the range set by the mixer. */
-      if (config_lookup_int(config.cfg, "general.volume_range", &value)) {
-        if ((value < 0) || (value > 200))
-          die("Invalid volume range  \"%sd\". It should be between 0 and 200. Zero means use the mixer's native range",
+      if (config_lookup_int(config.cfg, "general.volume_range_db", &value)) {
+        if ((value < 30) || (value > 150))
+          die("Invalid volume range  \"%sd\". It should be between 30 and 150 dB. Zero means use the mixer's native range",
               value);
         else
           config.volume_range_db = value;