Mercurial > audlegacy-plugins
comparison src/stereo_plugin/stereo.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Effect/stereo_plugin/stereo.c@1a34353aeca5 |
children | 67b56e61de74 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 #include <gtk/gtk.h> | |
2 #include <glib/gi18n.h> | |
3 #include "audacious/util.h" | |
4 | |
5 #include <audacious/plugin.h> | |
6 #include <audacious/configdb.h> | |
7 | |
8 #include "../../../config.h" | |
9 | |
10 static void init(void); | |
11 static void about(void); | |
12 static void configure(void); | |
13 static int mod_samples(gpointer *d, gint length, AFormat afmt, gint srate, gint nch); | |
14 | |
15 | |
16 | |
17 EffectPlugin stereo_ep = | |
18 { | |
19 NULL, | |
20 NULL, | |
21 NULL, /* Description */ | |
22 init, | |
23 NULL, | |
24 about, | |
25 configure, | |
26 mod_samples | |
27 }; | |
28 | |
29 static const char *about_text = N_("Extra Stereo Plugin\n\n" | |
30 "By Johan Levin 1999."); | |
31 | |
32 static GtkWidget *conf_dialog = NULL; | |
33 static gdouble value; | |
34 | |
35 EffectPlugin *get_eplugin_info(void) | |
36 { | |
37 stereo_ep.description = | |
38 g_strdup_printf(_("Extra Stereo Plugin %s"), VERSION); | |
39 return &stereo_ep; | |
40 } | |
41 | |
42 static void init(void) | |
43 { | |
44 ConfigDb *db; | |
45 db = bmp_cfg_db_open(); | |
46 if (!bmp_cfg_db_get_double(db, "extra_stereo", "intensity", &value)) | |
47 value = 2.5; | |
48 bmp_cfg_db_close(db); | |
49 } | |
50 | |
51 static void about(void) | |
52 { | |
53 static GtkWidget *about_dialog = NULL; | |
54 | |
55 if (about_dialog != NULL) | |
56 return; | |
57 | |
58 about_dialog = xmms_show_message(_("About Extra Stereo Plugin"), | |
59 _(about_text), _("Ok"), FALSE, | |
60 NULL, NULL); | |
61 gtk_signal_connect(GTK_OBJECT(about_dialog), "destroy", | |
62 GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
63 &about_dialog); | |
64 } | |
65 | |
66 static void conf_ok_cb(GtkButton * button, gpointer data) | |
67 { | |
68 ConfigDb *db; | |
69 | |
70 value = *(gdouble *) data; | |
71 | |
72 db = bmp_cfg_db_open(); | |
73 bmp_cfg_db_set_double(db, "extra_stereo", "intensity", value); | |
74 bmp_cfg_db_close(db); | |
75 gtk_widget_destroy(conf_dialog); | |
76 } | |
77 | |
78 static void conf_cancel_cb(GtkButton * button, gpointer data) | |
79 { | |
80 gtk_widget_destroy(conf_dialog); | |
81 } | |
82 | |
83 static void conf_apply_cb(GtkButton *button, gpointer data) | |
84 { | |
85 value = *(gdouble *) data; | |
86 } | |
87 | |
88 static void configure(void) | |
89 { | |
90 GtkWidget *hbox, *label, *scale, *button, *bbox; | |
91 GtkObject *adjustment; | |
92 | |
93 if (conf_dialog != NULL) | |
94 return; | |
95 | |
96 conf_dialog = gtk_dialog_new(); | |
97 gtk_signal_connect(GTK_OBJECT(conf_dialog), "destroy", | |
98 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &conf_dialog); | |
99 gtk_window_set_title(GTK_WINDOW(conf_dialog), _("Configure Extra Stereo")); | |
100 | |
101 label = gtk_label_new(_("Effect intensity:")); | |
102 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(conf_dialog)->vbox), label, | |
103 TRUE, TRUE, 0); | |
104 gtk_widget_show(label); | |
105 | |
106 hbox = gtk_hbox_new(FALSE, 10); | |
107 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(conf_dialog)->vbox), hbox, | |
108 TRUE, TRUE, 10); | |
109 gtk_widget_show(hbox); | |
110 | |
111 adjustment = gtk_adjustment_new(value, 0.0, 15.0 + 1.0, 0.1, 1.0, 1.0); | |
112 scale = gtk_hscale_new(GTK_ADJUSTMENT(adjustment)); | |
113 gtk_box_pack_start(GTK_BOX(hbox), scale, TRUE, TRUE, 10); | |
114 gtk_widget_show(scale); | |
115 | |
116 bbox = gtk_hbutton_box_new(); | |
117 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
118 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
119 gtk_box_pack_start(GTK_BOX((GTK_DIALOG(conf_dialog)->action_area)), | |
120 bbox, TRUE, TRUE, 0); | |
121 | |
122 button = gtk_button_new_with_label(_("Ok")); | |
123 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
124 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); | |
125 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
126 GTK_SIGNAL_FUNC(conf_ok_cb), | |
127 >K_ADJUSTMENT(adjustment)->value); | |
128 gtk_widget_grab_default(button); | |
129 gtk_widget_show(button); | |
130 | |
131 button = gtk_button_new_with_label(_("Cancel")); | |
132 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
133 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); | |
134 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
135 GTK_SIGNAL_FUNC(conf_cancel_cb), NULL); | |
136 gtk_widget_show(button); | |
137 | |
138 button = gtk_button_new_with_label(_("Apply")); | |
139 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
140 gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0); | |
141 gtk_signal_connect(GTK_OBJECT(button), "clicked", | |
142 GTK_SIGNAL_FUNC(conf_apply_cb), | |
143 >K_ADJUSTMENT(adjustment)->value); | |
144 gtk_widget_show(button); | |
145 | |
146 gtk_widget_show(bbox); | |
147 | |
148 gtk_widget_show(conf_dialog); | |
149 } | |
150 | |
151 static int mod_samples(gpointer *d, gint length, AFormat afmt, gint srate, gint nch) | |
152 { | |
153 gint i; | |
154 gdouble avg, ldiff, rdiff, tmp, mul; | |
155 gint16 *data = (gint16 *)*d; | |
156 | |
157 if (!(afmt == FMT_S16_NE || | |
158 (afmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) || | |
159 (afmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) || | |
160 nch != 2) | |
161 return length; | |
162 | |
163 mul = value; | |
164 | |
165 for (i = 0; i < length / 2; i += 2) | |
166 { | |
167 avg = (data[i] + data[i + 1]) / 2; | |
168 ldiff = data[i] - avg; | |
169 rdiff = data[i + 1] - avg; | |
170 | |
171 tmp = avg + ldiff * mul; | |
172 if (tmp < -32768) | |
173 tmp = -32768; | |
174 if (tmp > 32767) | |
175 tmp = 32767; | |
176 data[i] = tmp; | |
177 | |
178 tmp = avg + rdiff * mul; | |
179 if (tmp < -32768) | |
180 tmp = -32768; | |
181 if (tmp > 32767) | |
182 tmp = 32767; | |
183 data[i + 1] = tmp; | |
184 } | |
185 return length; | |
186 } |