1
|
1 #include "mpg123.h"
|
|
2
|
|
3 void init_spline(float *x, float *y, int n, float *y2)
|
|
4 {
|
30990
|
5 int i, k;
|
|
6 float p, qn, sig, un, *u;
|
|
7 u = malloc(n * sizeof (float));
|
1
|
8
|
30990
|
9 y2[0] = u[0] = 0.0;
|
1
|
10
|
30990
|
11 for (i = 1; i < n - 1; i++)
|
|
12 {
|
|
13 sig = ((float) x[i] - x[i - 1]) / ((float) x[i + 1] - x[i - 1]);
|
|
14 p = sig * y2[i - 1] + 2.0;
|
|
15 y2[i] = (sig - 1.0) / p;
|
|
16 u[i] = (((float) y[i + 1] - y[i]) / (x[i + 1] - x[i])) -
|
|
17 (((float) y[i] - y[i - 1]) / (x[i] - x[i - 1]));
|
|
18 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
|
|
19 }
|
|
20 qn = un = 0.0;
|
1
|
21
|
30990
|
22 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
|
|
23 for (k = n - 2; k >= 0; k--)
|
|
24 y2[k] = y2[k] * y2[k + 1] + u[k];
|
|
25 free(u);
|
1
|
26 }
|
|
27
|
|
28 float eval_spline(float xa[], float ya[], float y2a[], int n, float x)
|
|
29 {
|
30990
|
30 int klo, khi, k;
|
|
31 float h, b, a;
|
1
|
32
|
30990
|
33 klo = 0;
|
|
34 khi = n - 1;
|
|
35 while (khi - klo > 1)
|
|
36 {
|
|
37 k = (khi + klo) >> 1;
|
|
38 if (xa[k] > x)
|
|
39 khi = k;
|
|
40 else
|
|
41 klo = k;
|
|
42 }
|
|
43 h = xa[khi] - xa[klo];
|
|
44 a = (xa[khi] - x) / h;
|
|
45 b = (x - xa[klo]) / h;
|
|
46 return (a * ya[klo] + b * ya[khi] + ((a * a * a - a) * y2a[klo] + (b * b * b - b) * y2a[khi])
|
|
47 * (h * h) / 6.0);
|
1
|
48 }
|
|
49
|
|
50 void mpg123_set_eq(int on, float preamp, float *b)
|
|
51 {
|
30990
|
52 float x[] =
|
|
53 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, yf[10], val, band[10];
|
|
54 int bands[] =
|
|
55 {0, 4, 8, 16, 26, 78, 157, 313, 366, 418};
|
|
56 int i, j;
|
1
|
57
|
30990
|
58 mpg123_info->eq_active = on;
|
|
59 if (mpg123_info->eq_active)
|
|
60 {
|
|
61 for (i = 0; i < 10; i++)
|
|
62 {
|
|
63 band[i] = b[i] + preamp;
|
|
64 }
|
1
|
65
|
30990
|
66 init_spline(x, band, 10, yf);
|
|
67 for (i = 0; i < 9; i++)
|
|
68 {
|
|
69 for (j = bands[i]; j < bands[i + 1]; j++)
|
|
70 {
|
|
71 val = eval_spline(x, band, yf, 10, i + ((float) (j - bands[i]) * (1.0 / (bands[i + 1] - bands[i]))));
|
|
72 mpg123_info->eq_mul[j] = pow(2, val / 10.0);
|
|
73 }
|
|
74 }
|
|
75 for (i = bands[9]; i < 576; i++)
|
|
76 mpg123_info->eq_mul[i] = mpg123_info->eq_mul[bands[9] - 1];
|
|
77 }
|
1
|
78 }
|