comparison audacious/output.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children 67cd014f35a2
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
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;
155 preamp = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre;
156 for (i = 0; i < 10; ++i)
157 gain[i] = 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i];
158 }
159
160 /* this should be in BYTES, NOT gint16s */
161 static void
162 byteswap(size_t size,
163 gint16 * buf)
164 {
165 gint16 *it;
166 size &= ~1; /* must be multiple of 2 */
167 for (it = buf; it < buf + size / 2; ++it)
168 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it);
169 }
170
171 static void
172 output_to_plugin(gint time,
173 AFormat format,
174 gint n_channels,
175 gint length,
176 gpointer sample,
177 int *going)
178 {
179 OutputPlugin *op = get_current_output_plugin();
180
181 /* do vis plugin(s) */
182 input_add_vis_pcm(time, format, n_channels, length, sample);
183
184 while (op->buffer_free() < length) { /* wait output buf */
185 if (going && !*going) /* thread stopped? */
186 return; /* so finish */
187
188 g_usleep(10000); /* else sleep for retry */
189 }
190
191 op->write_audio(sample, length); /* do output */
192 }
193
194
195
196 /* called by input plugin when data is ready */
197 void
198 produce_audio(gint time, /* position */
199 AFormat fmt, /* output format */
200 gint nch, /* channels */
201 gint length, /* length of sample */
202 gpointer ptr, /* data */
203 int *going /* 0 when time to stop */
204 )
205 {
206 #ifndef XMMS_EQ
207
208 static int init = 0;
209 int swapped = 0;
210 int myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE;
211 int caneq = (fmt == FMT_S16_NE || fmt == myorder);
212
213 if (!caneq && cfg.equalizer_active) { /* wrong byte order */
214 byteswap(length, ptr); /* so convert */
215 ++swapped;
216 ++caneq;
217 } /* can eq now, mark swapd */
218 else if (caneq && !cfg.equalizer_active) /* right order but no eq */
219 caneq = 0; /* so don't eq */
220
221 if (caneq) { /* if eq enab */
222 if (!init) { /* if first run */
223 init_iir(); /* then init eq */
224 ++init;
225 }
226
227 iir(&ptr, length); /* do iir */
228
229 if (swapped) /* if was swapped */
230 byteswap(length, ptr); /* swap back for output */
231 }
232
233 #endif
234
235 output_to_plugin(time, fmt, nch, length, ptr, going);
236 }