Mercurial > audlegacy
annotate src/audacious/output.c @ 2771:4585019eb82e trunk
[svn] -Renamed MPRIS /TrackList Shuffle method to Random
-Added stubs for the MPRIS /Player signals
-Added stubs for the MPRIS /TrackList methods (implemented AddTrack)
-Modified build system to be more ignorant of DBus support
author | magma |
---|---|
date | Tue, 15 May 2007 21:53:37 -0700 |
parents | 6884a2144a01 |
children | 1c7ee5ed3a10 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 2 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #include "output.h" | |
29 #include "iir.h" | |
30 #include "main.h" | |
31 #include "input.h" | |
2328 | 32 #include "playback.h" |
2313 | 33 |
34 #include "playlist.h" | |
2717 | 35 #include "configdb.h" |
2542 | 36 |
37 #include <math.h> | |
38 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
39 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
40 #include <samplerate.h> |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
41 #endif |
2313 | 42 |
43 OutputPluginData op_data = { | |
44 NULL, | |
45 NULL | |
46 }; | |
47 | |
48 OutputPluginState op_state = { | |
49 0, | |
50 0, | |
51 0 | |
52 }; | |
53 | |
54 OutputPlugin psuedo_output_plugin = { | |
55 NULL, | |
56 NULL, | |
57 "XMMS reverse compatibility output plugin", | |
58 NULL, | |
59 NULL, | |
60 NULL, | |
61 NULL, | |
62 output_get_volume, | |
63 output_set_volume, | |
64 output_open_audio, | |
65 output_write_audio, | |
66 output_close_audio, | |
67 | |
68 output_flush, | |
69 output_pause, | |
70 output_buffer_free, | |
71 output_buffer_playing, | |
72 get_output_time, | |
73 get_written_time, | |
74 NULL | |
75 }; | |
76 | |
77 OutputPlugin * | |
78 get_current_output_plugin(void) | |
79 { | |
80 return op_data.current_output_plugin; | |
81 } | |
82 | |
83 void | |
84 set_current_output_plugin(gint i) | |
85 { | |
86 gboolean playing; | |
87 OutputPlugin *op = get_current_output_plugin(); | |
88 | |
89 GList *node = g_list_nth(op_data.output_list, i); | |
90 if (!node) { | |
91 op_data.current_output_plugin = NULL; | |
92 return; | |
93 } | |
94 | |
95 op_data.current_output_plugin = node->data; | |
96 | |
97 playing = playback_get_playing(); | |
98 | |
99 if (playing == TRUE) | |
100 { | |
101 guint time, pos; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
102 PlaylistEntry *entry; |
2313 | 103 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
104 /* don't stop yet, get the seek time and playlist position first */ |
2313 | 105 pos = playlist_get_position(playlist_get_active()); |
106 time = op->output_time(); | |
107 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
108 /* reset the audio system */ |
2313 | 109 mainwin_stop_pushed(); |
110 op->close_audio(); | |
111 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
112 g_usleep(300000); |
2313 | 113 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
114 /* wait for the playback thread to come online */ |
2313 | 115 while (playback_get_playing()) |
116 g_message("waiting for audio system shutdown..."); | |
117 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
118 /* wait for the playback thread to come online */ |
2313 | 119 playlist_set_position(playlist_get_active(), pos); |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
120 entry = playlist_get_entry_to_play(playlist_get_active()); |
2313 | 121 playback_play_file(entry); |
122 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
123 while (!playback_get_playing()) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
124 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
125 gtk_main_iteration(); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
126 g_message("waiting for audio system startup..."); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
127 } |
2313 | 128 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
129 /* and signal a reseek */ |
2313 | 130 if (playlist_get_current_length(playlist_get_active()) > -1 && |
131 time <= (playlist_get_current_length(playlist_get_active()))) | |
132 playback_seek(time / 1000); | |
133 } | |
134 } | |
135 | |
136 GList * | |
137 get_output_list(void) | |
138 { | |
139 return op_data.output_list; | |
140 } | |
141 | |
142 void | |
143 output_about(gint i) | |
144 { | |
145 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
146 if (out && out->about) | |
147 out->about(); | |
148 } | |
149 | |
150 void | |
151 output_configure(gint i) | |
152 { | |
153 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
154 if (out && out->configure) | |
155 out->configure(); | |
156 } | |
157 | |
158 void | |
159 output_get_volume(gint * l, gint * r) | |
160 { | |
161 *l = *r = -1; | |
162 | |
163 if (!op_data.current_output_plugin) | |
164 return; | |
165 | |
166 if (!op_data.current_output_plugin->get_volume) | |
167 return; | |
168 | |
169 op_data.current_output_plugin->get_volume(l, r); | |
170 } | |
171 | |
172 void | |
173 output_set_volume(gint l, gint r) | |
174 { | |
175 if (!op_data.current_output_plugin) | |
176 return; | |
177 | |
178 if (!op_data.current_output_plugin->set_volume) | |
179 return; | |
180 | |
181 op_data.current_output_plugin->set_volume(l, r); | |
182 } | |
183 | |
184 void | |
185 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
186 { | |
187 int i; | |
188 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
189 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
190 | |
191 for (i = 0; i < 10; ++i) | |
192 { | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
193 set_gain(i, 0, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
194 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
2313 | 195 } |
196 } | |
197 | |
198 /* this should be in BYTES, NOT gint16s */ | |
199 static void | |
200 byteswap(size_t size, | |
201 gint16 * buf) | |
202 { | |
203 gint16 *it; | |
204 size &= ~1; /* must be multiple of 2 */ | |
205 for (it = buf; it < buf + size / 2; ++it) | |
206 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it); | |
207 } | |
208 | |
209 /* called by input plugin to peek at the output plugin's write progress */ | |
210 gint | |
211 get_written_time(void) | |
212 { | |
213 OutputPlugin *op = get_current_output_plugin(); | |
214 | |
215 return op->written_time(); | |
216 } | |
217 | |
218 /* called by input plugin to peek at the output plugin's output progress */ | |
219 gint | |
220 get_output_time(void) | |
221 { | |
222 OutputPlugin *op = get_current_output_plugin(); | |
223 | |
224 return op->output_time(); | |
225 } | |
226 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
227 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
228 static SRC_STATE *src_state; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
229 static SRC_DATA src_data; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
230 static int overSamplingFs = 96000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
231 static int converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
232 static int srcError = 0; |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
233 |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
234 static float *srcIn = NULL, *srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
235 static short int *wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
236 static int lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
237 static int lengthOfSrcOut = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
238 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
239 static void freeSRC() |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
240 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
241 if(src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
242 src_state = src_delete(src_state); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
243 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
244 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
245 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
246 srcIn = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
247 srcOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
248 wOut = NULL; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
249 lengthOfSrcIn = 0; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
250 lengthOfSrcOut = 0; |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
251 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
252 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
253 |
2313 | 254 gint |
255 output_open_audio(AFormat fmt, gint rate, gint nch) | |
256 { | |
257 gint ret; | |
258 OutputPlugin *op; | |
259 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
260 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
261 ConfigDb *db; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
262 gboolean src_enabled; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
263 gint src_rate, src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
264 db = bmp_cfg_db_open(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
265 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
266 if (bmp_cfg_db_get_bool(db, NULL, "enable_src", &src_enabled) == FALSE) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
267 src_enabled = FALSE; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
268 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
269 if (bmp_cfg_db_get_int(db, NULL, "src_rate", &src_rate) == FALSE) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
270 overSamplingFs = 48000; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
271 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
272 overSamplingFs = src_rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
273 |
2649
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
274 /* don't resample if sampling rates are the same --nenolod */ |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
275 if (rate == overSamplingFs) |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
276 src_enabled = FALSE; |
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
277 |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
278 if (bmp_cfg_db_get_int(db, NULL, "src_type", &src_type) == FALSE) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
279 converter_type = SRC_SINC_BEST_QUALITY; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
280 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
281 converter_type = src_type; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
282 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
283 bmp_cfg_db_close(db); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
284 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
285 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
286 |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
287 if(src_enabled&& |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
288 (fmt == FMT_S16_NE||(fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN)|| |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
289 (fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN))) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
290 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
291 src_state = src_new(converter_type, nch, &srcError); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
292 if (src_state != NULL) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
293 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
294 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
295 rate = overSamplingFs; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
296 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
297 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
298 fprintf(stderr, "src_new(): %s\n\n", src_strerror(srcError)); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
299 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
300 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
301 |
2313 | 302 op = get_current_output_plugin(); |
303 | |
304 if (op == NULL) | |
305 return -1; | |
306 | |
307 /* Is our output port already open? */ | |
308 if ((op_state.rate != 0 && op_state.nch != 0) && | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
309 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
2313 | 310 { |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
311 /* Yes, and it's the correct sampling rate. Reset the counter and go. */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
312 op->flush(0); |
2313 | 313 return 1; |
314 } | |
315 else if (op_state.rate != 0 && op_state.nch != 0) | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
316 op->close_audio(); |
2313 | 317 |
318 ret = op->open_audio(fmt, rate, nch); | |
319 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
320 if (ret == 1) /* Success? */ |
2313 | 321 { |
322 op_state.fmt = fmt; | |
323 op_state.rate = rate; | |
324 op_state.nch = nch; | |
325 } | |
326 | |
327 return ret; | |
328 } | |
329 | |
330 void | |
331 output_write_audio(gpointer ptr, gint length) | |
332 { | |
333 OutputPlugin *op = get_current_output_plugin(); | |
334 | |
335 /* Sanity check. */ | |
336 if (op == NULL) | |
337 return; | |
338 | |
339 op->write_audio(ptr, length); | |
340 } | |
341 | |
342 void | |
343 output_close_audio(void) | |
344 { | |
345 OutputPlugin *op = get_current_output_plugin(); | |
346 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
347 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
348 freeSRC(); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
349 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
350 |
2313 | 351 /* Do not close if there are still songs to play and the user has |
352 * not requested a stop. --nenolod | |
353 */ | |
354 if (ip_data.stop == FALSE && | |
2673 | 355 (playlist_get_position_nolock(playlist_get_active()) < |
356 playlist_get_length(playlist_get_active()) - 1)) | |
2313 | 357 return; |
358 | |
359 /* Sanity check. */ | |
360 if (op == NULL) | |
361 return; | |
362 | |
363 op->close_audio(); | |
364 | |
365 /* Reset the op_state. */ | |
366 op_state.fmt = op_state.rate = op_state.nch = 0; | |
367 } | |
368 | |
369 void | |
370 output_flush(gint time) | |
371 { | |
372 OutputPlugin *op = get_current_output_plugin(); | |
373 | |
374 if (op == NULL) | |
375 return; | |
376 | |
377 op->flush(time); | |
378 } | |
379 | |
380 void | |
381 output_pause(gshort paused) | |
382 { | |
383 OutputPlugin *op = get_current_output_plugin(); | |
384 | |
385 if (op == NULL) | |
386 return; | |
387 | |
388 op->pause(paused); | |
389 } | |
390 | |
391 gint | |
392 output_buffer_free(void) | |
393 { | |
394 OutputPlugin *op = get_current_output_plugin(); | |
395 | |
396 if (op == NULL) | |
397 return 0; | |
398 | |
399 return op->buffer_free(); | |
400 } | |
401 | |
402 gint | |
403 output_buffer_playing(void) | |
404 { | |
405 OutputPlugin *op = get_current_output_plugin(); | |
406 | |
407 if (op == NULL) | |
408 return 0; | |
409 | |
410 return op->buffer_playing(); | |
411 } | |
412 | |
413 /* called by input plugin when data is ready */ | |
414 void | |
415 produce_audio(gint time, /* position */ | |
416 AFormat fmt, /* output format */ | |
417 gint nch, /* channels */ | |
418 gint length, /* length of sample */ | |
419 gpointer ptr, /* data */ | |
420 int *going /* 0 when time to stop */ | |
421 ) | |
422 { | |
423 static int init = 0; | |
424 int swapped = 0; | |
425 guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; | |
426 int caneq = (fmt == FMT_S16_NE || fmt == myorder); | |
427 OutputPlugin *op = get_current_output_plugin(); | |
428 int writeoffs; | |
429 | |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
430 #ifdef USE_SRC |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
431 if(src_state != NULL&&length > 0) |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
432 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
433 int lrLength = length/2; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
434 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
435 if(lengthOfSrcIn < lrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
436 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
437 lengthOfSrcIn = lrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
438 free(srcIn); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
439 srcIn = (float*)malloc(sizeof(float)*lrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
440 } |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
441 if(lengthOfSrcOut < overLrLength) |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
442 { |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
443 lengthOfSrcOut = overLrLength; |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
444 free(srcOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
445 free(wOut); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
446 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
447 wOut = (short int*)malloc(sizeof(short int)*overLrLength); |
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
448 } |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
449 src_short_to_float_array((short int*)ptr, srcIn, lrLength); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
450 src_data.data_in = srcIn; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
451 src_data.data_out = srcOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
452 src_data.end_of_input = 0; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
453 src_data.input_frames = lrLength/2; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
454 src_data.output_frames = overLrLength/2; |
2542 | 455 if ((srcError = src_process(src_state, &src_data)) > 0) |
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
456 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
457 fprintf(stderr, "src_process(): %s\n", src_strerror(srcError)); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
458 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
459 else |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
460 { |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
461 src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2); |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
462 ptr = wOut; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
463 length = src_data.output_frames_gen*4; |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
464 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
465 } |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
466 #endif |
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
467 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
468 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
469 byteswap(length, ptr); /* so convert */ |
2313 | 470 ++swapped; |
471 ++caneq; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
472 } /* can eq now, mark swapd */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
473 else if (caneq && !cfg.equalizer_active) /* right order but no eq */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
474 caneq = 0; /* so don't eq */ |
2313 | 475 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
476 if (caneq) { /* if eq enab */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
477 if (!init) { /* if first run */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
478 init_iir(); /* then init eq */ |
2313 | 479 ++init; |
480 } | |
481 | |
482 iir(&ptr, length, nch); | |
483 | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
484 if (swapped) /* if was swapped */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
485 byteswap(length, ptr); /* swap back for output */ |
2313 | 486 } |
487 | |
488 /* do vis plugin(s) */ | |
489 input_add_vis_pcm(time, fmt, nch, length, ptr); | |
490 | |
491 writeoffs = 0; | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
492 while (writeoffs < length) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
493 { |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
494 int writable = length - writeoffs; |
2313 | 495 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
496 if (writable > 2048) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
497 writable = 2048; |
2313 | 498 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
499 if (writable == 0) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
500 return; |
2313 | 501 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
502 while (op->buffer_free() < writable) { /* wait output buf */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
503 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
504 return; /* so finish */ |
2313 | 505 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
506 if (ip_data.stop) /* has a stop been requested? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
507 return; /* yes, so finish */ |
2313 | 508 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
509 g_usleep(10000); /* else sleep for retry */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
510 } |
2313 | 511 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
512 if (ip_data.stop) |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
513 return; |
2313 | 514 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
515 if (going && !*going) /* thread stopped? */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
516 return; /* so finish */ |
2313 | 517 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
518 /* do output */ |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
519 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
2313 | 520 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
521 writeoffs += writable; |
2313 | 522 } |
523 } |