Mercurial > audlegacy
annotate src/audacious/equalizer_flow.c @ 4516:9fbb55542e73
hookified many function calls
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 23 Apr 2008 20:11:10 +0200 |
parents | e548627b2004 |
children |
rev | line source |
---|---|
4300 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2008 Audacious team | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; under version 3 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * You should have received a copy of the GNU General Public License | |
14 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
15 * | |
16 * The Audacious team does not consider modular code linking to | |
17 * Audacious or using our public API to be a derived work. | |
18 */ | |
19 | |
4307
cfaecedace4e
importing of winamp EQ presets library
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4300
diff
changeset
|
20 /*#define AUD_DEBUG*/ |
4300 | 21 |
22 #include <glib.h> | |
4314
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
23 #include <math.h> |
4300 | 24 #include "main.h" |
25 #include "plugin.h" | |
26 #include "flow.h" | |
27 | |
28 #include "af_compat.h" | |
29 #include "equalizer_flow.h" | |
30 | |
31 int equalizer_open(af_instance_t* af); /* af_equalizer.c */ | |
32 | |
33 static af_instance_t *eq = NULL; | |
34 static gint eq_nch = 0; | |
35 static gint eq_rate = 0; | |
36 static gboolean bands_changed = FALSE; | |
37 | |
38 static void | |
39 equalizer_flow_reinit(gint rate, gint nch) | |
40 { | |
41 af_data_t data; | |
42 | |
43 AUDDBG("\n"); | |
44 if(eq == NULL) return; | |
45 | |
46 data.rate = rate; | |
47 data.nch = nch; | |
48 data.bps = 4; | |
49 data.format = AF_FORMAT_FLOAT_NE; | |
50 eq->control(eq, AF_CONTROL_REINIT, &data); | |
51 } | |
52 | |
53 void | |
54 equalizer_flow(FlowContext *context) | |
55 { | |
56 af_data_t data; | |
57 | |
58 if(!cfg.equalizer_active || eq == NULL) return; | |
59 | |
60 if(context->fmt != FMT_FLOAT) { | |
61 context->error = TRUE; | |
62 return; | |
63 } | |
64 | |
65 if(eq_nch != context->channels || | |
66 eq_rate != context->srate || | |
67 bands_changed) { | |
68 equalizer_flow_reinit(context->srate, context->channels); | |
69 eq_nch = context->channels; | |
70 eq_rate = context->srate; | |
71 bands_changed = FALSE; | |
72 } | |
73 | |
74 data.nch = context->channels; | |
75 data.audio = context->data; | |
76 data.len = context->len; | |
77 eq->play(eq, &data); | |
78 } | |
79 | |
80 void | |
81 equalizer_flow_set_bands(gfloat pre, gfloat *bands) | |
82 { | |
83 int i; | |
84 af_control_ext_t ctl; | |
4314
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
85 gfloat b[10]; |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
86 gfloat adj = 0.0; |
4300 | 87 AUDDBG("\n"); |
88 | |
89 if(eq == NULL) { | |
90 eq = g_malloc(sizeof(af_instance_t)); | |
91 equalizer_open(eq); | |
92 } | |
4314
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
93 |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
94 for(i = 0; i < 10; i++) |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
95 b[i] = bands[i] + pre; |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
96 |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
97 for(i = 0; i < 10; i++) |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
98 if(fabsf(b[i]) > fabsf(adj)) adj = b[i]; |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
99 |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
100 if(fabsf(adj) > EQUALIZER_MAX_GAIN) { |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
101 adj = adj > 0.0 ? EQUALIZER_MAX_GAIN - adj : -EQUALIZER_MAX_GAIN - adj; |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
102 for(i = 0; i < 10; i++) b[i] += adj; |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
103 } |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
104 |
e548627b2004
EQ pregain works. nobody uses it though
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
4307
diff
changeset
|
105 ctl.arg = b; |
4300 | 106 for(i = 0; i < AF_NCH; i++) { |
107 ctl.ch = i; | |
108 eq->control(eq, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &ctl); | |
109 } | |
110 | |
111 bands_changed = TRUE; | |
112 } | |
113 | |
114 void | |
115 equalizer_flow_free() | |
116 { | |
117 AUDDBG("\n"); | |
118 if(eq != NULL) { | |
119 eq->uninit(eq); | |
120 g_free(eq); | |
121 eq = NULL; | |
122 eq_nch = 0; | |
123 eq_rate = 0; | |
124 bands_changed = FALSE; | |
125 } | |
126 } |