]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
More comprhensive saving and restoring of hardware and software level when a session...
authorMike Brady <mikebrady@eircom.net>
Mon, 11 Dec 2017 16:32:37 +0000 (16:32 +0000)
committerMike Brady <mikebrady@eircom.net>
Mon, 11 Dec 2017 16:32:37 +0000 (16:32 +0000)
common.h
player.c
shairport.c

index 1853c4470ac12c87ed909fc4dc5695d93d87cae0..24f37676dcb95901e739599e608ad96f03f7695e 100644 (file)
--- a/common.h
+++ b/common.h
@@ -81,7 +81,7 @@ enum sps_format_t {
 
 typedef struct {
   config_t *cfg;
-  int fix_volume;
+  double airplay_volume; // stored here for reloading when necessary
   char *appName; // normally the app is called shairport-syn, but it may be symlinked
   char *password;
   char *service_name; // the name for the shairport service, e.g. "Shairport Sync Version %v running
index 1cd14f1462d73faca18566d4c83f8a962d2d99af..8530f444615c1ede90a18900d665031c5136ccb5 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1227,16 +1227,16 @@ static int stuff_buffer_basic_32(int32_t *inptr, int length, enum sps_format_t l
 
   pthread_mutex_lock(&conn->vol_mutex);
   for (i = 0; i < stuffsamp; i++) { // the whole frame, if no stuffing
-    process_sample(*inptr++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
-    process_sample(*inptr++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
+    process_sample(*inptr++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
+    process_sample(*inptr++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
   };
   if (tstuff) {
     if (tstuff == 1) {
       // debug(3, "+++++++++");
       // interpolate one sample
-      process_sample(mean_32(inptr[-2], inptr[0]), &l_outptr, l_output_format, config.fix_volume,
+      process_sample(mean_32(inptr[-2], inptr[0]), &l_outptr, l_output_format, conn->fix_volume,
                      dither, conn);
-      process_sample(mean_32(inptr[-1], inptr[1]), &l_outptr, l_output_format, config.fix_volume,
+      process_sample(mean_32(inptr[-1], inptr[1]), &l_outptr, l_output_format, conn->fix_volume,
                      dither, conn);
     } else if (stuff == -1) {
       // debug(3, "---------");
@@ -1251,8 +1251,8 @@ static int stuff_buffer_basic_32(int32_t *inptr, int length, enum sps_format_t l
       remainder = remainder + tstuff; // don't run over the correct end of the output buffer
 
     for (i = stuffsamp; i < remainder; i++) {
-      process_sample(*inptr++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
-      process_sample(*inptr++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
+      process_sample(*inptr++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
+      process_sample(*inptr++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
     }
   }
   pthread_mutex_unlock(&conn->vol_mutex);
@@ -1329,8 +1329,8 @@ static int stuff_buffer_soxr_32(int32_t *inptr, int32_t *scratchBuffer, int leng
     ip = scratchBuffer;
     char *l_outptr = outptr;
     for (i = 0; i < length + tstuff; i++) {
-      process_sample(*ip++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
-      process_sample(*ip++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
+      process_sample(*ip++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
+      process_sample(*ip++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
     };
 
   } else { // the whole frame, if no stuffing
@@ -1341,8 +1341,8 @@ static int stuff_buffer_soxr_32(int32_t *inptr, int32_t *scratchBuffer, int leng
     int i;
 
     for (i = 0; i < length; i++) {
-      process_sample(*ip++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
-      process_sample(*ip++, &l_outptr, l_output_format, config.fix_volume, dither, conn);
+      process_sample(*ip++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
+      process_sample(*ip++, &l_outptr, l_output_format, conn->fix_volume, dither, conn);
     };
   }
   conn->amountStuffed = tstuff;
@@ -1535,7 +1535,7 @@ static void *player_thread_func(void *arg) {
     debug(1, "Dithering will be enabled because the input bit depth is greater than the output bit "
              "depth");
   }
-  if (config.fix_volume != 0x10000) {
+  if (conn->fix_volume != 0x10000) {
     debug(1, "Dithering will be enabled because the output volume is being altered in software");
   }
 
@@ -1623,6 +1623,11 @@ static void *player_thread_func(void *arg) {
     }
   }
 
+       // set the default volume to whaterver it was before, as stored in the config airplay_volume
+       debug(1,"Set initial volume to %f.",config.airplay_volume);
+       
+       player_volume(config.airplay_volume,conn);
+       
   uint64_t tens_of_seconds = 0;
   while (!conn->player_thread_please_stop) {
     abuf_t *inframe = buffer_get_frame(conn);
@@ -1649,7 +1654,7 @@ static void *player_thread_func(void *arg) {
           config.output->play(silence, conn->max_frames_per_packet * conn->output_sample_ratio);
         } else {
           int enable_dither = 0;
-          if ((config.fix_volume != 0x10000) || (conn->input_bit_depth > output_bit_depth) ||
+          if ((conn->fix_volume != 0x10000) || (conn->input_bit_depth > output_bit_depth) ||
               (config.playback_mode == ST_mono))
             enable_dither = 1;
 
@@ -1951,7 +1956,7 @@ static void *player_thread_func(void *arg) {
                   // Apply volume and loudness
                   // Volume must be applied here because the loudness filter will increase the
                   // signal level and it would saturate the int32_t otherwise
-                  float gain = config.fix_volume / 65536.0f;
+                  float gain = conn->fix_volume / 65536.0f;
                   float gain_db = 20 * log10(gain);
                   // debug(1, "Applying soft volume dB: %f k: %f", gain_db, gain);
 
@@ -2440,7 +2445,7 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c
   // %f",software_attenuation,temp_fix_volume,airplay_volume);
 
   pthread_mutex_lock(&conn->vol_mutex);
-  config.fix_volume = temp_fix_volume;
+  conn->fix_volume = temp_fix_volume;
   pthread_mutex_unlock(&conn->vol_mutex);
 
   if (config.loudness)
@@ -2462,6 +2467,9 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c
     send_ssnc_metadata('pvol', dv, strlen(dv), 1);
   }
 #endif
+
+       // here, store the volume for possible use in the future
+       config.airplay_volume = airplay_volume;
 }
 
 void player_volume(double airplay_volume, rtsp_conn_info *conn) {
index 71d1bc69a3bc68133be03a4a2672625e5b365953..effc4cca91cc14f6325ed83c8f4cf37b71986574 100644 (file)
@@ -440,8 +440,8 @@ int parse_options(int argc, char **argv) {
   config.resyncthreshold = 1.0 * fResyncthreshold / 44100;
   config.tolerance = 1.0 * fTolerance / 44100;
   config.audio_backend_silent_lead_in_time = -1.0; // flag to indicate it has not been set
-  config.fix_volume = 0x01000; // if no volume is ever set and it's a software volume control, default to 1/16 max, i.e. approx 24 dB down
-
+  config.airplay_volume = -18.0; // if no volume is ever set, default to initial default value if nothing else comes in first.
+  
   config_setting_t *setting;
   const char *str = 0;
   int value = 0;