Mercurial > audlegacy
annotate src/audacious/output.c @ 3016:e84073b61ba5 trunk
fix tinyplayer skin
| author | Tomasz Mon <desowin@gmail.com> |
|---|---|
| date | Mon, 09 Jul 2007 13:02:50 +0200 |
| parents | 49f3d1b43518 |
| children | 3b6d316f8b09 |
| 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 |
|
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
37 #include "effect.h" |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
38 |
| 2542 | 39 #include <math.h> |
| 40 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
41 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
42 #include <samplerate.h> |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
43 #endif |
| 2313 | 44 |
| 45 OutputPluginData op_data = { | |
| 46 NULL, | |
| 47 NULL | |
| 48 }; | |
| 49 | |
| 50 OutputPluginState op_state = { | |
| 51 0, | |
| 52 0, | |
| 53 0 | |
| 54 }; | |
| 55 | |
| 56 OutputPlugin psuedo_output_plugin = { | |
| 57 NULL, | |
| 58 NULL, | |
| 59 "XMMS reverse compatibility output plugin", | |
| 60 NULL, | |
| 61 NULL, | |
| 62 NULL, | |
| 63 NULL, | |
| 64 output_get_volume, | |
| 65 output_set_volume, | |
| 66 output_open_audio, | |
| 67 output_write_audio, | |
| 68 output_close_audio, | |
| 69 | |
| 70 output_flush, | |
| 71 output_pause, | |
| 72 output_buffer_free, | |
| 73 output_buffer_playing, | |
| 74 get_output_time, | |
| 75 get_written_time, | |
| 76 NULL | |
| 77 }; | |
| 78 | |
| 79 OutputPlugin * | |
| 80 get_current_output_plugin(void) | |
| 81 { | |
| 82 return op_data.current_output_plugin; | |
| 83 } | |
| 84 | |
| 85 void | |
| 86 set_current_output_plugin(gint i) | |
| 87 { | |
| 88 gboolean playing; | |
| 89 OutputPlugin *op = get_current_output_plugin(); | |
| 90 | |
| 91 GList *node = g_list_nth(op_data.output_list, i); | |
| 92 if (!node) { | |
| 93 op_data.current_output_plugin = NULL; | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 op_data.current_output_plugin = node->data; | |
| 98 | |
| 99 playing = playback_get_playing(); | |
| 100 | |
| 101 if (playing == TRUE) | |
| 102 { | |
| 103 guint time, pos; | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
104 PlaylistEntry *entry; |
| 2313 | 105 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
106 /* don't stop yet, get the seek time and playlist position first */ |
| 2313 | 107 pos = playlist_get_position(playlist_get_active()); |
| 108 time = op->output_time(); | |
| 109 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
110 /* reset the audio system */ |
| 2313 | 111 mainwin_stop_pushed(); |
| 112 op->close_audio(); | |
| 113 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
114 g_usleep(300000); |
| 2313 | 115 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
116 /* wait for the playback thread to come online */ |
| 2313 | 117 while (playback_get_playing()) |
| 118 g_message("waiting for audio system shutdown..."); | |
| 119 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
120 /* wait for the playback thread to come online */ |
| 2313 | 121 playlist_set_position(playlist_get_active(), pos); |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
122 entry = playlist_get_entry_to_play(playlist_get_active()); |
| 2313 | 123 playback_play_file(entry); |
| 124 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
125 while (!playback_get_playing()) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
126 { |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
127 gtk_main_iteration(); |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
128 g_message("waiting for audio system startup..."); |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
129 } |
| 2313 | 130 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
131 /* and signal a reseek */ |
| 2313 | 132 if (playlist_get_current_length(playlist_get_active()) > -1 && |
| 133 time <= (playlist_get_current_length(playlist_get_active()))) | |
| 134 playback_seek(time / 1000); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 GList * | |
| 139 get_output_list(void) | |
| 140 { | |
| 141 return op_data.output_list; | |
| 142 } | |
| 143 | |
| 144 void | |
| 145 output_about(gint i) | |
| 146 { | |
| 147 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
| 148 if (out && out->about) | |
| 149 out->about(); | |
| 150 } | |
| 151 | |
| 152 void | |
| 153 output_configure(gint i) | |
| 154 { | |
| 155 OutputPlugin *out = g_list_nth(op_data.output_list, i)->data; | |
| 156 if (out && out->configure) | |
| 157 out->configure(); | |
| 158 } | |
| 159 | |
| 160 void | |
| 161 output_get_volume(gint * l, gint * r) | |
| 162 { | |
| 163 *l = *r = -1; | |
| 164 | |
| 165 if (!op_data.current_output_plugin) | |
| 166 return; | |
| 167 | |
| 168 if (!op_data.current_output_plugin->get_volume) | |
| 169 return; | |
| 170 | |
| 171 op_data.current_output_plugin->get_volume(l, r); | |
| 172 } | |
| 173 | |
| 174 void | |
| 175 output_set_volume(gint l, gint r) | |
| 176 { | |
| 177 if (!op_data.current_output_plugin) | |
| 178 return; | |
| 179 | |
| 180 if (!op_data.current_output_plugin->set_volume) | |
| 181 return; | |
| 182 | |
| 183 op_data.current_output_plugin->set_volume(l, r); | |
| 184 } | |
| 185 | |
| 186 void | |
| 187 output_set_eq(gboolean active, gfloat pre, gfloat * bands) | |
| 188 { | |
| 189 int i; | |
| 190 preamp[0] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
| 191 preamp[1] = 1.0 + 0.0932471 * pre + 0.00279033 * pre * pre; | |
| 192 | |
| 193 for (i = 0; i < 10; ++i) | |
| 194 { | |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
195 set_gain(i, 0, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
|
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
196 set_gain(i, 1, 0.03 * bands[i] + 0.000999999 * bands[i] * bands[i]); |
| 2313 | 197 } |
| 198 } | |
| 199 | |
| 200 /* this should be in BYTES, NOT gint16s */ | |
| 201 static void | |
| 202 byteswap(size_t size, | |
| 203 gint16 * buf) | |
| 204 { | |
| 205 gint16 *it; | |
| 206 size &= ~1; /* must be multiple of 2 */ | |
| 207 for (it = buf; it < buf + size / 2; ++it) | |
| 208 *(guint16 *) it = GUINT16_SWAP_LE_BE(*(guint16 *) it); | |
| 209 } | |
| 210 | |
| 211 /* called by input plugin to peek at the output plugin's write progress */ | |
| 212 gint | |
| 213 get_written_time(void) | |
| 214 { | |
| 215 OutputPlugin *op = get_current_output_plugin(); | |
| 216 | |
| 217 return op->written_time(); | |
| 218 } | |
| 219 | |
| 220 /* called by input plugin to peek at the output plugin's output progress */ | |
| 221 gint | |
| 222 get_output_time(void) | |
| 223 { | |
| 224 OutputPlugin *op = get_current_output_plugin(); | |
| 225 | |
| 226 return op->output_time(); | |
| 227 } | |
| 228 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
229 #ifdef USE_SRC |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
230 |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
231 static SRC_STATE *src_state; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
232 static SRC_DATA src_data; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
233 static int overSamplingFs = 96000; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
234 static int converter_type = SRC_SINC_BEST_QUALITY; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
235 static int srcError = 0; |
|
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
236 |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
237 static float *srcIn = NULL, *srcOut = NULL; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
238 static short int *wOut = NULL; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
239 static int lengthOfSrcIn = 0; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
240 static int lengthOfSrcOut = 0; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
241 |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
242 static void freeSRC() |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
243 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
244 if(src_state != NULL) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
245 src_state = src_delete(src_state); |
|
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
246 free(srcIn); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
247 free(srcOut); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
248 free(wOut); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
249 srcIn = NULL; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
250 srcOut = NULL; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
251 wOut = NULL; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
252 lengthOfSrcIn = 0; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
253 lengthOfSrcOut = 0; |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
254 } |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
255 |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
256 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
257 |
| 2313 | 258 gint |
| 259 output_open_audio(AFormat fmt, gint rate, gint nch) | |
| 260 { | |
| 261 gint ret; | |
| 262 OutputPlugin *op; | |
| 263 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
264 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
265 ConfigDb *db; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
266 gboolean src_enabled; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
267 gint src_rate, src_type; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
268 db = bmp_cfg_db_open(); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
269 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
270 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
|
271 src_enabled = FALSE; |
|
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 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
|
274 overSamplingFs = 48000; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
275 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
276 overSamplingFs = src_rate; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
277 |
|
2649
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
278 /* 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
|
279 if (rate == overSamplingFs) |
|
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
280 src_enabled = FALSE; |
|
153dc928115a
[svn] - don't resample if source rate matches the internal clock rate. closes #881.
nenolod
parents:
2648
diff
changeset
|
281 |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
282 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
|
283 converter_type = SRC_SINC_BEST_QUALITY; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
284 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
285 converter_type = src_type; |
|
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 bmp_cfg_db_close(db); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
288 |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
289 freeSRC(); |
|
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 if(src_enabled&& |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
292 (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
|
293 (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
|
294 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
295 src_state = src_new(converter_type, nch, &srcError); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
296 if (src_state != NULL) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
297 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
298 src_data.src_ratio = (float)overSamplingFs/(float)rate; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
299 rate = overSamplingFs; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
300 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
301 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
302 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
|
303 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
304 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
305 |
| 2313 | 306 op = get_current_output_plugin(); |
| 307 | |
| 308 if (op == NULL) | |
| 309 return -1; | |
| 310 | |
| 311 /* Is our output port already open? */ | |
| 312 if ((op_state.rate != 0 && op_state.nch != 0) && | |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
313 (op_state.rate == rate && op_state.nch == nch && op_state.fmt == fmt)) |
| 2313 | 314 { |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
315 /* Yes, and it's the correct sampling rate. Reset the counter and go. */ |
|
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
316 op->flush(0); |
| 2313 | 317 return 1; |
| 318 } | |
| 319 else if (op_state.rate != 0 && op_state.nch != 0) | |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
320 op->close_audio(); |
| 2313 | 321 |
| 322 ret = op->open_audio(fmt, rate, nch); | |
| 323 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
324 if (ret == 1) /* Success? */ |
| 2313 | 325 { |
| 326 op_state.fmt = fmt; | |
| 327 op_state.rate = rate; | |
| 328 op_state.nch = nch; | |
| 329 } | |
| 330 | |
| 331 return ret; | |
| 332 } | |
| 333 | |
| 334 void | |
| 335 output_write_audio(gpointer ptr, gint length) | |
| 336 { | |
| 337 OutputPlugin *op = get_current_output_plugin(); | |
| 338 | |
| 339 /* Sanity check. */ | |
| 340 if (op == NULL) | |
| 341 return; | |
| 342 | |
| 343 op->write_audio(ptr, length); | |
| 344 } | |
| 345 | |
| 346 void | |
| 347 output_close_audio(void) | |
| 348 { | |
| 349 OutputPlugin *op = get_current_output_plugin(); | |
| 350 | |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
351 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
352 freeSRC(); |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
353 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
354 |
| 2313 | 355 /* Do not close if there are still songs to play and the user has |
| 356 * not requested a stop. --nenolod | |
| 357 */ | |
| 358 if (ip_data.stop == FALSE && | |
| 2673 | 359 (playlist_get_position_nolock(playlist_get_active()) < |
| 360 playlist_get_length(playlist_get_active()) - 1)) | |
| 2313 | 361 return; |
| 362 | |
| 363 /* Sanity check. */ | |
| 364 if (op == NULL) | |
| 365 return; | |
| 366 | |
| 367 op->close_audio(); | |
| 368 | |
| 369 /* Reset the op_state. */ | |
| 370 op_state.fmt = op_state.rate = op_state.nch = 0; | |
| 371 } | |
| 372 | |
| 373 void | |
| 374 output_flush(gint time) | |
| 375 { | |
| 376 OutputPlugin *op = get_current_output_plugin(); | |
| 377 | |
| 378 if (op == NULL) | |
| 379 return; | |
| 380 | |
| 381 op->flush(time); | |
| 382 } | |
| 383 | |
| 384 void | |
| 385 output_pause(gshort paused) | |
| 386 { | |
| 387 OutputPlugin *op = get_current_output_plugin(); | |
| 388 | |
| 389 if (op == NULL) | |
| 390 return; | |
| 391 | |
| 392 op->pause(paused); | |
| 393 } | |
| 394 | |
| 395 gint | |
| 396 output_buffer_free(void) | |
| 397 { | |
| 398 OutputPlugin *op = get_current_output_plugin(); | |
| 399 | |
| 400 if (op == NULL) | |
| 401 return 0; | |
| 402 | |
| 403 return op->buffer_free(); | |
| 404 } | |
| 405 | |
| 406 gint | |
| 407 output_buffer_playing(void) | |
| 408 { | |
| 409 OutputPlugin *op = get_current_output_plugin(); | |
| 410 | |
| 411 if (op == NULL) | |
| 412 return 0; | |
| 413 | |
| 414 return op->buffer_playing(); | |
| 415 } | |
| 416 | |
| 417 /* called by input plugin when data is ready */ | |
| 418 void | |
| 419 produce_audio(gint time, /* position */ | |
| 420 AFormat fmt, /* output format */ | |
| 421 gint nch, /* channels */ | |
| 422 gint length, /* length of sample */ | |
| 423 gpointer ptr, /* data */ | |
| 424 int *going /* 0 when time to stop */ | |
| 425 ) | |
| 426 { | |
| 427 static int init = 0; | |
| 428 int swapped = 0; | |
| 429 guint myorder = G_BYTE_ORDER == G_LITTLE_ENDIAN ? FMT_S16_LE : FMT_S16_BE; | |
| 430 int caneq = (fmt == FMT_S16_NE || fmt == myorder); | |
| 431 OutputPlugin *op = get_current_output_plugin(); | |
|
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
432 EffectPlugin *ep = get_current_effect_plugin(); |
| 2313 | 433 int writeoffs; |
|
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
434 AFormat new_format; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
435 gint new_rate; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
436 gint new_nch; |
| 2313 | 437 |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
438 #ifdef USE_SRC |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
439 if(src_state != NULL&&length > 0) |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
440 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
441 int lrLength = length/2; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
442 int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1)); |
|
2648
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
443 if(lengthOfSrcIn < lrLength) |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
444 { |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
445 lengthOfSrcIn = lrLength; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
446 free(srcIn); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
447 srcIn = (float*)malloc(sizeof(float)*lrLength); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
448 } |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
449 if(lengthOfSrcOut < overLrLength) |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
450 { |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
451 lengthOfSrcOut = overLrLength; |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
452 free(srcOut); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
453 free(wOut); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
454 srcOut = (float*)malloc(sizeof(float)*overLrLength); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
455 wOut = (short int*)malloc(sizeof(short int)*overLrLength); |
|
51495131e4ae
[svn] - synchronize SRC conversion patch with upstream
nenolod
parents:
2542
diff
changeset
|
456 } |
|
2538
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
457 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
|
458 src_data.data_in = srcIn; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
459 src_data.data_out = srcOut; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
460 src_data.end_of_input = 0; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
461 src_data.input_frames = lrLength/2; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
462 src_data.output_frames = overLrLength/2; |
| 2542 | 463 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
|
464 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
465 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
|
466 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
467 else |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
468 { |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
469 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
|
470 ptr = wOut; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
471 length = src_data.output_frames_gen*4; |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
472 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
473 } |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
474 #endif |
|
719e0898ff3c
[svn] - Patch to use libsamplerate for high-quality interpolated upsampling,
nenolod
parents:
2373
diff
changeset
|
475 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
476 if (!caneq && cfg.equalizer_active) { /* wrong byte order */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
477 byteswap(length, ptr); /* so convert */ |
| 2313 | 478 ++swapped; |
| 479 ++caneq; | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
480 } /* can eq now, mark swapd */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
481 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
|
482 caneq = 0; /* so don't eq */ |
| 2313 | 483 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
484 if (caneq) { /* if eq enab */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
485 if (!init) { /* if first run */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
486 init_iir(); /* then init eq */ |
| 2313 | 487 ++init; |
| 488 } | |
| 489 | |
| 490 iir(&ptr, length, nch); | |
| 491 | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
492 if (swapped) /* if was swapped */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
493 byteswap(length, ptr); /* swap back for output */ |
| 2313 | 494 } |
| 495 | |
| 496 /* do vis plugin(s) */ | |
| 497 input_add_vis_pcm(time, fmt, nch, length, ptr); | |
| 498 | |
|
2811
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
499 /* do effect plugin(s) */ |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
500 if (effects_enabled() && ep && ep->query_format) { |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
501 new_format = op_state.fmt; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
502 new_rate = op_state.rate; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
503 new_nch = op_state.nch; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
504 |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
505 ep->query_format(&new_format, &new_rate, &new_nch); |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
506 |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
507 if (new_format != op_state.fmt || |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
508 new_rate != op_state.rate || |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
509 new_nch != op_state.nch) { |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
510 /* |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
511 * The effect plugin changes the stream format. Reopen the |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
512 * audio device. |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
513 */ |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
514 if (0 == output_open_audio(new_format, new_rate, new_nch)) { |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
515 /* |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
516 * Fatal error. |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
517 */ |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
518 return; |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
519 } |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
520 } |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
521 } |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
522 |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
523 if (effects_enabled() && ep && ep->mod_samples) |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
524 length = ep->mod_samples(&ptr, length, op_state.fmt, |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
525 op_state.rate, op_state.nch); |
|
1c7ee5ed3a10
[svn] Move effect plugin handling into the main thread
ertzing
parents:
2717
diff
changeset
|
526 |
| 2313 | 527 writeoffs = 0; |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
528 while (writeoffs < length) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
529 { |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
530 int writable = length - writeoffs; |
| 2313 | 531 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
532 if (writable > 2048) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
533 writable = 2048; |
| 2313 | 534 |
|
2813
49f3d1b43518
[svn] - code cleanups involving SRC patch and indentation
nenolod
parents:
2811
diff
changeset
|
535 if (writable == 0) |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
536 return; |
| 2313 | 537 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
538 while (op->buffer_free() < writable) { /* wait output buf */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
539 if (going && !*going) /* thread stopped? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
540 return; /* so finish */ |
| 2313 | 541 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
542 if (ip_data.stop) /* has a stop been requested? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
543 return; /* yes, so finish */ |
| 2313 | 544 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
545 g_usleep(10000); /* else sleep for retry */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
546 } |
| 2313 | 547 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
548 if (ip_data.stop) |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
549 return; |
| 2313 | 550 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
551 if (going && !*going) /* thread stopped? */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
552 return; /* so finish */ |
| 2313 | 553 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
554 /* do output */ |
|
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
555 op->write_audio(((guint8 *) ptr) + writeoffs, writable); |
| 2313 | 556 |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
557 writeoffs += writable; |
| 2313 | 558 } |
| 559 } |
