comparison src/xmms-sid.c @ 127:ddb513bd2610

Improved audio format support, now supported formats are "queried" from emulator engines. Preparing for NanoSID-support, since it's the worst in this sense.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 Jan 2004 21:45:05 +0000
parents 5bddcad25ef7
children 4162a5370b9e
comparison
equal deleted inserted replaced
126:4f4dba82011e 127:ddb513bd2610
127 memset(&xs_cfg, 0, sizeof(xs_cfg)); 127 memset(&xs_cfg, 0, sizeof(xs_cfg));
128 xs_read_configuration(); 128 xs_read_configuration();
129 129
130 /* Initialize status */ 130 /* Initialize status */
131 memset(&xs_status, 0, sizeof(xs_status)); 131 memset(&xs_status, 0, sizeof(xs_status));
132 132 xs_status.audioFrequency = xs_cfg.audioFrequency;
133 xs_status.audioBitsPerSample = xs_cfg.audioBitsPerSample;
134 xs_status.audioChannels = xs_cfg.audioChannels;
135 xs_status.audioFormat = -1;
136
133 /* Try to initialize emulator engine */ 137 /* Try to initialize emulator engine */
134 XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine); 138 XSDEBUG("initializing emulator engine #%i...\n", xs_cfg.playerEngine);
135 139
136 iPlayer = 0; 140 iPlayer = 0;
137 isInitialized = FALSE; 141 isInitialized = FALSE;
250 { 254 {
251 t_xs_status myStatus; 255 t_xs_status myStatus;
252 t_xs_tune *myTune; 256 t_xs_tune *myTune;
253 gboolean audioOpen = FALSE, doPlay = FALSE; 257 gboolean audioOpen = FALSE, doPlay = FALSE;
254 guint audioGot; 258 guint audioGot;
255 gint audioFreq, audioChannels, songLength, audioFmt; 259 gint songLength;
256 gchar audioBuffer[XS_BUFSIZE]; 260 gchar audioBuffer[XS_BUFSIZE];
257 261
258 /* Initialize */ 262 /* Initialize */
259 pthread_mutex_lock(&xs_mutex); 263 pthread_mutex_lock(&xs_mutex);
260 XSDEBUG("entering play thread\n"); 264 XSDEBUG("entering play thread\n");
261 memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); 265 memcpy(&myStatus, &xs_status, sizeof(t_xs_status));
262 myTune = xs_status.pTune; 266 myTune = xs_status.pTune;
263 pthread_mutex_unlock(&xs_mutex); 267 pthread_mutex_unlock(&xs_mutex);
264 268
265 /* Copy and check audio options here (they might change in config while running) */
266 #ifdef HAVE_UNSIGNEDPCM
267 audioFmt = (xs_cfg.fmtBitsPerSample == XS_RES_16BIT) ? FMT_U16_NE : FMT_U8;
268 #else
269 audioFmt = (xs_cfg.fmtBitsPerSample == XS_RES_16BIT) ? FMT_S16_NE : FMT_S8;
270 #endif
271 audioFreq = xs_cfg.fmtFrequency;
272 audioChannels = (xs_cfg.fmtChannels == XS_CHN_MONO) ? 1 : 2;
273 269
274 /* 270 /*
275 * Main player loop: while not stopped, loop here - play subtunes 271 * Main player loop: while not stopped, loop here - play subtunes
276 */ 272 */
277 doPlay = TRUE; 273 doPlay = TRUE;
297 /* Get song information for current subtune */ 293 /* Get song information for current subtune */
298 xs_plugin_ip.set_info( 294 xs_plugin_ip.set_info(
299 myTune->subTunes[myStatus.currSong - 1].tuneTitle, 295 myTune->subTunes[myStatus.currSong - 1].tuneTitle,
300 (songLength > 0) ? (songLength * 1000) : -1, 296 (songLength > 0) ? (songLength * 1000) : -1,
301 (myTune->subTunes[myStatus.currSong - 1].tuneSpeed > 0) ? (myTune->subTunes[myStatus.currSong - 1].tuneSpeed * 1000) : -1, 297 (myTune->subTunes[myStatus.currSong - 1].tuneSpeed > 0) ? (myTune->subTunes[myStatus.currSong - 1].tuneSpeed * 1000) : -1,
302 audioFreq, 298 myStatus.audioFrequency,
303 audioChannels); 299 myStatus.audioChannels);
304 300
305 301
306 /* Open the audio output */ 302 /* Open the audio output */
307 if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels)) 303 if (!xs_plugin_ip.output->open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels))
308 { 304 {
309 XSERR("Couldn't open XMMS audio output!\n"); 305 XSERR("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n",
306 myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels);
310 pthread_mutex_lock(&xs_mutex); 307 pthread_mutex_lock(&xs_mutex);
311 xs_status.isError = TRUE; 308 xs_status.isError = TRUE;
312 pthread_mutex_unlock(&xs_mutex); 309 pthread_mutex_unlock(&xs_mutex);
313 goto err_exit; 310 goto err_exit;
314 } 311 }
324 audioGot = xs_player->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE); 321 audioGot = xs_player->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE);
325 322
326 /* I <3 visualice/haujobb */ 323 /* I <3 visualice/haujobb */
327 xs_plugin_ip.add_vis_pcm( 324 xs_plugin_ip.add_vis_pcm(
328 xs_plugin_ip.output->written_time(), 325 xs_plugin_ip.output->written_time(),
329 audioFmt, audioChannels, audioGot, audioBuffer); 326 myStatus.audioFormat, myStatus.audioChannels,
327 audioGot, audioBuffer);
330 328
331 /* Wait a little */ 329 /* Wait a little */
332 while (xs_status.isPlaying && 330 while (xs_status.isPlaying &&
333 (xs_status.currSong == myStatus.currSong) && 331 (xs_status.currSong == myStatus.currSong) &&
334 ((guint) xs_plugin_ip.output->buffer_free() < audioGot)) 332 ((guint) xs_plugin_ip.output->buffer_free() < audioGot))
669 } 667 }
670 668
671 669
672 void xs_fileinfo(gchar *pcFilename) 670 void xs_fileinfo(gchar *pcFilename)
673 { 671 {
674 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu, *tmpText; 672 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
675 t_xs_stil_subnode *tmpNode; 673 t_xs_stil_subnode *tmpNode;
676 gchar tmpStr[32], *tmpS; 674 gchar tmpStr[32], *tmpS;
677 gint n; 675 gint n;
678 676
679 /* Free old info, if set */ 677 /* Free old info, if set */