From: Mike Brady Date: Sun, 10 Nov 2019 18:05:59 +0000 (+0000) Subject: Fix D-Bus loudness switch silencing output. Rename LoudnessFiulterActive to Loudness... X-Git-Tag: 3.3.6~6^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f2442f4aa5e478c9fdea826c3f59b4012cd907d;p=thirdparty%2Fshairport-sync.git Fix D-Bus loudness switch silencing output. Rename LoudnessFiulterActive to Loudness. Add Convolution, ConvolutionGain and ConvolutionImpulseResponseFile properties to the D-Bus interface. --- diff --git a/FFTConvolver/convolver.cpp b/FFTConvolver/convolver.cpp index 3f08f0c6..f8f60179 100644 --- a/FFTConvolver/convolver.cpp +++ b/FFTConvolver/convolver.cpp @@ -33,6 +33,9 @@ void convolver_init(const char* filename, int max_length) size_t l = sf_readf_float(file, buffer, size); assert(l == size); + + convolver_l.reset(); // it is possible that init could be called more than once + convolver_r.reset(); // so it could be necessary to remove all previous settings if (info.channels == 1) { convolver_l.init(352, buffer, size); diff --git a/common.h b/common.h index 58772f8b..d3966a56 100644 --- a/common.h +++ b/common.h @@ -230,7 +230,7 @@ typedef struct { #ifdef CONFIG_CONVOLUTION int convolution; - const char *convolution_ir_file; + char *convolution_ir_file; float convolution_gain; int convolution_max_length; #endif diff --git a/dbus-service.c b/dbus-service.c index 76cc0456..7e9d3586 100644 --- a/dbus-service.c +++ b/dbus-service.c @@ -15,6 +15,10 @@ #include "dbus-service.h" +#ifdef CONFIG_CONVOLUTION +#include +#endif + int service_is_running = 0; ShairportSyncDiagnostics *shairportSyncDiagnosticsSkeleton = NULL; @@ -413,14 +417,77 @@ gboolean notify_disable_standby_callback(ShairportSync *skeleton, return TRUE; } -gboolean notify_loudness_filter_active_callback(ShairportSync *skeleton, +#ifdef CONFIG_CONVOLUTION +gboolean notify_convolution_callback(ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + // debug(1, "\"notify_convolution_callback\" called."); + if (shairport_sync_get_convolution(skeleton)) { + debug(1, ">> activating convolution"); + config.convolution = 1; + } else { + debug(1, ">> deactivating convolution"); + config.convolution = 0; + } + return TRUE; +} +#else +gboolean notify_convolution_callback(__attribute__((unused)) ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + warn(">> Convolution support is not built in to this build of Shairport Sync."); + return TRUE; +} +#endif + +#ifdef CONFIG_CONVOLUTION +gboolean notify_convolution_gain_callback(ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + + gdouble th = shairport_sync_get_convolution_gain(skeleton); + if ((th <= 0.0) && (th >= -100.0)) { + debug(1, ">> setting convolution gain to %f.", th); + config.convolution_gain = th; + } else { + debug(1, ">> invalid convolution gain: %f. Ignored.", th); + shairport_sync_set_convolution_gain(skeleton, config.convolution_gain); + } + return TRUE; +} +#else +gboolean notify_convolution_gain_callback(__attribute__((unused)) ShairportSync *skeleton, __attribute__((unused)) gpointer user_data) { - // debug(1, "\"notify_loudness_filter_active_callback\" called."); - if (shairport_sync_get_loudness_filter_active(skeleton)) { - debug(1, ">> activating loudness filter"); + warn(">> Convolution support is not built in to this build of Shairport Sync."); + return TRUE; +} +#endif +#ifdef CONFIG_CONVOLUTION +gboolean notify_convolution_impulse_response_file_callback(ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + char *th = (char *)shairport_sync_get_convolution_impulse_response_file(skeleton); + if (config.convolution_ir_file) + free(config.convolution_ir_file); + config.convolution_ir_file = strdup(th); + debug(1, ">> setting configuration impulse response filter file to \"%s\".", config.convolution_ir_file); + convolver_init(config.convolution_ir_file, config.convolution_max_length); + return TRUE; +} +#else +gboolean notify_convolution_impulse_response_file_callback(__attribute__((unused)) ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + char *th = (char *)shairport_sync_get_convolution_impulse_response_file(skeleton); + return TRUE; +} +#endif + + + +gboolean notify_loudness_callback(ShairportSync *skeleton, + __attribute__((unused)) gpointer user_data) { + // debug(1, "\"notify_loudness_callback\" called."); + if (shairport_sync_get_loudness(skeleton)) { + debug(1, ">> activating loudness"); config.loudness = 1; } else { - debug(1, ">> deactivating loudness filter"); + debug(1, ">> deactivating loudness"); config.loudness = 0; } return TRUE; @@ -687,8 +754,14 @@ static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name G_CALLBACK(notify_volume_control_profile_callback), NULL); g_signal_connect(shairportSyncSkeleton, "notify::disable-standby", G_CALLBACK(notify_disable_standby_callback), NULL); - g_signal_connect(shairportSyncSkeleton, "notify::loudness-filter-active", - G_CALLBACK(notify_loudness_filter_active_callback), NULL); + g_signal_connect(shairportSyncSkeleton, "notify::convolution", + G_CALLBACK(notify_convolution_callback), NULL); + g_signal_connect(shairportSyncSkeleton, "notify::convolution-gain", + G_CALLBACK(notify_convolution_gain_callback), NULL); + g_signal_connect(shairportSyncSkeleton, "notify::convolution-impulse-response-file", + G_CALLBACK(notify_convolution_impulse_response_file_callback), NULL); + g_signal_connect(shairportSyncSkeleton, "notify::loudness", + G_CALLBACK(notify_loudness_callback), NULL); g_signal_connect(shairportSyncSkeleton, "notify::loudness-threshold", G_CALLBACK(notify_loudness_threshold_callback), NULL); g_signal_connect(shairportSyncSkeleton, "notify::drift-tolerance", @@ -824,11 +897,23 @@ static void on_dbus_name_acquired(GDBusConnection *connection, const gchar *name } if (config.loudness == 0) { - shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE); + shairport_sync_set_loudness(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE); } else { - shairport_sync_set_loudness_filter_active(SHAIRPORT_SYNC(shairportSyncSkeleton), TRUE); + shairport_sync_set_loudness(SHAIRPORT_SYNC(shairportSyncSkeleton), TRUE); } +#ifdef CONFIG_CONVOLUTION + if (config.convolution == 0) { + shairport_sync_set_convolution(SHAIRPORT_SYNC(shairportSyncSkeleton), FALSE); + } else { + shairport_sync_set_convolution(SHAIRPORT_SYNC(shairportSyncSkeleton), TRUE); + } + if (config.convolution_ir_file) + shairport_sync_set_convolution_impulse_response_file(SHAIRPORT_SYNC(shairportSyncSkeleton), config.convolution_ir_file); + else + shairport_sync_set_convolution_impulse_response_file(SHAIRPORT_SYNC(shairportSyncSkeleton), NULL); +#endif + shairport_sync_set_version(SHAIRPORT_SYNC(shairportSyncSkeleton), PACKAGE_VERSION); char *vs = get_version_string(); shairport_sync_set_version_string(SHAIRPORT_SYNC(shairportSyncSkeleton), vs); diff --git a/documents/sample dbus commands b/documents/sample dbus commands index 2e88003d..e6251929 100644 --- a/documents/sample dbus commands +++ b/documents/sample dbus commands @@ -31,3 +31,22 @@ dbus-send --system --print-reply --type=method_call --dest=org.gnome.ShairportSy dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:DriftTolerance # Set Drift Tolerance to 1 millisecond dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:org.gnome.ShairportSync string:DriftTolerance variant:double:0.001 + + +# Enable Loudness Filter + + +# Is Convolution enabled: +dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:Convolution + +# Enable Convolution +dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:org.gnome.ShairportSync string:Convolution variant:boolean:true + +# Get Convolution Gain: +dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:ConvolutionGain + +# Set Convolution Gain -- the gain applied before convolution is applied -- to -10.0 dB +dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Set string:org.gnome.ShairportSync string:ConvolutionGain variant:double:-10 + +# Get Convolution Impulse Response File: +dbus-send --print-reply --system --dest=org.gnome.ShairportSync /org/gnome/ShairportSync org.freedesktop.DBus.Properties.Get string:org.gnome.ShairportSync string:ConvolutionImpulseResponseFile diff --git a/loudness.c b/loudness.c index b4dbc3c3..79862ece 100644 --- a/loudness.c +++ b/loudness.c @@ -44,7 +44,7 @@ void loudness_set_volume(float volume) { if (gain < 0) gain = 0; - inform("Volume: %.1f dB - Loudness gain @10Hz: %.1f dB", volume, gain); + debug(2, "Volume: %.1f dB - Loudness gain @10Hz: %.1f dB", volume, gain); _loudness_set_volume(&loudness_l, volume); _loudness_set_volume(&loudness_r, volume); } diff --git a/org.gnome.ShairportSync.xml b/org.gnome.ShairportSync.xml index e4a7d1e6..15317faa 100644 --- a/org.gnome.ShairportSync.xml +++ b/org.gnome.ShairportSync.xml @@ -5,8 +5,11 @@ - + + + + diff --git a/player.c b/player.c index e98331f4..6f7f6415 100644 --- a/player.c +++ b/player.c @@ -2902,8 +2902,8 @@ void player_volume_without_notification(double airplay_volume, rtsp_conn_info *c conn->fix_volume = temp_fix_volume; - if (config.loudness) - loudness_set_volume(software_attenuation / 100); + // if (config.loudness) + loudness_set_volume(software_attenuation / 100); } if (config.logOutputLevel) { diff --git a/shairport.c b/shairport.c index 4216d5bb..9c519122 100644 --- a/shairport.c +++ b/shairport.c @@ -962,12 +962,12 @@ int parse_options(int argc, char **argv) { } if (config_lookup_string(config.cfg, "dsp.convolution_ir_file", &str)) { - config.convolution_ir_file = str; + config.convolution_ir_file = strdup(str); convolver_init(config.convolution_ir_file, config.convolution_max_length); } if (config.convolution && config.convolution_ir_file == NULL) { - die("Convolution enabled but no convolution_ir_file provided"); + warn("Convolution enabled but no convolution_ir_file provided"); } #endif if (config_lookup_string(config.cfg, "dsp.loudness", &str)) { @@ -1339,6 +1339,9 @@ Actually, there is no stop_mpris_service() function. if (config.service_name) free(config.service_name); + + if (config.convolution_ir_file) + free(config.convolution_ir_file); if (config.regtype) free(config.regtype);