Mercurial > audlegacy
annotate src/audacious/output.c @ 2574:40407b7363f3 trunk
[svn] - enforce playback stop when clearing the playlist to load new files in. closes #808.
| author | nenolod |
|---|---|
| date | Sun, 25 Feb 2007 00:53:19 -0800 |
| parents | ef01234ae265 |
| children | 51495131e4ae |
| 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" | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
35 #include "libaudacious/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; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
233 static void freeSRC() |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
234 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
235 if(src_state != NULL) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
236 src_state = src_delete(src_state); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
237 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
238 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
239 |
| 2313 | 240 gint |
| 241 output_open_audio(AFormat fmt, gint rate, gint nch) | |
| 242 { | |
| 243 gint ret; | |
| 244 OutputPlugin *op; | |
| 245 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
246 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
247 ConfigDb *db; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
248 gboolean src_enabled; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
249 gint src_rate, src_type; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
250 db = bmp_cfg_db_open(); |
|
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 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
|
253 src_enabled = FALSE; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
254 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
255 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
|
256 overSamplingFs = 48000; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
257 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
258 overSamplingFs = src_rate; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
259 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
260 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
|
261 converter_type = SRC_SINC_BEST_QUALITY; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
262 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
263 converter_type = src_type; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
264 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
265 bmp_cfg_db_close(db); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
266 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
267 freeSRC(); |
|
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(src_enabled&& |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
270 (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
|
271 (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
|
272 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
273 src_state = src_new(converter_type, nch, &srcError); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
274 if (src_state != NULL) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
275 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
276 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
277 rate = overSamplingFs; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
278 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
279 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
280 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
|
281 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
282 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
283 |
| 2313 | 284 op = get_current_output_plugin(); |
| 285 | |
| 286 if (op == NULL) | |
| 287 return -1; | |
| 288 | |
| 289 /* Is our output port already open? */ | |
| 290 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
|
291 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
| 2313 | 292 { |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
293 /* 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
|
294 op->flush(0); |
| 2313 | 295 return 1; |
| 296 } | |
| 297 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
|
298 op->close_audio(); |
| 2313 | 299 |
| 300 ret = op->open_audio(fmt, rate, nch); | |
| 301 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
302 if (ret == 1) /* Success? */ |
| 2313 | 303 { |
| 304 op_state.fmt = fmt; | |
| 305 op_state.rate = rate; | |
| 306 op_state.nch = nch; | |
| 307 } | |
| 308 | |
| 309 return ret; | |
| 310 } | |
| 311 | |
| 312 void | |
| 313 output_write_audio(gpointer ptr, gint length) | |
| 314 { | |
| 315 OutputPlugin *op = get_current_output_plugin(); | |
| 316 | |
| 317 /* Sanity check. */ | |
| 318 if (op == NULL) | |
| 319 return; | |
| 320 | |
| 321 op->write_audio(ptr, length); | |
| 322 } | |
| 323 | |
| 324 void | |
| 325 output_close_audio(void) | |
| 326 { | |
| 327 OutputPlugin *op = get_current_output_plugin(); | |
| 328 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
329 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
330 freeSRC(); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
331 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
332 |
| 2313 | 333 /* Do not close if there are still songs to play and the user has |
| 334 * not requested a stop. --nenolod | |
| 335 */ | |
| 336 if (ip_data.stop == FALSE && | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
337 (playlist_get_position_nolock(playlist_get_active()) < playlist_get_length_nolock(playlist_get_active()) - 1)) |
| 2313 | 338 return; |
| 339 | |
| 340 /* Sanity check. */ | |
| 341 if (op == NULL) | |
| 342 return; | |
| 343 | |
| 344 op->close_audio(); | |
| 345 | |
| 346 /* Reset the op_state. */ | |
| 347 op_state.fmt = op_state.rate = op_state.nch = 0; | |
| 348 } | |
| 349 | |
| 350 void | |
| 351 output_flush(gint time) | |
| 352 { | |
| 353 OutputPlugin *op = get_current_output_plugin(); | |
| 354 | |
| 355 if (op == NULL) | |
| 356 return; | |
| 357 | |
| 358 op->flush(time); | |
| 359 } | |
| 360 | |
| 361 void | |
| 362 output_pause(gshort paused) | |
| 363 { | |
| 364 OutputPlugin *op = get_current_output_plugin(); | |
| 365 | |
| 366 if (op == NULL) | |
| 367 return; | |
| 368 | |
| 369 op->pause(paused); | |
| 370 } | |
| 371 | |
| 372 gint | |
| 373 output_buffer_free(void) | |
| 374 { | |
| 375 OutputPlugin *op = get_current_output_plugin(); | |
| 376 | |
| 377 if (op == NULL) | |
| 378 return 0; | |
| 379 | |
| 380 return op->buffer_free(); | |
| 381 } | |
| 382 | |
| 383 gint | |
| 384 output_buffer_playing(void) | |
| 385 { | |
| 386 OutputPlugin *op = get_current_output_plugin(); | |
| 387 | |
| 388 if (op == NULL) | |
| 389 return 0; | |
| 390 | |
| 391 return op->buffer_playing(); | |
| 392 } | |
| 393 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
394 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
395 static float *srcIn = NULL, *srcOut = NULL; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
396 static short int *wOut = NULL; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
397 static gboolean isSrcAlloc = FALSE; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
398 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
399 |
| 2313 | 400 /* called by input plugin when data is ready */ |
| 401 void | |
| 402 produce_audio(gint time, /* position */ | |
| 403 AFormat fmt, /* output format */ | |
| 404 gint nch, /* channels */ | |
| 405 gint length, /* length of sample */ | |
| 406 gpointer ptr, /* data */ | |
| 407 int *going /* 0 when time to stop */ | |
| 408 ) | |
| 409 { | |
| 410 static int init = 0; | |
| 411 int swapped = 0; | |
| 412 guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; | |
| 413 int caneq = (fmt == FMT_S16_NE || fmt == myorder); | |
| 414 OutputPlugin *op = get_current_output_plugin(); | |
| 415 int writeoffs; | |
| 416 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
417 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
418 if(isSrcAlloc == TRUE) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
419 { |
| 2542 | 420 g_free(srcIn); |
| 421 g_free(srcOut); | |
| 422 g_free(wOut); | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
423 isSrcAlloc = FALSE; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
424 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
425 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
426 if(src_state != NULL&&length > 0) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
427 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
428 int lrLength = length/2; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
429 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
| 2542 | 430 srcIn = (float*) g_malloc(sizeof(float)*lrLength); |
| 431 srcOut = (float*) g_malloc(sizeof(float)*overLrLength); | |
| 432 wOut = (short int*) g_malloc(sizeof(short int)*overLrLength); | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
433 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
|
434 isSrcAlloc = TRUE; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
435 src_data.data_in = srcIn; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
436 src_data.data_out = srcOut; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
437 src_data.end_of_input = 0; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
438 src_data.input_frames = lrLength/2; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
439 src_data.output_frames = overLrLength/2; |
| 2542 | 440 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
|
441 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
442 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
|
443 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
444 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
445 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
446 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
|
447 ptr = wOut; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
448 length = src_data.output_frames_gen*4; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
449 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
450 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
451 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
452 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
453 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
454 byteswap(length, ptr); /* so convert */ |
| 2313 | 455 ++swapped; |
| 456 ++caneq; | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
457 } /* can eq now, mark swapd */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
458 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
|
459 caneq = 0; /* so don't eq */ |
| 2313 | 460 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
461 if (caneq) { /* if eq enab */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
462 if (!init) { /* if first run */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
463 init_iir(); /* then init eq */ |
| 2313 | 464 ++init; |
| 465 } | |
| 466 | |
| 467 iir(&ptr, length, nch); | |
| 468 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
469 if (swapped) /* if was swapped */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
470 byteswap(length, ptr); /* swap back for output */ |
| 2313 | 471 } |
| 472 | |
| 473 /* do vis plugin(s) */ | |
| 474 input_add_vis_pcm(time, fmt, nch, length, ptr); | |
| 475 | |
| 476 writeoffs = 0; | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
477 while (writeoffs < length) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
478 { |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
479 int writable = length - writeoffs; |
| 2313 | 480 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
481 if (writable > 2048) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
482 writable = 2048; |
| 2313 | 483 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
484 if (writable == 0) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
485 return; |
| 2313 | 486 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
487 while (op->buffer_free() < writable) { /* wait output buf */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
488 if (going && !*going) /* thread stopped? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
489 return; /* so finish */ |
| 2313 | 490 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
491 if (ip_data.stop) /* has a stop been requested? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
492 return; /* yes, so finish */ |
| 2313 | 493 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
494 g_usleep(10000); /* else sleep for retry */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
495 } |
| 2313 | 496 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
497 if (ip_data.stop) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
498 return; |
| 2313 | 499 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
500 if (going && !*going) /* thread stopped? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
501 return; /* so finish */ |
| 2313 | 502 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
503 /* do output */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
504 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
| 2313 | 505 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
506 writeoffs += writable; |
| 2313 | 507 } |
| 508 } |
