comparison src/audacious/equalizer_flow.c @ 4300:060c9865ea17

forgotten files
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sat, 23 Feb 2008 16:37:02 +0300
parents
children cfaecedace4e
comparison
equal deleted inserted replaced
4299:a16edefb8836 4300:060c9865ea17
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
20 #define AUD_DEBUG
21
22 #include <glib.h>
23 #include "main.h"
24 #include "plugin.h"
25 #include "flow.h"
26
27 #include "af_compat.h"
28 #include "equalizer_flow.h"
29
30 int equalizer_open(af_instance_t* af); /* af_equalizer.c */
31
32 static af_instance_t *eq = NULL;
33 static gint eq_nch = 0;
34 static gint eq_rate = 0;
35 static gboolean bands_changed = FALSE;
36
37 static void
38 equalizer_flow_reinit(gint rate, gint nch)
39 {
40 af_data_t data;
41
42 AUDDBG("\n");
43 if(eq == NULL) return;
44
45 data.rate = rate;
46 data.nch = nch;
47 data.bps = 4;
48 data.format = AF_FORMAT_FLOAT_NE;
49 eq->control(eq, AF_CONTROL_REINIT, &data);
50 }
51
52 void
53 equalizer_flow(FlowContext *context)
54 {
55 af_data_t data;
56
57 if(!cfg.equalizer_active || eq == NULL) return;
58
59 if(context->fmt != FMT_FLOAT) {
60 context->error = TRUE;
61 return;
62 }
63
64 if(eq_nch != context->channels ||
65 eq_rate != context->srate ||
66 bands_changed) {
67 equalizer_flow_reinit(context->srate, context->channels);
68 eq_nch = context->channels;
69 eq_rate = context->srate;
70 bands_changed = FALSE;
71 }
72
73 data.nch = context->channels;
74 data.audio = context->data;
75 data.len = context->len;
76 eq->play(eq, &data);
77 }
78
79 void
80 equalizer_flow_set_bands(gfloat pre, gfloat *bands)
81 {
82 int i;
83 af_control_ext_t ctl;
84 AUDDBG("\n");
85
86 if(eq == NULL) {
87 eq = g_malloc(sizeof(af_instance_t));
88 equalizer_open(eq);
89 }
90
91 ctl.arg = bands;
92 for(i = 0; i < AF_NCH; i++) {
93 ctl.ch = i;
94 eq->control(eq, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &ctl);
95 }
96
97 bands_changed = TRUE;
98 }
99
100 void
101 equalizer_flow_free()
102 {
103 AUDDBG("\n");
104 if(eq != NULL) {
105 eq->uninit(eq);
106 g_free(eq);
107 eq = NULL;
108 eq_nch = 0;
109 eq_rate = 0;
110 bands_changed = FALSE;
111 }
112 }