changeset 1728:63feceeb3799

Remove software volume control (it has been moved to the core as a pipeline flow element).
author William Pitcock <nenolod@atheme.org>
date Tue, 18 Sep 2007 10:53:36 -0500
parents 9d6de95dd7ed
children 38375d565192
files src/alsa/alsa.h src/alsa/audio.c src/alsa/configure.c src/alsa/init.c
diffstat 4 files changed, 10 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/src/alsa/alsa.h	Tue Sep 18 09:47:41 2007 -0500
+++ b/src/alsa/alsa.h	Tue Sep 18 10:53:36 2007 -0500
@@ -56,7 +56,6 @@
 	{
 		int left, right;
 	} vol;
-	gboolean soft_volume;
 };
 
 extern struct alsa_config alsa_cfg;
--- a/src/alsa/audio.c	Tue Sep 18 09:47:41 2007 -0500
+++ b/src/alsa/audio.c	Tue Sep 18 10:53:36 2007 -0500
@@ -443,8 +443,7 @@
 		return -1;
 	}
 
-	if (!alsa_cfg.soft_volume)
-		alsa_set_volume(a * 100 / alsa_max_vol, b * 100 / alsa_max_vol);
+	alsa_set_volume(a * 100 / alsa_max_vol, b * 100 / alsa_max_vol);
 
 	debug("alsa_setup_mixer: end");
 
@@ -485,28 +484,20 @@
 		mixer_start = FALSE;
 	}
 
-	if (alsa_cfg.soft_volume)
-	{
-		*l = alsa_cfg.vol.left;
-		*r = alsa_cfg.vol.right;
-	}
-
 	if (!pcm_element)
 		return;
 
 	snd_mixer_handle_events(mixer);
 
-	if (!alsa_cfg.soft_volume)
-	{
-		snd_mixer_selem_get_playback_volume(pcm_element,
-						    SND_MIXER_SCHN_FRONT_LEFT,
-						    &ll);
-		snd_mixer_selem_get_playback_volume(pcm_element,
-						    SND_MIXER_SCHN_FRONT_RIGHT,
-						    &lr);
-		*l = ll;
-		*r = lr;
-	}
+	snd_mixer_selem_get_playback_volume(pcm_element,
+					    SND_MIXER_SCHN_FRONT_LEFT,
+					    &ll);
+	snd_mixer_selem_get_playback_volume(pcm_element,
+					    SND_MIXER_SCHN_FRONT_RIGHT,
+					    &lr);
+	*l = ll;
+	*r = lr;
+
 	if (mixer_timeout)
 		gtk_timeout_remove(mixer_timeout);
 	mixer_timeout = gtk_timeout_add(5000, alsa_mixer_timeout, NULL);
@@ -515,13 +506,6 @@
 
 void alsa_set_volume(int l, int r)
 {
-	if (alsa_cfg.soft_volume)
-	{
-		alsa_cfg.vol.left = l;
-		alsa_cfg.vol.right = r;
-		return;
-	}
-
 	if (!pcm_element)
 		return;
 
@@ -590,110 +574,6 @@
 	return (alsa_total_written * 1000) / inputf->bps;
 }
 
