aboutsummaryrefslogtreecommitdiff
path: root/src/pulse-manager.c
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-04-22 17:58:50 +0100
committerConor Curran <conor.curran@canonical.com>2010-04-22 17:58:50 +0100
commit5b74cf4b47b34fc53b89cc98fab413c603e2c80a (patch)
tree2bc3388c9db597c40173da394e48724103dc8d2d /src/pulse-manager.c
parent132bf8d107161102b63bf254056624bc00b8d01f (diff)
downloadayatana-indicator-sound-5b74cf4b47b34fc53b89cc98fab413c603e2c80a.tar.gz
ayatana-indicator-sound-5b74cf4b47b34fc53b89cc98fab413c603e2c80a.tar.bz2
ayatana-indicator-sound-5b74cf4b47b34fc53b89cc98fab413c603e2c80a.zip
panning now honoured at all times, more feedback loop noise removed also from the indicator side
Diffstat (limited to 'src/pulse-manager.c')
-rw-r--r--src/pulse-manager.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index 1ce94d0..e3fa097 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -46,6 +46,18 @@ static void destroy_sink_info(void *value);
static gboolean determine_sink_availability();
static void reconnect_to_pulse();
+static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cached_sink);
+/*static gdouble construct_volume_with_respect_to_balance(pa_cvolume* new_vol, pa_cvolume* cached_vol, pa_channel_map* cached_map);*/
+
+
+enum {
+ VOLUME,
+ BALANCE,
+ FADE,
+ LFE,
+};
+
+#define NUM_TYPES LFE + 1
/**
Refactoring notes
@@ -223,25 +235,38 @@ void set_sink_volume(gdouble percent)
if(pa_server_available == FALSE)
return;
g_debug("in the pulse manager:set_sink_volume with percent %f", percent);
+
if(DEFAULT_SINK_INDEX < 0)
{
g_warning("We have no default sink !!! - returning after not attempting to set any volume of any sink");
return;
}
- sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
-
+ sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX));
+ pa_volume_t cached_volume = pa_cvolume_max(&s->volume);
pa_volume_t new_volume = (pa_volume_t) ((percent * PA_VOLUME_NORM) / 100);
- g_debug("new_volume double check :%f", pa_sw_volume_to_linear(new_volume));
- g_debug("new volume calculated :%f", (gdouble)new_volume);
- pa_cvolume dev_vol;
- pa_cvolume_set(&dev_vol, s->volume.channels, new_volume);
- s->volume = dev_vol;
- pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL));
-
+ pa_volume_t difference = 0;
+
+ if( cached_volume > new_volume ){
+ g_debug("I'm moving down down ...");
+ difference = cached_volume - new_volume;
+ pa_cvolume_dec(&s->volume, difference);
+ }
+ else if ( cached_volume < new_volume ){
+ g_debug("I'm moving up up ...");
+ difference = new_volume - cached_volume;
+ pa_cvolume_inc(&s->volume, difference);
+ }
+
+ g_debug("Calculated difference : %f", (gdouble)difference);
+ g_debug("new_volume calculated from percentage input :%f", pa_sw_volume_to_linear(new_volume));
+ g_debug("new volume calculated from resultant output :%f", pa_sw_volume_to_linear(pa_cvolume_max(&s->volume)));
+
+ pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &s->volume, NULL, NULL));
}
+
/**********************************************************************************************************************/
// Pulse-Audio asychronous call-backs
/**********************************************************************************************************************/
@@ -373,9 +398,18 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
s->name = g_strdup(info->name);
gboolean mute_changed = s->mute != !!info->mute;
s->mute = !!info->mute;
- gboolean volume_changed = (pa_cvolume_equal(&info->volume, &s->volume) == 0);
+ g_debug("new balance : %i", (int)(pa_cvolume_get_balance(&info->volume, &info->channel_map) * 100));
+ g_debug("cached balance : %i", (int)(pa_cvolume_get_balance(&s->volume, &s->channel_map) * 100));
+ g_debug("update_sink_info: new_volume input : %f", (gdouble)(pa_cvolume_avg(&info->volume)));
+ g_debug("update sink info: cached volume is at: %f", (gdouble)(pa_cvolume_avg(&s->volume)));
+ gboolean volume_changed = has_volume_changed(info, s);
+
+ g_debug("update sink info : volume changed = %i", volume_changed);
+ g_debug("update sink info : compatibility = %i", pa_cvolume_compatible_with_channel_map(&info->volume, &s->channel_map));
+
s->volume = info->volume;
- s->base_volume = info->base_volume;
+ s->channel_map = info->channel_map;
+
if(DEFAULT_SINK_INDEX == s->index)
{
//update the UI
@@ -409,6 +443,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
value->name = g_strdup(info->name);
value->mute = !!info->mute;
value->volume = info->volume;
+ value->channel_map = info->channel_map;
value->base_volume = info->base_volume;
g_hash_table_insert(sink_hash, GINT_TO_POINTER(value->index), value);
g_debug("pulse-manager:update_sink_info -> After adding a new sink to our hash");
@@ -417,6 +452,21 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
}
+static gboolean has_volume_changed(const pa_sink_info* new_sink, sink_info* cached_sink)
+{
+ if(pa_cvolume_compatible_with_channel_map(&new_sink->volume, &cached_sink->channel_map) == FALSE)
+ return FALSE;
+
+ if(pa_cvolume_equal(&new_sink->volume, &cached_sink->volume) == TRUE)
+ return FALSE;
+
+ if((int)(pa_cvolume_get_balance(&new_sink->volume, &new_sink->channel_map) * 100) != (int)(pa_cvolume_get_balance(&cached_sink->volume, &cached_sink->channel_map) * 100))
+ return FALSE;
+
+ return TRUE;
+}
+
+
static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata)
{
g_debug("server info callback");