annotate mp3lib/equalizer.c @ 32254:70cdc0575aff

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