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