From: Mike Brady Date: Mon, 11 Dec 2017 16:32:37 +0000 (+0000) Subject: More comprhensive saving and restoring of hardware and software level when a session... X-Git-Tag: 3.1.5~3^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea46a09aeacdc8d6d52e63713fb02ecacdb63589;p=thirdparty%2Fshairport-sync.git More comprhensive saving and restoring of hardware and software level when a session is stopped and started. Does hardware as well as software. --- diff --git a/common.h b/common.h index 1853c447..24f37676 100644 --- 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 diff --git a/player.c b/player.c index 1cd14f14..8530f444 100644 --- 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) { diff --git a/shairport.c b/shairport.c index 71d1bc69..effc4cca 100644 --- a/shairport.c +++ b/shairport.c @@ -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;