comparison src/xmms-sid.c @ 657:acaba070cf49

Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Apr 2008 19:46:59 +0300
parents 1684092c2bc9
children 04ea91a61225
comparison
equal deleted inserted replaced
656:e9257f006f41 657:acaba070cf49
54 54
55 55
56 /* 56 /*
57 * List of players and links to their functions 57 * List of players and links to their functions
58 */ 58 */
59 t_xs_player xs_playerlist[] = { 59 xs_player_t xs_playerlist[] = {
60 #ifdef HAVE_SIDPLAY1 60 #ifdef HAVE_SIDPLAY1
61 {XS_ENG_SIDPLAY1, 61 {XS_ENG_SIDPLAY1,
62 xs_sidplay1_probe, 62 xs_sidplay1_probe,
63 xs_sidplay1_init, xs_sidplay1_close, 63 xs_sidplay1_init, xs_sidplay1_close,
64 xs_sidplay1_initsong, xs_sidplay1_fillbuffer, 64 xs_sidplay1_initsong, xs_sidplay1_fillbuffer,
77 xs_sidplay2_flush 77 xs_sidplay2_flush
78 }, 78 },
79 #endif 79 #endif
80 }; 80 };
81 81
82 const gint xs_nplayerlist = (sizeof(xs_playerlist) / sizeof(t_xs_player)); 82 const gint xs_nplayerlist = (sizeof(xs_playerlist) / sizeof(xs_playerlist[0]));
83 83
84 84
85 /* 85 /*
86 * Global variables 86 * Global variables
87 */ 87 */
88 t_xs_status xs_status; 88 xs_status_t xs_status;
89 XS_MUTEX(xs_status); 89 XS_MUTEX(xs_status);
90 static XS_THREAD_T xs_decode_thread; 90 static XS_THREAD_T xs_decode_thread;
91 91
92 static GtkWidget *xs_subctrl = NULL; 92 static GtkWidget *xs_subctrl = NULL;
93 static GtkObject *xs_subctrl_adj = NULL; 93 static GtkObject *xs_subctrl_adj = NULL;
142 142
143 XS_MUTEX_LOCK(xs_status); 143 XS_MUTEX_LOCK(xs_status);
144 XS_MUTEX_LOCK(xs_cfg); 144 XS_MUTEX_LOCK(xs_cfg);
145 145
146 /* Initialize status and sanitize configuration */ 146 /* Initialize status and sanitize configuration */
147 xs_memset(&xs_status, 0, sizeof(xs_status)); 147 memset(&xs_status, 0, sizeof(xs_status));
148 148
149 if (xs_cfg.audioFrequency < 8000) 149 if (xs_cfg.audioFrequency < 8000)
150 xs_cfg.audioFrequency = 8000; 150 xs_cfg.audioFrequency = 8000;
151 151
152 if (xs_cfg.oversampleFactor < XS_MIN_OVERSAMPLE) 152 if (xs_cfg.oversampleFactor < XS_MIN_OVERSAMPLE)
171 isInitialized = FALSE; 171 isInitialized = FALSE;
172 while ((iPlayer < xs_nplayerlist) && !isInitialized) { 172 while ((iPlayer < xs_nplayerlist) && !isInitialized) {
173 if (xs_playerlist[iPlayer].plrIdent == xs_cfg.playerEngine) { 173 if (xs_playerlist[iPlayer].plrIdent == xs_cfg.playerEngine) {
174 if (xs_playerlist[iPlayer].plrInit(&xs_status)) { 174 if (xs_playerlist[iPlayer].plrInit(&xs_status)) {
175 isInitialized = TRUE; 175 isInitialized = TRUE;
176 xs_status.sidPlayer = (t_xs_player *) & xs_playerlist[iPlayer]; 176 xs_status.sidPlayer = (xs_player_t *) & xs_playerlist[iPlayer];
177 } 177 }
178 } 178 }
179 iPlayer++; 179 iPlayer++;
180 } 180 }
181 181
183 183
184 iPlayer = 0; 184 iPlayer = 0;
185 while ((iPlayer < xs_nplayerlist) && !isInitialized) { 185 while ((iPlayer < xs_nplayerlist) && !isInitialized) {
186 if (xs_playerlist[iPlayer].plrInit(&xs_status)) { 186 if (xs_playerlist[iPlayer].plrInit(&xs_status)) {
187 isInitialized = TRUE; 187 isInitialized = TRUE;
188 xs_status.sidPlayer = (t_xs_player *) & xs_playerlist[iPlayer]; 188 xs_status.sidPlayer = (xs_player_t *) & xs_playerlist[iPlayer];
189 xs_cfg.playerEngine = xs_playerlist[iPlayer].plrIdent; 189 xs_cfg.playerEngine = xs_playerlist[iPlayer].plrIdent;
190 } else 190 } else
191 iPlayer++; 191 iPlayer++;
192 } 192 }
193 193
204 XS_MUTEX_UNLOCK(xs_cfg); 204 XS_MUTEX_UNLOCK(xs_cfg);
205 205
206 /* Initialize song-length database */ 206 /* Initialize song-length database */
207 xs_songlen_close(); 207 xs_songlen_close();
208 if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) { 208 if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) {
209 xs_error(_("Error initializing song-length database!\n")); 209 xs_error("Error initializing song-length database!\n");
210 } 210 }
211 211
212 /* Initialize STIL database */ 212 /* Initialize STIL database */
213 xs_stil_close(); 213 xs_stil_close();
214 if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) { 214 if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) {
215 xs_error(_("Error initializing STIL database!\n")); 215 xs_error("Error initializing STIL database!\n");
216 } 216 }
217 217
218 } 218 }
219 219
220 220
270 if (pcFilename == NULL) 270 if (pcFilename == NULL)
271 return FALSE; 271 return FALSE;
272 272
273 /* Try to detect via detection routine, if required */ 273 /* Try to detect via detection routine, if required */
274 if (xs_cfg.detectMagic) { 274 if (xs_cfg.detectMagic) {
275 t_xs_file *f; 275 xs_file_t *f;
276 if ((f = xs_fopen(pcFilename, "rb")) != NULL) { 276 if ((f = xs_fopen(pcFilename, "rb")) != NULL) {
277 if (xs_status.sidPlayer->plrProbe(f)) 277 if (xs_status.sidPlayer->plrProbe(f))
278 return TRUE; 278 return TRUE;
279 xs_fclose(f); 279 xs_fclose(f);
280 } 280 }
308 /* 308 /*
309 * Main playing thread loop 309 * Main playing thread loop
310 */ 310 */
311 void *xs_playthread(void *argPointer) 311 void *xs_playthread(void *argPointer)
312 { 312 {
313 t_xs_status myStatus; 313 xs_status_t myStatus;
314 t_xs_tuneinfo *myTune; 314 xs_tuneinfo_t *myTune;
315 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE; 315 gboolean audioOpen = FALSE, doPlay = FALSE, isFound = FALSE;
316 gint audioGot, songLength, i; 316 gint audioGot, songLength, i;
317 gchar *audioBuffer = NULL, *oversampleBuffer = NULL, *tmpTitle; 317 gchar *audioBuffer = NULL, *oversampleBuffer = NULL, *tmpTitle;
318 318
319 (void) argPointer; 319 (void) argPointer;
320 320
321 /* Initialize */ 321 /* Initialize */
322 XSDEBUG("entering player thread\n"); 322 XSDEBUG("entering player thread\n");
323 XS_MUTEX_LOCK(xs_status); 323 XS_MUTEX_LOCK(xs_status);
324 memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); 324 memcpy(&myStatus, &xs_status, sizeof(xs_status_t));
325 myTune = xs_status.tuneInfo; 325 myTune = xs_status.tuneInfo;
326 for (i = 0; i <= myTune->nsubTunes; i++) 326 for (i = 0; i <= myTune->nsubTunes; i++)
327 myTune->subTunes[i].tunePlayed = FALSE; 327 myTune->subTunes[i].tunePlayed = FALSE;
328 XS_MUTEX_UNLOCK(xs_status); 328 XS_MUTEX_UNLOCK(xs_status);
329 329
330 /* Allocate audio buffer */ 330 /* Allocate audio buffer */
331 audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE); 331 audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE);
332 if (audioBuffer == NULL) { 332 if (audioBuffer == NULL) {
333 xs_error(_("Couldn't allocate memory for audio data buffer!\n")); 333 xs_error("Couldn't allocate memory for audio data buffer!\n");
334 goto xs_err_exit; 334 goto xs_err_exit;
335 } 335 }
336 336
337 if (myStatus.oversampleEnable) { 337 if (myStatus.oversampleEnable) {
338 oversampleBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE * myStatus.oversampleFactor); 338 oversampleBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE * myStatus.oversampleFactor);
339 if (oversampleBuffer == NULL) { 339 if (oversampleBuffer == NULL) {
340 xs_error(_("Couldn't allocate memory for audio oversampling buffer!\n")); 340 xs_error("Couldn't allocate memory for audio oversampling buffer!\n");
341 goto xs_err_exit; 341 goto xs_err_exit;
342 } 342 }
343 } 343 }
344 344
345 /* 345 /*
412 songLength = xs_cfg.playMinTime; 412 songLength = xs_cfg.playMinTime;
413 } 413 }
414 414
415 /* Initialize song */ 415 /* Initialize song */
416 if (!myStatus.sidPlayer->plrInitSong(&myStatus)) { 416 if (!myStatus.sidPlayer->plrInitSong(&myStatus)) {
417 xs_error(_("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n"), 417 xs_error("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n",
418 myTune->sidFilename, myStatus.currSong); 418 myTune->sidFilename, myStatus.currSong);
419 goto xs_err_exit; 419 goto xs_err_exit;
420 } 420 }
421 421
422 /* Open the audio output */ 422 /* Open the audio output */
423 XSDEBUG("open audio output (%d, %d, %d)\n", 423 XSDEBUG("open audio output (%d, %d, %d)\n",
424 myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels); 424 myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels);
425 425
426 if (!xs_plugin_ip.output-> 426 if (!xs_plugin_ip.output->
427 open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) { 427 open_audio(myStatus.audioFormat, myStatus.audioFrequency, myStatus.audioChannels)) {
428 xs_error(_("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n"), 428 xs_error("Couldn't open XMMS audio output (fmt=%x, freq=%i, nchan=%i)!\n",
429 myStatus.audioFormat, 429 myStatus.audioFormat,
430 myStatus.audioFrequency, 430 myStatus.audioFrequency,
431 myStatus.audioChannels); 431 myStatus.audioChannels);
432 432
433 XS_MUTEX_LOCK(xs_status); 433 XS_MUTEX_LOCK(xs_status);
469 audioGot /= myStatus.oversampleFactor; 469 audioGot /= myStatus.oversampleFactor;
470 470
471 /* Execute rate-conversion with filtering */ 471 /* Execute rate-conversion with filtering */
472 if (xs_filter_rateconv(audioBuffer, oversampleBuffer, 472 if (xs_filter_rateconv(audioBuffer, oversampleBuffer,
473 myStatus.audioFormat, myStatus.oversampleFactor, audioGot) < 0) { 473 myStatus.audioFormat, myStatus.oversampleFactor, audioGot) < 0) {
474 xs_error(_("Oversampling rate-conversion pass failed.\n")); 474 xs_error("Oversampling rate-conversion pass failed.\n");
475 XS_MUTEX_LOCK(xs_status); 475 XS_MUTEX_LOCK(xs_status);
476 xs_status.isError = TRUE; 476 xs_status.isError = TRUE;
477 XS_MUTEX_UNLOCK(xs_status); 477 XS_MUTEX_UNLOCK(xs_status);
478 goto xs_err_exit; 478 goto xs_err_exit;
479 } 479 }
589 xs_status.isError = FALSE; 589 xs_status.isError = FALSE;
590 xs_status.currSong = xs_status.tuneInfo->startTune; 590 xs_status.currSong = xs_status.tuneInfo->startTune;
591 591
592 /* Start the playing thread! */ 592 /* Start the playing thread! */
593 if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) { 593 if (pthread_create(&xs_decode_thread, NULL, xs_playthread, NULL) < 0) {
594 xs_error(_("Couldn't create playing thread!\n")); 594 xs_error("Couldn't create playing thread!\n");
595 xs_tuneinfo_free(xs_status.tuneInfo); 595 xs_tuneinfo_free(xs_status.tuneInfo);
596 xs_status.tuneInfo = NULL; 596 xs_status.tuneInfo = NULL;
597 xs_status.sidPlayer->plrDeleteSID(&xs_status); 597 xs_status.sidPlayer->plrDeleteSID(&xs_status);
598 } 598 }
599 599
936 * Subsequent changes to information are made by the player thread, 936 * Subsequent changes to information are made by the player thread,
937 * which uses xs_plugin_ip.set_info(); 937 * which uses xs_plugin_ip.set_info();
938 */ 938 */
939 void xs_get_song_info(gchar * songFilename, gchar ** songTitle, gint * songLength) 939 void xs_get_song_info(gchar * songFilename, gchar ** songTitle, gint * songLength)
940 { 940 {
941 t_xs_tuneinfo *pInfo; 941 xs_tuneinfo_t *pInfo;
942 942
943 XS_MUTEX_LOCK(xs_status); 943 XS_MUTEX_LOCK(xs_status);
944 944
945 /* Get tune information from emulation engine */ 945 /* Get tune information from emulation engine */
946 pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename); 946 pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename);