Mercurial > audlegacy
annotate audacious/output.c @ 439:3c43e25ddc7d trunk
[svn] Add `Apply' button to the presets window. Patch via NhJm.
author | nenolod |
---|---|
date | Sun, 15 Jan 2006 00:34:41 -0800 |
parents | 67cd014f35a2 |
children | 6c28a04d1254 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include "output.h" | |
27 #include "iir.h" | |
28 #include "main.h" | |
29 #include "input.h" | |
30 | |
31 #include "playlist.h" | |
32 #include "libaudacious/util.h" | |
33 | |
34 OutputPluginData op_data = { | |
35 NULL, | |
36 NULL | |
37 }; | |
38 | |
39 OutputPlugin * | |
40 get_current_output_plugin(void) | |
41 { | |
42 return op_data.current_output_plugin; | |
43 } | |
44 | |
45 void | |
46 set_current_output_plugin(gint i) | |
47 { | |
48 #if 0 | |
49 gint time; | |
50 gint pos; | |
51 gboolean playing; | |
52 #endif | |
53 | |
54 GList *node = g_list_nth(op_data.output_list, i); | |
55 if (!node) { | |
56 op_data.current_output_plugin = NULL; | |
57 return; | |
58 } | |
59 | |
60 op_data.current_output_plugin = node->data; | |
61 | |
62 | |
63 #if 0 | |
64 playing = bmp_playback_get_playing(); | |
65 if (playing) { | |
66 | |
67 /* FIXME: we do all on our own here */ | |
68 | |
69 guint min = 0, sec = 0, params, time, pos; | |
70 gchar timestr[10]; | |
71 | |
72 bmp_playback_pause(); | |
73 pos = get_playlist_position(); | |
74 time = bmp_playback_get_time() / 1000; | |
75 g_snprintf(timestr, sizeof(timestr), "%u:%2.2u", | |
76 time / 60, time % 60); | |
77 | |
78 params = sscanf(timestr, "%u:%u", &min, &sec); | |
79 if (params == 2) | |
80 time = (min * 60) + sec; | |
81 else if (params == 1) | |
82 time = min; | |
83 else | |
84 return; | |
85 | |
86 bmp_playback_stop(); | |
87 playlist_set_position(pos); | |
88 bmp_playback_play_file(playlist_get_filename(pos)); | |
89 | |
90 while (!bmp_playback_get_playing()) | |
91 g_message("waiting..."); | |
92 | |
93 if (playlist_get_current_length() > -1 && | |
94 time <= (playlist_get_current_length() / 1000)) { | |
95 /* Some time for things to cool down and heat up */ | |
96 g_usleep(1000000); | |
97 bmp_playback_seek(time); | |
98 } | |
99 } | |
100 #endif | |
101 } | |
102 | |
103 GList * | |
104 get_output_list(void) | |
105 { | |
106 return op_data.output_list; | |
107 } | |
108 | |
109 void | |
110 output_about(gint i) | |
111 { | |
112 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
113 if (out && out->about) | |
114 out->about(); | |
115 } | |
116 | |
117 void | |
118 output_configure(gint i) | |
119 { | |
120 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
121 if (out && out->configure) | |
122 out->configure(); | |
123 } | |
124 | |
125 void | |
126 output_get_volume(gint * l, gint * r) | |
127 { | |
128 *l = *r = -1; | |
129 | |
130 if (!op_data.current_output_plugin) | |
131 return; | |
132 | |
133 if (!op_data.current_output_plugin->get_volume) | |
134 return; | |
135 | |
136 op_data.current_output_plugin->get_volume(l, r); | |
137 } | |
138 | |
139 void | |
140 output_set_volume(gint l, gint r) | |
141 { | |
142 if (!op_data.current_output_plugin) | |
143 return; | |
144 | |
145 if (!op_data.current_output_plugin->set_volume) | |
146 return; | |
147 | |
148 op_data.current_output_plugin->set_volume(l, r); | |
149 } | |
150 | |
151 void | |
152 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
153 { | |
154 int i; | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
155 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
156 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
157 |
0 | 158 for (i = 0; i < 10; ++i) |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
159 { |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
160 set_gain(i, 0, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
161 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
162 } |
0 | 163 } |
164 | |
165 /* this should be in BYTES, NOT gint16s */ | |
166 static void | |
167 byteswap(size_t size, | |
168 gint16 * buf) | |
169 { | |
170 gint16 *it; | |
171 size &= ~1; /* must be multiple of 2 */ | |
172 for (it = buf; it < buf + size / 2; ++it) | |
173 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it); | |
174 } | |
175 | |
176 static void | |
177 output_to_plugin(gint time, | |
178 AFormat format, | |
179 gint n_channels, | |
180 gint length, | |
181 gpointer sample, | |
182 int *going) | |
183 { | |
184 OutputPlugin *op = get_current_output_plugin(); | |
185 | |
186 /* do vis plugin(s) */ | |
187 input_add_vis_pcm(time, format, n_channels, length, sample); | |
188 | |
189 while (op->buffer_free() < length) { /* wait output buf */ | |
190 if (going && !*going) /* thread stopped? */ | |
191 return; /* so finish */ | |
192 | |
193 g_usleep(10000); /* else sleep for retry */ | |
194 } | |
195 | |
196 op->write_audio(sample, length); /* do output */ | |
197 } | |
198 | |
199 | |
200 | |
201 /* called by input plugin when data is ready */ | |
202 void | |
203 produce_audio(gint time, /* position */ | |
204 AFormat fmt, /* output format */ | |
205 gint nch, /* channels */ | |
206 gint length, /* length of sample */ | |
207 gpointer ptr, /* data */ | |
208 int *going /* 0 when time to stop */ | |
209 ) | |
210 { | |
211 #ifndef XMMS_EQ | |
212 | |
213 static int init = 0; | |
214 int swapped = 0; | |
215 int myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; | |
216 int caneq = (fmt == FMT_S16_NE || fmt == myorder); | |
217 | |
218 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ | |
219 byteswap(length, ptr); /* so convert */ | |
220 ++swapped; | |
221 ++caneq; | |
222 } /* can eq now, mark swapd */ | |
223 else if (caneq && !cfg.equalizer_active) /* right order but no eq */ | |
224 caneq = 0; /* so don't eq */ | |
225 | |
226 if (caneq) { /* if eq enab */ | |
227 if (!init) { /* if first run */ | |
228 init_iir(); /* then init eq */ | |
229 ++init; | |
230 } | |
231 | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
232 iir(&ptr, length, nch); |
0 | 233 |
234 if (swapped) /* if was swapped */ | |
235 byteswap(length, ptr); /* swap back for output */ | |
236 } | |
237 | |
238 #endif | |
239 | |
240 output_to_plugin(time, fmt, nch, length, ptr, going); | |
241 } |