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