]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix D-Bus loudness switch silencing output. Rename LoudnessFiulterActive to Loudness...
authorMike Brady <mikebrady@eircom.net>
Sun, 10 Nov 2019 18:05:59 +0000 (18:05 +0000)
committerMike Brady <mikebrady@eircom.net>
Sun, 10 Nov 2019 18:05:59 +0000 (18:05 +0000)
FFTConvolver/convolver.cpp
common.h
dbus-service.c
documents/sample dbus commands
loudness.c
org.gnome.ShairportSync.xml
player.c
shairport.c

index 3f08f0c6d2e288a12394c404002b57c38cb46a71..f8f6017937f4a7630d0fa2bc3667bfdf3eb37846 100644 (file)
@@ -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);
index 58772f8b8bce70d700162137c55dff5dc08788a5..d3966a562a84c6ff2952121448342841d703e315 100644 (file)
--- 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
index 76cc045647eb6b0c72182ac468943f2a8687f5bc..7e9d3586e989b1091fa426b6bd078e2abd9bf896 100644 (file)
 
 #include "dbus-service.h"
 
+#ifdef CONFIG_CONVOLUTION
+#include <FFTConvolver/convolver.h>
+#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);
index 2e88003d5d378b3d1688537306c6ada525428dfa..e6251929ceb8417947178c13c7d715b0b6d7e443 100644 (file)
@@ -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
index b4dbc3c3a2425eab81cd4cf3757c78f55e63748d..79862ecebae2662ac44e6300b87eff55253b87fb 100644 (file)
@@ -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);
 }
index e4a7d1e6f0e197655e99f5893b1bc5cabd5a704f..15317faa02ff663435fa91ce59ca425f45fe2607 100644 (file)
@@ -5,8 +5,11 @@
     <property name='Active' type='b' access='read'/>
     <property name="DisableStandby" type="b" access="readwrite" />
     <property name="DisableStandbyMode" type="s" access="readwrite" />
-    <property name="LoudnessFilterActive" type="b" access="readwrite" />
+    <property name="Loudness" type="b" access="readwrite" />
     <property name="LoudnessThreshold" type="d" access="readwrite" />
+    <property name="Convolution" type="b" access="readwrite" />
+    <property name="ConvolutionGain" type="d" access="readwrite" />
+    <property name="ConvolutionImpulseResponseFile" type="s" access="readwrite" />
     <property name="DriftTolerance" type="d" access="readwrite" />
     <method name="RemoteCommand">
       <arg name="command" type="s" direction="in" />
index e98331f4d8ebf3d458d5aa656ebd0fcf90135bea..6f7f64151e8c8151a8ab0d92dc86153157b7f0e5 100644 (file)
--- 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) {
index 4216d5bbedfbb5daab49f8408d171497926acede..9c519122585697cb7689a97c817c4ed6abc8504e 100644 (file)
@@ -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);