annotate mp3lib/equalizer.c @ 25815:8920f8a26c05

sub_scale command now works with ass subtitles renderer
author ben
date Wed, 23 Jan 2008 22:33:46 +0000
parents 3b5f5d1c5041
children 9fc9d1e788aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 #include "mpg123.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 void init_spline(float *x, float *y, int n, float *y2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 int i, k;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 float p, qn, sig, un, *u;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 u = (float *) malloc(n * sizeof (float));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 y2[0] = u[0] = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 for (i = 1; i < n - 1; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 sig = ((float) x[i] - x[i - 1]) / ((float) x[i + 1] - x[i - 1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 p = sig * y2[i - 1] + 2.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 y2[i] = (sig - 1.0) / p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 u[i] = (((float) y[i + 1] - y[i]) / (x[i + 1] - x[i])) -
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 (((float) y[i] - y[i - 1]) / (x[i] - x[i - 1]));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 qn = un = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 for (k = n - 2; k >= 0; k--)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 y2[k] = y2[k] * y2[k + 1] + u[k];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 free(u);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 float eval_spline(float xa[], float ya[], float y2a[], int n, float x)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 int klo, khi, k;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 float h, b, a;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 klo = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 khi = n - 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 while (khi - klo > 1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 k = (khi + klo) >> 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 if (xa[k] > x)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 khi = k;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 klo = k;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 h = xa[khi] - xa[klo];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 a = (xa[khi] - x) / h;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 b = (x - xa[klo]) / h;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 return (a * ya[klo] + b * ya[khi] + ((a * a * a - a) * y2a[klo] + (b * b * b - b) * y2a[khi])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 * (h * h) / 6.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 void mpg123_set_eq(int on, float preamp, float *b)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 float x[] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, yf[10], val, band[10];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 int bands[] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 {0, 4, 8, 16, 26, 78, 157, 313, 366, 418};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 int i, j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 mpg123_info->eq_active = on;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 if (mpg123_info->eq_active)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 for (i = 0; i < 10; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 band[i] = b[i] + preamp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 init_spline(x, band, 10, yf);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 for (i = 0; i < 9; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 for (j = bands[i]; j < bands[i + 1]; j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 val = eval_spline(x, band, yf, 10, i + ((float) (j - bands[i]) * (1.0 / (bands[i + 1] - bands[i]))));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 mpg123_info->eq_mul[j] = pow(2, val / 10.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 for (i = bands[9]; i < 576; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 mpg123_info->eq_mul[i] = mpg123_info->eq_mul[bands[9] - 1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }