annotate audacious/eq_graph.c @ 197:ccd034857702 trunk

[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
author nenolod
date Tue, 15 Nov 2005 20:21:50 -0800
parents cb178e5ad177
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "eq_graph.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include "main.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include "skin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 init_spline(gfloat * x, gfloat * y, gint n, gfloat * y2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 gint i, k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 gfloat p, qn, sig, un, *u;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 u = (gfloat *) g_malloc(n * sizeof(gfloat));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 y2[0] = u[0] = 0.0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 for (i = 1; i < n - 1; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 sig = ((gfloat) x[i] - x[i - 1]) / ((gfloat) x[i + 1] - x[i - 1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 p = sig * y2[i - 1] + 2.0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 y2[i] = (sig - 1.0) / p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 u[i] =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 (((gfloat) y[i + 1] - y[i]) / (x[i + 1] - x[i])) -
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 (((gfloat) y[i] - y[i - 1]) / (x[i] - x[i - 1]));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 qn = un = 0.0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 for (k = n - 2; k >= 0; k--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 y2[k] = y2[k] * y2[k + 1] + u[k];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 g_free(u);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 gfloat
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 eval_spline(gfloat xa[], gfloat ya[], gfloat y2a[], gint n, gfloat x)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 gint klo, khi, k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 gfloat h, b, a;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 klo = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 khi = n - 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 while (khi - klo > 1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 k = (khi + klo) >> 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 if (xa[k] > x)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 khi = k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 klo = k;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 h = xa[khi] - xa[klo];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 a = (xa[khi] - x) / h;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 b = (x - xa[klo]) / h;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 return (a * ya[klo] + b * ya[khi] +
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 ((a * a * a - a) * y2a[klo] +
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 (b * b * b - b) * y2a[khi]) * (h * h) / 6.0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 eqgraph_draw(Widget * w)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 EqGraph *eg = (EqGraph *) w;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 GdkPixmap *obj;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 GdkColor col;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 guint32 cols[19];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 gint i, y, ymin, ymax, py = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 gfloat x[] = { 0, 11, 23, 35, 47, 59, 71, 83, 97, 109 }, yf[10];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 * This avoids the init_spline() function to be inlined.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 * Inlining the function caused troubles when compiling with
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 * `-O' (at least on FreeBSD).
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 void (*__init_spline) (gfloat *, gfloat *, gint, gfloat *) = init_spline;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 obj = eg->eg_widget.parent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 skin_draw_pixmap(bmp_active_skin, obj, eg->eg_widget.gc, SKIN_EQMAIN,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 0, 294, eg->eg_widget.x, eg->eg_widget.y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 eg->eg_widget.width, eg->eg_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 skin_draw_pixmap(bmp_active_skin, obj, eg->eg_widget.gc, SKIN_EQMAIN,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 0, 314, eg->eg_widget.x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 eg->eg_widget.y + 9 +
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 ((cfg.equalizer_preamp * 9) / 20),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 eg->eg_widget.width, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 skin_get_eq_spline_colors(bmp_active_skin, cols);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 __init_spline(x, cfg.equalizer_bands, 10, yf);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 for (i = 0; i < 109; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 y = 9 -
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 (gint) ((eval_spline(x, cfg.equalizer_bands, yf, 10, i) *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 9.0) / 20.0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 if (y < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 if (y > 18)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 y = 18;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 if (!i)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 py = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if (y < py) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 ymin = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 ymax = py;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 ymin = py;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 ymax = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 py = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 for (y = ymin; y <= ymax; y++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 col.pixel = cols[y];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 gdk_gc_set_foreground(eg->eg_widget.gc, &col);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 gdk_draw_point(obj, eg->eg_widget.gc, eg->eg_widget.x + i + 2,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 eg->eg_widget.y + y);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 EqGraph *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 create_eqgraph(GList ** wlist, GdkPixmap * parent, GdkGC * gc, gint x, gint y)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 EqGraph *eg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 eg = g_new0(EqGraph, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 widget_init(&eg->eg_widget, parent, gc, x, y, 113, 19, TRUE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 eg->eg_widget.draw = eqgraph_draw;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 widget_list_add(wlist, WIDGET(eg));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 return eg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 }