# HG changeset patch # User Matti Hamalainen # Date 1063509241 0 # Node ID 2bc607888f5369f6e7725a191160e0af0707c14e # Parent e3b205a6bc7efb729485cd6ef8773d3c340e0911 Added libsidplay2 module, lots of reworking of internals, sidplay1 support now works with the new framework! Getting libsidplay2 support working shouldn't be too far now... diff -r e3b205a6bc7e -r 2bc607888f53 src/Makefile.am --- a/src/Makefile.am Fri Sep 12 03:26:04 2003 +0000 +++ b/src/Makefile.am Sun Sep 14 03:14:01 2003 +0000 @@ -20,6 +20,7 @@ xs_glade.c xs_glade.h \ xs_interface.c xs_interface.h \ xs_sidplay1.cc xs_sidplay1.h \ + xs_sidplay2.cc xs_sidplay2.h \ xmms-sid.c xmms-sid.h EXTRA_DIST = xmms-sid-logo.xpm diff -r e3b205a6bc7e -r 2bc607888f53 src/xmms-sid.c --- a/src/xmms-sid.c Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xmms-sid.c Sun Sep 14 03:14:01 2003 +0000 @@ -48,25 +48,44 @@ typedef struct { gint plrIdent; + gboolean (*plrIsOurFile)(gchar *); gboolean (*plrInit)(t_xs_status *); void (*plrClose)(t_xs_status *); gboolean (*plrInitSong)(t_xs_status *); - void (*plrFillBuffer)(t_xs_status *, gchar *, gint); + gboolean (*plrFillBuffer)(t_xs_status *, gchar *, gint); gboolean (*plrLoadSID)(t_xs_status *, gchar *); + gint (*plrGetTuneSpeed)(t_xs_status *); + void (*plrDeleteSID)(t_xs_status *); + void (*plrGetSIDInfo)(gchar *, gchar **, gint *); } t_xs_player; t_xs_player xs_playerlist[] = { #ifdef HAVE_SIDPLAY1 - { XS_ENG_SIDPLAY1, xs_sidplay1_init, xs_sidplay1_close, + { XS_ENG_SIDPLAY1, + xs_sidplay1_isourfile, + xs_sidplay1_init, xs_sidplay1_close, xs_sidplay1_initsong, xs_sidplay1_fillbuffer, - xs_sidplay1_loadsid + xs_sidplay1_loadsid, xs_sidplay1_gettunespeed, + xs_sidplay1_deletesid, xs_sidplay1_getsidinfo }, #endif #ifdef HAVE_SIDPLAY2 - { XS_ENG_SIDPLAY2, xs_sidplay2_init, xs_sidplay2_close, + { XS_ENG_SIDPLAY2, + xs_sidplay2_isourfile, + xs_sidplay2_init, xs_sidplay2_close, xs_sidplay2_initsong, xs_sidplay2_fillbuffer, - xs_sidplay2_loadsid + xs_sidplay2_loadsid, xs_sidplay2_gettunespeed, + xs_sidplay2_deletesid, xs_sidplay2_getsidinfo + }, +#endif +#ifdef HAVE_NANOSID + { XS_ENG_NANOSID, + xs_nanosid_isourfile, + xs_nanosid_init, xs_nanosid_close, + xs_nanosid_initsong, xs_nanosid_fillbuffer, + xs_nanosid_loadsid, xs_nanosid_gettunespeed, + xs_nanosid_deletesid, xs_nanosid_getsidinfo }, #endif }; @@ -117,10 +136,12 @@ memset(&xs_cfg, 0, sizeof(xs_cfg)); xs_read_configuration(); + /* Initialize status */ memset(&xs_status, 0, sizeof(xs_status)); xs_status.allowNext = TRUE; + /* Try to initialize emulator engine */ XSDEBUG("initializing emulator engine...\n"); @@ -135,8 +156,8 @@ isInitialized = TRUE; xs_player = (t_xs_player *) &xs_playerlist[iPlayer]; } - } else - iPlayer++; + } + iPlayer++; } @@ -147,8 +168,8 @@ { isInitialized = TRUE; xs_player = (t_xs_player *) &xs_playerlist[iPlayer]; - } else - iPlayer++; + } + iPlayer++; } @@ -178,6 +199,7 @@ /* Stop playing */ xs_stop(); + xs_player->plrDeleteSID(&xs_status); xs_player->plrClose(&xs_status); /* Close sub-song control window */ @@ -191,6 +213,37 @@ /* + * Check whether the given file is handled by this plugin + */ +gint xs_is_our_file(gchar *pcFileName) +{ + char *pcExt; + + /* Check the filename */ + if (pcFileName == NULL) + return FALSE; + + /* Try to detect via detection routine, if required */ + if (xs_cfg.detectMagic && xs_player->plrIsOurFile(pcFileName)) + return TRUE; + + /* Detect just by checking filename extension */ + pcExt = strrchr(pcFileName, '.'); + if (pcExt) + { + pcExt++; + if (!strcasecmp(pcExt, "psid")) return TRUE; + if (!strcasecmp(pcExt, "sid")) return TRUE; + if (!strcasecmp(pcExt, "dat")) return TRUE; + if (!strcasecmp(pcExt, "inf")) return TRUE; + if (!strcasecmp(pcExt, "info")) return TRUE; + } + + return FALSE; +} + + +/* * Main playing thread loop */ void *xs_play_loop(void *argPointer) @@ -199,7 +252,6 @@ gboolean audioOpen; gint audioFreq, audioChannels, songLength, audioFmt; gchar audioBuffer[XS_BUFSIZE]; - gchar *tmpStr; pthread_mutex_lock(&xs_mutex); @@ -244,11 +296,8 @@ XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong); - /* Get song length for current subtune */ - songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong); - /* Initialize song */ - if ((myStatus.currTune == NULL) || !xs_player->plrInitSong(&myStatus)) + if (!xs_player->plrInitSong(&myStatus)) { XSERR("Couldn't initialize SID-tune '%s' (sub-tune #%i)!\n", myStatus.currFileName, myStatus.currSong); @@ -256,16 +305,17 @@ } - /* Set information for current sub-tune */ - xs_player->plrGetTuneInfo(&myStatus, &myTuneInfo); + /* Get song information for current subtune */ + songLength = xs_songlen_get(myStatus.currFileName, myStatus.currSong); +/* xs_plugin_ip.set_info( - myTuneInfo->titleStr, + myTuneInfo.titleStr, (songLength > 0) ? (songLength * 1000) : -1, - 1000 * myTuneInfo->songSpeed, + 1000 * myTuneInfo.songSpeed, audioFreq, audioChannels); - +*/ /* Open the audio output */ if (!xs_plugin_ip.output->open_audio(audioFmt, audioFreq, audioChannels)) @@ -349,11 +399,7 @@ xs_plugin_ip.output->close_audio(); } - if (myStatus.currTune != NULL) - { - myStatus.currPlayer->plrDeleteTune(&myStatus); - myStatus.currTune = NULL; - } + xs_player->plrDeleteSID(&myStatus); g_free(myStatus.currFileName); @@ -376,7 +422,18 @@ */ void xs_play_file(gchar *pcFileName) { + /* Initialize the tune */ + if (!xs_player->plrLoadSID(&xs_status, pcFileName)) + return; + /* Start the playing thread! */ + if (pthread_create(&xs_decode_thread, NULL, xs_play_loop, NULL) < 0) + { + XSERR("Couldn't start playing thread! Possible reason reported by system: %s\n", strerror(errno)); + xs_player->plrDeleteSID(&xs_status); + } + + XSDEBUG("systems should be up?\n"); } @@ -449,3 +506,11 @@ return xs_plugin_ip.output->output_time(); } + +/* + * Return song information + */ +void xs_get_song_info(gchar *songFileName, gchar **songTitle, gint *songLength) +{ + xs_player->plrGetSIDInfo(songFileName, songTitle, songLength); +} diff -r e3b205a6bc7e -r 2bc607888f53 src/xmms-sid.h --- a/src/xmms-sid.h Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xmms-sid.h Sun Sep 14 03:14:01 2003 +0000 @@ -51,14 +51,11 @@ extern InputPlugin xs_plugin_ip; /* XMMS-SID plugin structure */ - typedef struct { - void *currConf; - void *currEng; - gboolean isError, isPlaying, allowNext; - gint currSong, nSongs; - void *currTune; - gchar *currFileName; + void *player; + gboolean isError, isPlaying, allowNext; + gint currSong, nSongs; + gchar *currFileName; } t_xs_status; extern t_xs_status xs_status; diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_about.c --- a/src/xs_about.c Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xs_about.c Sun Sep 14 03:14:01 2003 +0000 @@ -19,7 +19,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "xmms-sid.h" #include #include "xmms-sid-logo.xpm" diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_config.h --- a/src/xs_config.h Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xs_config.h Sun Sep 14 03:14:01 2003 +0000 @@ -13,7 +13,7 @@ enum XS_ENG { XS_ENG_SIDPLAY1, XS_ENG_SIDPLAY2, - XS_ENG_TINYSID + XS_ENG_NANOSID }; diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_length.c --- a/src/xs_length.c Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xs_length.c Sun Sep 14 03:14:01 2003 +0000 @@ -19,7 +19,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "xs_length.h" #include "xs_support.h" #include "xs_config.h" diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_sidplay1.cc --- a/src/xs_sidplay1.cc Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xs_sidplay1.cc Sun Sep 14 03:14:01 2003 +0000 @@ -19,11 +19,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "xmms-sid.h" + #ifdef HAVE_SIDPLAY1 -#include "xs_sidplay1.h" extern "C" { -#include +#include "xs_sidplay1.h" +#include +#include +#include "xs_config.h" +#include "xs_support.h" +#include "xs_length.h" } #include @@ -31,96 +37,156 @@ #include +typedef struct { + emuEngine *currEng; + emuConfig currConfig; + sidTune *currTune; +} t_xs_sidplay1; + + +/* + * We need to 'export' all this pseudo-C++ crap + */ +extern "C" { + +gboolean xs_sidplay1_isourfile(gchar *pcFileName) +{ + /* Try to detect via libSIDPlay's detection routine, if required */ + sidTune *testTune = new sidTune(pcFileName); + + if (!testTune) return FALSE; + if (!testTune->getStatus()) + { + delete testTune; + return FALSE; + } + + delete testTune; + return TRUE; +} + + void xs_sidplay1_close(t_xs_status *myStatus) { + t_xs_sidplay1 *myPlayer; + + /* Check pointer */ if (!myStatus) return; - if (!myStatus->currEng) - delete (emuEngine *) myStatus->currEng; + /* Free internals */ + xs_sidplay1_deletesid(myStatus); + + myPlayer = (t_xs_sidplay1 *) myStatus->player; + + if (myPlayer->currEng) delete myPlayer->currEng; - if (!myStatus->currConf) - free(myStatus->currConf); + free(myPlayer); + myStatus->player = NULL; - free(myStatus); + /* Miscellaneous */ + free(myStatus->currFileName); + myStatus->currFileName = NULL; } gboolean xs_sidplay1_init(t_xs_status *myStatus) { + t_xs_sidplay1 *myPlayer; + + /* Check pointer */ if (!myStatus) return FALSE; - myStatus->currEng = (void *) new emuEngine; - if (!myStatus->currEng) + /* Allocate internal structures */ + myPlayer = (t_xs_sidplay1 *) g_malloc0(sizeof(t_xs_sidplay1)); + if (!myPlayer) return FALSE; + + /* Initialize engine */ + myPlayer->currEng = new emuEngine(); + if (!myPlayer->currEng) { - xs_sidplay1_close(myStatus); + XSERR("Could not initialize libSIDPlay1 emulation engine\n"); + free(myPlayer); return FALSE; } - myStatus->currConf = calloc(1, sizeof(struct emuConfig)); - if (!myStatus->currConf) + /* Verify endianess */ + if (!myPlayer->currEng->verifyEndianess()) { - xs_sidplay1_close(myStatus); + XSERR("Endianess verification failed\n"); + free(myPlayer); return FALSE; } + myStatus->player = myPlayer; return TRUE; } gboolean xs_sidplay1_initsong(t_xs_status *myStatus) { - if ((!myStatus->currTune) || (!((sidTune *)myStatus->currTune)->getStatus())) return FALSE; + t_xs_sidplay1 *myPlayer = (t_xs_sidplay1 *) myStatus->player; + + if (!myPlayer) return FALSE; + + if ((!myPlayer->currTune) || (!myPlayer->currTune->getStatus())) return FALSE; return sidEmuInitializeSong( - (emuEngine *) myStatus->currEngine, - (sidTune *) myStatus->currTune, + *myPlayer->currEng, + *myPlayer->currTune, myStatus->currSong); } -void xs_sidplay1_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize) +gboolean xs_sidplay1_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize) { + t_xs_sidplay1 *myPlayer = (t_xs_sidplay1 *) myStatus->player; + + if (!myPlayer) return FALSE; + sidEmuFillBuffer( - (emuEngine *) myStatus->currEngine, - (sidTune *) myStatus->currTune, + *myPlayer->currEng, + *myPlayer->currTune, audioBuffer, audioBufSize); + + return TRUE; } gboolean xs_sidplay1_loadsid(t_xs_status *myStatus, gchar *pcFileName) { + t_xs_sidplay1 *myPlayer = (t_xs_sidplay1 *) myStatus->player; sidTune *newTune; sidTuneInfo tuneInfo; /* Try to get the tune */ if (!pcFileName) return FALSE; newTune = new sidTune(pcFileName); - if (newTune == NULL) return FALSE; + if (!newTune) return FALSE; /* Get current configuration */ - myStatus->currEngine.getConfig(myStatus->currConf); + myPlayer->currEng->getConfig(myPlayer->currConfig); /* Configure channels and stuff */ switch (xs_cfg.fmtChannels) { case XS_CHN_AUTOPAN: - myStatus->currConf.channels = SIDEMU_STEREO; - myStatus->currConf.autoPanning = SIDEMU_CENTEREDAUTOPANNING; - myStatus->currConf.volumeControl = SIDEMU_FULLPANNING; + myPlayer->currConfig.channels = SIDEMU_STEREO; + myPlayer->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING; + myPlayer->currConfig.volumeControl = SIDEMU_FULLPANNING; break; case XS_CHN_STEREO: - myStatus->currConf.channels = SIDEMU_STEREO; - myStatus->currConf.autoPanning = SIDEMU_NONE; - myStatus->currConf.volumeControl = SIDEMU_NONE; + myPlayer->currConfig.channels = SIDEMU_STEREO; + myPlayer->currConfig.autoPanning = SIDEMU_NONE; + myPlayer->currConfig.volumeControl = SIDEMU_NONE; break; case XS_CHN_MONO: default: - myStatus->currConf.channels = SIDEMU_MONO; - myStatus->currConf.autoPanning = SIDEMU_NONE; - myStatus->currConf.volumeControl = SIDEMU_NONE; + myPlayer->currConfig.channels = SIDEMU_MONO; + myPlayer->currConfig.autoPanning = SIDEMU_NONE; + myPlayer->currConfig.volumeControl = SIDEMU_NONE; break; } @@ -128,19 +194,19 @@ /* Memory mode settings */ switch (xs_cfg.memoryMode) { case XS_MPU_BANK_SWITCHING: - myStatus->currConf.memoryMode = MPU_BANK_SWITCHING; + myPlayer->currConfig.memoryMode = MPU_BANK_SWITCHING; break; case XS_MPU_TRANSPARENT_ROM: - myStatus->currConf.memoryMode = MPU_TRANSPARENT_ROM; + myPlayer->currConfig.memoryMode = MPU_TRANSPARENT_ROM; break; case XS_MPU_PLAYSID_ENVIRONMENT: - myStatus->currConf.memoryMode = MPU_PLAYSID_ENVIRONMENT; + myPlayer->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; break; default: - myStatus->currConf.memoryMode = MPU_BANK_SWITCHING; + myPlayer->currConfig.memoryMode = MPU_BANK_SWITCHING; break; } @@ -148,46 +214,104 @@ /* Clockspeed settings */ switch (xs_cfg.clockSpeed) { case XS_CLOCK_NTSC: - myStatus->currConf.clockSpeed = SIDTUNE_CLOCK_NTSC; + myPlayer->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC; break; case XS_CLOCK_PAL: default: - myStatus->currConf.clockSpeed = SIDTUNE_CLOCK_PAL; + myPlayer->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL; break; } /* Configure rest of the emulation */ - myStatus->currConf.bitsPerSample = xs_cfg.fmtBitsPerSample; - myStatus->currConf.frequency = xs_cfg.fmtFrequency; + myPlayer->currConfig.bitsPerSample = xs_cfg.fmtBitsPerSample; + myPlayer->currConfig.frequency = xs_cfg.fmtFrequency; #ifdef HAVE_UNSIGNEDPCM - myStatus->currConf.sampleFormat = SIDEMU_UNSIGNED_PCM; + myPlayer->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; #else - myStatus->currConf.sampleFormat = SIDEMU_SIGNED_PCM; + myPlayer->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; #endif - myStatus->currConf.mos8580 = xs_cfg.mos8580; - myStatus->currConf.emulateFilter = xs_cfg.emulateFilters; - myStatus->currConf.filterFs = xs_cfg.filterFs; - myStatus->currConf.filterFm = xs_cfg.filterFm; - myStatus->currConf.filterFt = xs_cfg.filterFt; + myPlayer->currConfig.mos8580 = xs_cfg.mos8580; + myPlayer->currConfig.emulateFilter = xs_cfg.emulateFilters; + myPlayer->currConfig.filterFs = xs_cfg.filterFs; + myPlayer->currConfig.filterFm = xs_cfg.filterFm; + myPlayer->currConfig.filterFt = xs_cfg.filterFt; /* Now set the emulator configuration */ - myStatus->currEngine.setConfig(myStatus->currConf); + myPlayer->currEng->setConfig(myPlayer->currConfig); /* Initialize status information */ newTune->getInfo(tuneInfo); - if (!newTune) return FALSE; myStatus->isPlaying = TRUE; myStatus->isError = FALSE; myStatus->currSong = tuneInfo.startSong; myStatus->nSongs = tuneInfo.songs; - myStatus->currTune = newTune; + myPlayer->currTune = newTune; myStatus->currFileName = g_strdup(pcFileName); return TRUE; } +/* + * Delete tune + */ +void xs_sidplay1_deletesid(t_xs_status *myStatus) +{ + t_xs_sidplay1 *myPlayer; + + if (!myStatus) return; + + myPlayer = (t_xs_sidplay1 *) myStatus->player; + if (!myPlayer) return; + + if (myPlayer->currTune) + delete myPlayer->currTune; +} + + +gint xs_sidplay1_gettunespeed(t_xs_status *myStatus) +{ + return 0; +} + +/* + * Return song information + */ +#include "xs_sidplay_info.h" + +void xs_sidplay1_getsidinfo(gchar *songFileName, gchar **songTitle, gint *songLength) +{ + sidTuneInfo tuneInfo; + sidTune *testTune; + gint tmpInt; + + /* Check if the tune exists and is readable */ + testTune = new sidTune(songFileName); + if (!testTune) return; + if (!testTune->getStatus()) + { + delete testTune; + return; + } + + /* Get general tune information */ + testTune->getInfo(tuneInfo); + delete testTune; + + /* Get titlestring */ + *songTitle = xs_make_filetitle(songFileName, &tuneInfo, tuneInfo.startSong); + + /* Get song length (in milliseconds), negative if no known length */ + tmpInt = xs_songlen_get(songFileName, tuneInfo.startSong); + if (tmpInt >= 0) + *songLength = (tmpInt * 1000); + else + *songLength = -1; +} + + +} /* extern "C" */ #endif /* HAVE_SIDPLAY1 */ diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_sidplay1.h --- a/src/xs_sidplay1.h Fri Sep 12 03:26:04 2003 +0000 +++ b/src/xs_sidplay1.h Sun Sep 14 03:14:01 2003 +0000 @@ -3,11 +3,14 @@ #include "xmms-sid.h" -void xs_sidplay1_close(t_xs_status *myStatus); -gboolean xs_sidplay1_init(t_xs_status *myStatus); -gboolean xs_sidplay1_initsong(t_xs_status *myStatus); -void xs_sidplay1_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize); -gboolean xs_sidplay1_loadsid(t_xs_status *myStatus, gchar *pcFileName); -void xs_sidplay1_deletesid(t_xs_status *myStatus); +gboolean xs_sidplay1_isourfile(gchar *); +void xs_sidplay1_close(t_xs_status *); +gboolean xs_sidplay1_init(t_xs_status *); +gboolean xs_sidplay1_initsong(t_xs_status *); +gboolean xs_sidplay1_fillbuffer(t_xs_status *, gchar *, gint); +gboolean xs_sidplay1_loadsid(t_xs_status *, gchar *); +void xs_sidplay1_deletesid(t_xs_status *); +gint xs_sidplay1_gettunespeed(t_xs_status *); +void xs_sidplay1_getsidinfo(gchar *, gchar **, gint *); #endif /* _XS_SIDPLAY1_H */ diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_sidplay2.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_sidplay2.cc Sun Sep 14 03:14:01 2003 +0000 @@ -0,0 +1,281 @@ +/* + XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) + + libSIDPlay v2 support + + Written by Matti "ccr" Hamalainen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "xmms-sid.h" + +#ifdef HAVE_SIDPLAY2 + +extern "C" { +#include "xs_sidplay2.h" +#include +#include +#include "xs_config.h" +#include "xs_support.h" +#include "xs_length.h" +} + +#include +#ifdef HAVE_RESID_BUILDER +#include +#endif +#ifdef HAVE_HARDSID_BUILDER +/* Dummy now */ +#endif + + +typedef struct { + sidplay2 *currEng; + sid2_config_t currConfig; + SidTune *currTune; +} t_xs_sidplay2; + + +/* + * We need to 'export' all this pseudo-C++ crap + */ +extern "C" { + +gboolean xs_sidplay2_isourfile(gchar *pcFileName) +{ + /* Try to detect via libSIDPlay's detection routine, if required */ + SidTune *testTune = new SidTune(pcFileName); + + if (!testTune) return FALSE; + if (!testTune->getStatus()) + { + delete testTune; + return FALSE; + } + + delete testTune; + return TRUE; +} + + +void xs_sidplay2_close(t_xs_status *myStatus) +{ + t_xs_sidplay2 *myPlayer; + sidbuilder *myBuilder; + + /* Check pointer */ + if (!myStatus) return; + + /* Free internals */ + myPlayer = (t_xs_sidplay2 *) myStatus->player; + + myBuilder = myPlayer->currConfig.sidEmulation; + myPlayer->currEng->config(myPlayer->currConfig); + + delete myBuilder; + delete myPlayer->currEng; + + xs_sidplay2_deletesid(myStatus); + + free(myPlayer); + myStatus->player = NULL; + + /* Miscellaneous */ + free(myStatus->currFileName); + myStatus->currFileName = NULL; +} + + +gboolean xs_sidplay2_init(t_xs_status *myStatus) +{ + t_xs_sidplay2 *myPlayer; + + /* Check pointer */ + if (!myStatus) return FALSE; + + /* Allocate internal structures */ + myPlayer = (t_xs_sidplay2 *) g_malloc0(sizeof(t_xs_sidplay2)); + if (!myPlayer) return FALSE; + + /* Initialize engine */ + myPlayer->currEng = new sidplay2; + if (!myPlayer->currEng) + { + XSERR("Could not initialize libSIDPlay2 emulation engine\n"); + free(myPlayer); + return FALSE; + } + + myStatus->player = myPlayer; + return TRUE; +} + + +gboolean xs_sidplay2_initsong(t_xs_status *myStatus) +{ + t_xs_sidplay2 *myPlayer = (t_xs_sidplay2 *) myStatus->player; + + if (!myPlayer || !myPlayer->currTune) return FALSE; + + myPlayer->currTune->selectSong(myStatus->currSong); + + return myPlayer->currEng->load(myPlayer->currTune); +} + + +gboolean xs_sidplay2_fillbuffer(t_xs_status *myStatus, gchar *audioBuffer, gint audioBufSize) +{ + t_xs_sidplay2 *myPlayer = (t_xs_sidplay2 *) myStatus->player; + + if (!myPlayer) return FALSE; + + return (myPlayer->currEng->play(audioBuffer, audioBufSize) == audioBufSize); +} + + +gboolean xs_sidplay2_loadsid(t_xs_status *myStatus, gchar *pcFileName) +{ + t_xs_sidplay2 *myPlayer = (t_xs_sidplay2 *) myStatus->player; + SidTune *newTune; + SidTuneInfo tuneInfo; + + /* Try to get the tune */ + if (!pcFileName) return FALSE; + newTune = new SidTune(pcFileName); + if (!newTune) return FALSE; + + /* Get current configuration */ + myPlayer->currEng->getConfig(myPlayer->currConfig); + + /* Configure channels and stuff */ + switch (xs_cfg.fmtChannels) { + + case XS_CHN_AUTOPAN: + myPlayer->currConfig.channels = SIDEMU_STEREO; + myPlayer->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING; + myPlayer->currConfig.volumeControl = SIDEMU_FULLPANNING; + break; + + case XS_CHN_STEREO: + myPlayer->currConfig.channels = SIDEMU_STEREO; + myPlayer->currConfig.autoPanning = SIDEMU_NONE; + myPlayer->currConfig.volumeControl = SIDEMU_NONE; + break; + + case XS_CHN_MONO: + default: + myPlayer->currConfig.channels = SIDEMU_MONO; + myPlayer->currConfig.autoPanning = SIDEMU_NONE; + myPlayer->currConfig.volumeControl = SIDEMU_NONE; + break; + } + + + /* Memory mode settings */ + switch (xs_cfg.memoryMode) { + case XS_MPU_BANK_SWITCHING: + myPlayer->currConfig.memoryMode = MPU_BANK_SWITCHING; + break; + + case XS_MPU_TRANSPARENT_ROM: + myPlayer->currConfig.memoryMode = MPU_TRANSPARENT_ROM; + break; + + case XS_MPU_PLAYSID_ENVIRONMENT: + myPlayer->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; + break; + + default: + myPlayer->currConfig.memoryMode = MPU_BANK_SWITCHING; + break; + } + + + /* Clockspeed settings */ + switch (xs_cfg.clockSpeed) { + case XS_CLOCK_NTSC: + myPlayer->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC; + break; + + case XS_CLOCK_PAL: + default: + myPlayer->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL; + break; + } + + + /* Configure rest of the emulation */ + myPlayer->currConfig.bitsPerSample = xs_cfg.fmtBitsPerSample; + myPlayer->currConfig.frequency = xs_cfg.fmtFrequency; +#ifdef HAVE_UNSIGNEDPCM + myPlayer->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; +#else + myPlayer->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; +#endif + myPlayer->currConfig.mos8580 = xs_cfg.mos8580; + myPlayer->currConfig.emulateFilter = xs_cfg.emulateFilters; + myPlayer->currConfig.filterFs = xs_cfg.filterFs; + myPlayer->currConfig.filterFm = xs_cfg.filterFm; + myPlayer->currConfig.filterFt = xs_cfg.filterFt; + + /* Now set the emulator configuration */ + myPlayer->currEng->setConfig(myPlayer->currConfig); + + /* Initialize status information */ + newTune->getInfo(tuneInfo); + + myStatus->isPlaying = TRUE; + myStatus->isError = FALSE; + myStatus->currSong = tuneInfo.startSong; + myStatus->nSongs = tuneInfo.songs; + myPlayer->currTune = newTune; + myStatus->currFileName = g_strdup(pcFileName); + + return TRUE; +} + + +/* + * Delete tune + */ +void xs_sidplay2_deletesid(t_xs_status *myStatus) +{ + t_xs_sidplay2 *myPlayer; + + if (!myStatus) return; + + myPlayer = (t_xs_sidplay2 *) myStatus->player; + if (!myPlayer) return; + + if (myPlayer->currTune) + delete myPlayer->currTune; +} + + +gint xs_sidplay2_gettunespeed(t_xs_status *myStatus) +{ + return 0; +} + +/* + * Return song information + */ +void xs_sidplay2_getsidinfo(gchar *songFileName, gchar **songTitle, gint *songLength) +{ +} + + +} /* extern "C" */ +#endif /* HAVE_SIDPLAY2 */ diff -r e3b205a6bc7e -r 2bc607888f53 src/xs_sidplay2.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_sidplay2.h Sun Sep 14 03:14:01 2003 +0000 @@ -0,0 +1,16 @@ +#ifndef _XS_SIDPLAY2_H +#define _XS_SIDPLAY2_H + +#include "xmms-sid.h" + +gboolean xs_sidplay2_isourfile(gchar *); +void xs_sidplay2_close(t_xs_status *); +gboolean xs_sidplay2_init(t_xs_status *); +gboolean xs_sidplay2_initsong(t_xs_status *); +gboolean xs_sidplay2_fillbuffer(t_xs_status *, gchar *, gint); +gboolean xs_sidplay2_loadsid(t_xs_status *, gchar *); +void xs_sidplay2_deletesid(t_xs_status *); +gint xs_sidplay2_gettunespeed(t_xs_status *); +void xs_sidplay2_getsidinfo(gchar *, gchar **, gint *); + +#endif /* _XS_SIDPLAY2_H */