-#define STEREO_ADJUST(type, type2, endian)					\
-do {										\
-	type *ptr = data;							\
-	for (i = 0; i < length; i += 4)						\
-	{									\
-		*ptr = type2##_TO_##endian(type2##_FROM_## endian(*ptr) *	\
-					   lvol / 256);				\
-		ptr++;								\
-		*ptr = type2##_TO_##endian(type2##_FROM_##endian(*ptr) *	\
-					   rvol / 256);				\
-		ptr++;								\
-	}									\
-} while (0)
-
-#define MONO_ADJUST(type, type2, endian)					\
-do {										\
-	type *ptr = data;							\
-	for (i = 0; i < length; i += 2)						\
-	{									\
-		*ptr = type2##_TO_##endian(type2##_FROM_## endian(*ptr) *	\
-					   vol / 256);				\
-		ptr++;								\
-	}									\
-} while (0)
-
-#define VOLUME_ADJUST(type, type2, endian)		\
-do {							\
-	if (channels == 2)				\
-		STEREO_ADJUST(type, type2, endian);	\
-	else						\
-		MONO_ADJUST(type, type2, endian);	\
-} while (0)
-
-#define STEREO_ADJUST8(type)				\
-do {							\
-	type *ptr = data;				\
-	for (i = 0; i < length; i += 2)			\
-	{						\
-		*ptr = *ptr * lvol / 256;		\
-		ptr++;					\
-		*ptr = *ptr * rvol / 256;		\
-		ptr++;					\
-	}						\
-} while (0)
-
-#define MONO_ADJUST8(type)			\
-do {						\
-	type *ptr = data;			\
-	for (i = 0; i < length; i++)		\
-	{					\
-		*ptr = *ptr * vol / 256;	\
-		ptr++;				\
-	}					\
-} while (0)
-
-#define VOLUME_ADJUST8(type)			\
-do {						\
-	if (channels == 2)			\
-		STEREO_ADJUST8(type);		\
-	else					\
-		MONO_ADJUST8(type);		\
-} while (0)
-
-
-static void volume_adjust(void* data, int length, AFormat fmt, int channels)
-{
-	int i, vol, lvol, rvol;
-
-	if ((alsa_cfg.vol.left == 100 && alsa_cfg.vol.right == 100) ||
-	    (channels == 1 &&
-	     (alsa_cfg.vol.left == 100 || alsa_cfg.vol.right == 100)))
-		return;
-
-	lvol = pow(10, (alsa_cfg.vol.left - 100) / 40.0) * 256;
-	rvol = pow(10, (alsa_cfg.vol.right - 100) / 40.0) * 256;
-	vol = MAX(lvol, rvol);
-
-	switch (fmt)
-	{
-		case FMT_S16_LE:
-			VOLUME_ADJUST(gint16, GINT16, LE);
-			break;
-		case FMT_U16_LE:
-			VOLUME_ADJUST(guint16, GUINT16, LE);
-			break;
-		case FMT_S16_BE:
-			VOLUME_ADJUST(gint16, GINT16, BE);
-			break;
-		case FMT_U16_BE:
-			VOLUME_ADJUST(guint16, GUINT16, BE);
-			break;
-		case FMT_S8:
-			VOLUME_ADJUST8(gint8);
-			break;
-		case FMT_U8:
-			VOLUME_ADJUST8(guint8);
-			break;
-		default:
-			g_warning("volue_adjust(): unhandled format: %d", fmt);
-			break;
-	}
-}
-
-
 /* transfer data to audio h/w; length is given in bytes
  *
  * data can be modified via effect plugin, rate conversion or
@@ -718,9 +598,6 @@
 						     effectf->rate,
 						     outputf->rate);
 
-	if (alsa_cfg.soft_volume)
-		volume_adjust(data, length, outputf->xmms_format, outputf->channels);
-
 	alsa_write_audio(data, length);
 }
 
--- a/src/alsa/configure.c	Tue Sep 18 09:47:41 2007 -0500
+++ b/src/alsa/configure.c	Tue Sep 18 10:53:36 2007 -0500
@@ -21,7 +21,6 @@
 
 static GtkWidget *configure_win = NULL;
 static GtkWidget *buffer_time_spin, *period_time_spin;
-static GtkWidget *softvolume_toggle_button;
 
 static GtkWidget *devices_combo, *mixer_devices_combo;
 
@@ -38,7 +37,6 @@
 	alsa_cfg.pcm_device = GET_CHARS(GTK_COMBO(devices_combo)->entry);
 	alsa_cfg.buffer_time = GET_SPIN_INT(buffer_time_spin);
 	alsa_cfg.period_time = GET_SPIN_INT(period_time_spin);
-	alsa_cfg.soft_volume = GET_TOGGLE(softvolume_toggle_button);
 	alsa_cfg.mixer_card = current_mixer_card;
 	alsa_cfg.mixer_device = GET_CHARS(GTK_COMBO(mixer_devices_combo)->entry);
 
@@ -55,8 +53,6 @@
 	bmp_cfg_db_set_string(cfgfile,"ALSA","pcm_device", alsa_cfg.pcm_device);
 	bmp_cfg_db_set_int(cfgfile, "ALSA", "mixer_card", alsa_cfg.mixer_card);
 	bmp_cfg_db_set_string(cfgfile,"ALSA","mixer_device", alsa_cfg.mixer_device);
-	bmp_cfg_db_set_bool(cfgfile, "ALSA", "soft_volume",
-			       alsa_cfg.soft_volume);
 	bmp_cfg_db_set_int(cfgfile, "ALSA", "volume_left", alsa_cfg.vol.left);
 	bmp_cfg_db_set_int(cfgfile, "ALSA", "volume_right", alsa_cfg.vol.right);
 	bmp_cfg_db_close(cfgfile);
@@ -236,13 +232,6 @@
 			  current_mixer_card);
 }
 
-static void softvolume_toggle_cb(GtkToggleButton * widget, gpointer data)
-{
-	gboolean softvolume = gtk_toggle_button_get_active(widget);
-	gtk_widget_set_sensitive(GTK_WIDGET(data), !softvolume);
-	gtk_widget_set_sensitive(mixer_devices_combo, !softvolume);
-}
-
 void alsa_configure(void)
 {
 	GtkWidget *vbox, *notebook;
@@ -303,12 +292,6 @@
 	gtk_container_set_border_width(GTK_CONTAINER(mixer_box), 5);
 	gtk_container_add(GTK_CONTAINER(mixer_frame), mixer_box);
 
-	softvolume_toggle_button = gtk_check_button_new_with_label(
-		_("Use software volume control"));
-
-	gtk_box_pack_start(GTK_BOX(mixer_box), softvolume_toggle_button,
-			   FALSE, FALSE, 0);
-
 	mixer_table = gtk_table_new(2, 2, FALSE);
 	gtk_table_set_row_spacings(GTK_TABLE(mixer_table), 5);
 	gtk_table_set_col_spacings(GTK_TABLE(mixer_table), 5);
@@ -341,11 +324,6 @@
 	gtk_table_attach(GTK_TABLE(mixer_table), mixer_devices_combo,
 			 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 
-	gtk_signal_connect(GTK_OBJECT(softvolume_toggle_button), "toggled",
-			   (GCallback)softvolume_toggle_cb, mixer_card_om);
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(softvolume_toggle_button),
-				     alsa_cfg.soft_volume);
-
 	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox,
 				 gtk_label_new(_("Device settings")));
 
--- a/src/alsa/init.c	Tue Sep 18 09:47:41 2007 -0500
+++ b/src/alsa/init.c	Tue Sep 18 10:53:36 2007 -0500
@@ -47,11 +47,6 @@
 	bmp_cfg_db_get_int(cfgfile, "ALSA", "buffer_time", &alsa_cfg.buffer_time);
 	bmp_cfg_db_get_int(cfgfile, "ALSA", "period_time", &alsa_cfg.period_time);
 
-	bmp_cfg_db_get_bool(cfgfile, "ALSA", "soft_volume",
-			      &alsa_cfg.soft_volume);
-	bmp_cfg_db_get_int(cfgfile, "ALSA", "volume_left", &alsa_cfg.vol.left);
-	bmp_cfg_db_get_int(cfgfile, "ALSA", "volume_right", &alsa_cfg.vol.right);
-
 	bmp_cfg_db_get_bool(cfgfile, "ALSA", "debug", &alsa_cfg.debug);
 	bmp_cfg_db_close(cfgfile);