Mercurial > audlegacy
annotate audacious/output.c @ 865:2f66993e2a53 trunk
[svn] fixed multiple spawns of adplug aboutbox
author | giacomo |
---|---|
date | Fri, 24 Mar 2006 07:51:13 -0800 |
parents | 79da0e6ed790 |
children | ed26947bbf57 |
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 | |
809 | 39 OutputPlugin psuedo_output_plugin = { |
807
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
40 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
41 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
42 "XMMS reverse compatibility output plugin", |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
43 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
44 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
45 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
46 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
47 output_get_volume, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
48 output_set_volume, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
49 NULL, /* XXX we need noop code for this */ |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
50 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
51 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
52 |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
53 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
54 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
55 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
56 NULL, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
57 get_output_time, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
58 get_written_time, |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
59 |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
60 NULL |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
61 }; |
df3412dc33c4
[svn] - add psuedo_output_plugin, a psuedo output plugin that will be used for reverse compatibility with old plugins.
nenolod
parents:
806
diff
changeset
|
62 |
0 | 63 OutputPlugin * |
64 get_current_output_plugin(void) | |
65 { | |
66 return op_data.current_output_plugin; | |
67 } | |
68 | |
69 void | |
70 set_current_output_plugin(gint i) | |
71 { | |
72 #if 0 | |
73 gint time; | |
74 gint pos; | |
75 gboolean playing; | |
76 #endif | |
77 | |
78 GList *node = g_list_nth(op_data.output_list, i); | |
79 if (!node) { | |
80 op_data.current_output_plugin = NULL; | |
81 return; | |
82 } | |
83 | |
84 op_data.current_output_plugin = node->data; | |
85 | |
86 | |
87 #if 0 | |
88 playing = bmp_playback_get_playing(); | |
89 if (playing) { | |
90 | |
91 /* FIXME: we do all on our own here */ | |
92 | |
93 guint min = 0, sec = 0, params, time, pos; | |
94 gchar timestr[10]; | |
95 | |
96 bmp_playback_pause(); | |
97 pos = get_playlist_position(); | |
98 time = bmp_playback_get_time() / 1000; | |
99 g_snprintf(timestr, sizeof(timestr), "%u:%2.2u", | |
100 time / 60, time % 60); | |
101 | |
102 params = sscanf(timestr, "%u:%u", &min, &sec); | |
103 if (params == 2) | |
104 time = (min * 60) + sec; | |
105 else if (params == 1) | |
106 time = min; | |
107 else | |
108 return; | |
109 | |
110 bmp_playback_stop(); | |
111 playlist_set_position(pos); | |
112 bmp_playback_play_file(playlist_get_filename(pos)); | |
113 | |
114 while (!bmp_playback_get_playing()) | |
115 g_message("waiting..."); | |
116 | |
117 if (playlist_get_current_length() > -1 && | |
118 time <= (playlist_get_current_length() / 1000)) { | |
119 /* Some time for things to cool down and heat up */ | |
120 g_usleep(1000000); | |
121 bmp_playback_seek(time); | |
122 } | |
123 } | |
124 #endif | |
125 } | |
126 | |
127 GList * | |
128 get_output_list(void) | |
129 { | |
130 return op_data.output_list; | |
131 } | |
132 | |
133 void | |
134 output_about(gint i) | |
135 { | |
136 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
137 if (out && out->about) | |
138 out->about(); | |
139 } | |
140 | |
141 void | |
142 output_configure(gint i) | |
143 { | |
144 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
145 if (out && out->configure) | |
146 out->configure(); | |
147 } | |
148 | |
149 void | |
150 output_get_volume(gint * l, gint * r) | |
151 { | |
152 *l = *r = -1; | |
153 | |
154 if (!op_data.current_output_plugin) | |
155 return; | |
156 | |
157 if (!op_data.current_output_plugin->get_volume) | |
158 return; | |
159 | |
160 op_data.current_output_plugin->get_volume(l, r); | |
161 } | |
162 | |
163 void | |
164 output_set_volume(gint l, gint r) | |
165 { | |
166 if (!op_data.current_output_plugin) | |
167 return; | |
168 | |
169 if (!op_data.current_output_plugin->set_volume) | |
170 return; | |
171 | |
172 op_data.current_output_plugin->set_volume(l, r); | |
173 } | |
174 | |
175 void | |
176 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
177 { | |
178 int i; | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
179 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
|
180 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
|
181 |
0 | 182 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
|
183 { |
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
184 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
|
185 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
|
186 } |
0 | 187 } |
188 | |
189 /* this should be in BYTES, NOT gint16s */ | |
190 static void | |
191 byteswap(size_t size, | |
192 gint16 * buf) | |
193 { | |
194 gint16 *it; | |
195 size &= ~1; /* must be multiple of 2 */ | |
196 for (it = buf; it < buf + size / 2; ++it) | |
197 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it); | |
198 } | |
199 | |
806 | 200 /* called by input plugin to peek at the output plugin's write progress */ |
201 gint | |
202 get_written_time(void) | |
203 { | |
204 OutputPlugin *op = get_current_output_plugin(); | |
205 | |
206 return op->written_time(); | |
207 } | |
208 | |
209 /* called by input plugin to peek at the output plugin's output progress */ | |
210 gint | |
211 get_output_time(void) | |
212 { | |
213 OutputPlugin *op = get_current_output_plugin(); | |
214 | |
215 return op->output_time(); | |
216 } | |
217 | |
0 | 218 /* called by input plugin when data is ready */ |
219 void | |
220 produce_audio(gint time, /* position */ | |
221 AFormat fmt, /* output format */ | |
222 gint nch, /* channels */ | |
223 gint length, /* length of sample */ | |
224 gpointer ptr, /* data */ | |
225 int *going /* 0 when time to stop */ | |
226 ) | |
227 { | |
228 static int init = 0; | |
229 int swapped = 0; | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
519
diff
changeset
|
230 guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; |
0 | 231 int caneq = (fmt == FMT_S16_NE || fmt == myorder); |
518 | 232 OutputPlugin *op = get_current_output_plugin(); |
0 | 233 |
234 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ | |
235 byteswap(length, ptr); /* so convert */ | |
236 ++swapped; | |
237 ++caneq; | |
238 } /* can eq now, mark swapd */ | |
239 else if (caneq && !cfg.equalizer_active) /* right order but no eq */ | |
240 caneq = 0; /* so don't eq */ | |
241 | |
242 if (caneq) { /* if eq enab */ | |
243 if (!init) { /* if first run */ | |
244 init_iir(); /* then init eq */ | |
245 ++init; | |
246 } | |
247 | |
430
67cd014f35a2
[svn] This commit rips out the old equalization engine with a dynamic engine
nenolod
parents:
0
diff
changeset
|
248 iir(&ptr, length, nch); |
0 | 249 |
250 if (swapped) /* if was swapped */ | |
251 byteswap(length, ptr); /* swap back for output */ | |
252 } | |
253 | |
518 | 254 /* do vis plugin(s) */ |
519
88e9a6a8336f
[svn] whoever wrote output_to_audio() was a crackhead.
nenolod
parents:
518
diff
changeset
|
255 input_add_vis_pcm(time, fmt, nch, length, ptr); |
0 | 256 |
518 | 257 while (op->buffer_free() < length) { /* wait output buf */ |
258 if (going && !*going) /* thread stopped? */ | |
259 return; /* so finish */ | |
260 | |
261 g_usleep(10000); /* else sleep for retry */ | |
262 } | |
263 | |
519
88e9a6a8336f
[svn] whoever wrote output_to_audio() was a crackhead.
nenolod
parents:
518
diff
changeset
|
264 op->write_audio(ptr, length); /* do output */ |
0 | 265 } |