comparison src/xmms-sid.c @ 392:b09d74eb71e6

Working on getting STIL and SLDB using completely dynamically allocated structures. Indentation cleanups, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 31 May 2006 10:02:00 +0000
parents e0caab85510e
children f997b79a7251
comparison
equal deleted inserted replaced
391:3cc7455360ad 392:b09d74eb71e6
97 97
98 98
99 /* 99 /*
100 * Error messages 100 * Error messages
101 */ 101 */
102 void XSERR(const char *fmt, ...) 102 void xs_error(const char *fmt, ...)
103 { 103 {
104 va_list ap; 104 va_list ap;
105 fprintf(stderr, "XMMS-SID: "); 105 fprintf(stderr, "XMMS-SID: ");
106 va_start(ap, fmt); 106 va_start(ap, fmt);
107 vfprintf(stderr, fmt, ap); 107 vfprintf(stderr, fmt, ap);
195 xs_cfg.oversampleEnable = xs_status.oversampleEnable; 195 xs_cfg.oversampleEnable = xs_status.oversampleEnable;
196 196
197 /* Initialize song-length database */ 197 /* Initialize song-length database */
198 xs_songlen_close(); 198 xs_songlen_close();
199 if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) { 199 if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) {
200 XSERR("Error initializing song-length database!\n"); 200 xs_error("Error initializing song-length database!\n");
201 } 201 }
202 202
203 /* Initialize STIL database */ 203 /* Initialize STIL database */
204 xs_stil_close(); 204 xs_stil_close();
205 if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) { 205 if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) {
206 XSERR("Error initializing STIL database!\n"); 206 xs_error("Error initializing STIL database!\n");
207 } 207 }
208 } 208 }
209 209
210 210
211 /* 211 /*
296 void *xs_playthread(void *argPointer) 296 void *xs_playthread(void *argPointer)
297 { 297 {
298 t_xs_status myStatus; 298 t_xs_status myStatus;
299 t_xs_tuneinfo *myTune; 299 t_xs_tuneinfo *myTune;
300 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE; 300 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE;
301 gboolean playedTune[XS_STIL_MAXENTRY + 1];
302 gint audioGot, songLength, i; 301 gint audioGot, songLength, i;
303 gchar *audioBuffer = NULL, *oversampleBuffer = NULL; 302 gchar *audioBuffer = NULL, *oversampleBuffer = NULL;
304 303
305 (void) argPointer; 304 (void) argPointer;
306 305
314 xs_memset(&playedTune, 0, sizeof(playedTune)); 313 xs_memset(&playedTune, 0, sizeof(playedTune));
315 314
316 /* Allocate audio buffer */ 315 /* Allocate audio buffer */
317 audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE); 316 audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE);
318 if (audioBuffer == NULL) { 317 if (audioBuffer == NULL) {
319 XSERR("Couldn't allocate memory for audio data buffer!\n"); 318 xs_error("Couldn't allocate memory for audio data buffer!\n");
320 goto xs_err_exit; 319 goto xs_err_exit;
321 } 320 }
322 321
323 if (myStatus.oversampleEnable) { 322 if (myStatus.oversampleEnable) {
324 oversampleBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE * myStatus.oversampleFactor); 323 oversampleBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE * myStatus.oversampleFactor);
325 if (oversampleBuffer == NULL) { 324 if (oversampleBuffer == NULL) {
326 XSERR("Couldn't allocate memory for audio oversampling buffer!\n"); 325 xs_error("Couldn't allocate memory for audio oversampling buffer!\n");
327 goto xs_err_exit; 326 goto xs_err_exit;
328 } 327 }
329 } 328 }
330 329
331 /* 330 /*
394 songLength = xs_cfg.playMinTime; 393 songLength = xs_cfg.playMinTime;
395 } 394 }
396 395
397 /* Initialize song */ 396 /* Initialize song */
398 if (!myStatus.sidPlayer->plrInitSong(&myStatus)) { 397 if (!myStatus.sidPlayer->plrInitSong(&myStatus)) {
399 XSERR("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n", 398 xs_error("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n",
400 myTune->sidFilename, myStatus.currSong); 399 myTune->sidFilename, myStatus.currSong);
401 goto xs_err_exit; 400 goto xs_err_exit;
402 } 401 }
403 402
404 403
405 /* Open the audio output */ 404 /* Open the audio output */
406 if (!xs_plugin_ip.output-> 405 if (!xs_plugin_ip.output->
407 open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) { 406 open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) {
408 XSERR("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n", myStatus.audioFormat, 407 xs_error("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n", myStatus.audioFormat,
409 myStatus.audioFrequency, myStatus.audioChannels); 408 myStatus.audioFrequency, myStatus.audioChannels);
410 409
411 XS_MUTEX_LOCK(xs_status); 410 XS_MUTEX_LOCK(xs_status);
412 xs_status.isError = TRUE; 411 xs_status.isError = TRUE;
413 XS_MUTEX_UNLOCK(xs_status); 412 XS_MUTEX_UNLOCK(xs_status);
441 audioGot /= myStatus.oversampleFactor; 440 audioGot /= myStatus.oversampleFactor;
442 441
443 /* Execute rate-conversion with filtering */ 442 /* Execute rate-conversion with filtering */
444 if (xs_filter_rateconv(audioBuffer, oversampleBuffer, 443 if (xs_filter_rateconv(audioBuffer, oversampleBuffer,
445 myStatus.audioFormat, myStatus.oversampleFactor, audioGot) < 0) { 444 myStatus.audioFormat, myStatus.oversampleFactor, audioGot) < 0) {
446 XSERR("Oversampling rate-conversion pass failed.\n"); 445 xs_error("Oversampling rate-conversion pass failed.\n");
447 XS_MUTEX_LOCK(xs_status); 446 XS_MUTEX_LOCK(xs_status);
448 xs_status.isError = TRUE; 447 xs_status.isError = TRUE;
449 XS_MUTEX_UNLOCK(xs_status); 448 XS_MUTEX_UNLOCK(xs_status);
450 goto xs_err_exit; 449 goto xs_err_exit;
451 } 450 }
553 xs_status.isError = FALSE; 552 xs_status.isError = FALSE;
554 xs_status.currSong = xs_status.tuneInfo->startTune; 553 xs_status.currSong = xs_status.tuneInfo->startTune;
555 554
556 /* Start the playing thread! */ 555 /* Start the playing thread! */
557 if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) { 556 if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) {
558 XSERR("Couldn't start playing thread!\n"); 557 xs_error("Couldn't start playing thread!\n");
559 xs_tuneinfo_free(xs_status.tuneInfo); 558 xs_tuneinfo_free(xs_status.tuneInfo);
560 xs_status.tuneInfo = NULL; 559 xs_status.tuneInfo = NULL;
561 xs_status.sidPlayer->plrDeleteSID(&xs_status); 560 xs_status.sidPlayer->plrDeleteSID(&xs_status);
562 } 561 }
563 562
935 t_xs_tuneinfo *pResult; 934 t_xs_tuneinfo *pResult;
936 935
937 /* Allocate structure */ 936 /* Allocate structure */
938 pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo)); 937 pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo));
939 if (!pResult) { 938 if (!pResult) {
940 XSERR("Could not allocate memory for t_xs_tuneinfo ('%s')\n", pcFilename); 939 xs_error("Could not allocate memory for t_xs_tuneinfo ('%s')\n", pcFilename);
941 return NULL; 940 return NULL;
942 } 941 }
943 942
944 pResult->sidFilename = g_strdup(pcFilename); 943 pResult->sidFilename = g_strdup(pcFilename);
945 if (!pResult->sidFilename) { 944 if (!pResult->sidFilename) {
946 XSERR("Could not allocate sidFilename ('%s')\n", pcFilename); 945 xs_error("Could not allocate sidFilename ('%s')\n", pcFilename);
947 g_free(pResult); 946 g_free(pResult);
948 return NULL; 947 return NULL;
949 } 948 }
950 949
951 /* Allocate space for subtune information */ 950 /* Allocate space for subtune information */
952 if (nsubTunes > 0) { 951 if (nsubTunes > 0) {
953 pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * nsubTunes); 952 pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * nsubTunes);
954 if (!pResult->subTunes) { 953 if (!pResult->subTunes) {
955 XSERR("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n", pcFilename, nsubTunes); 954 xs_error("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n", pcFilename, nsubTunes);
956 955
957 g_free(pResult->sidFilename); 956 g_free(pResult->sidFilename);
958 g_free(pResult); 957 g_free(pResult);
959 return NULL; 958 return NULL;
960 } 959 }