Mercurial > hg > xmms-sid
view src/xs_sidplay2.cc @ 74:8cb66a3f75f7
Testing
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 14 Sep 2003 18:51:05 +0000 |
parents | 2bc607888f53 |
children | 653c9b0d1320 |
line wrap: on
line source
/* XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) libSIDPlay v2 support Written by Matti "ccr" Hamalainen <ccr@tnsp.org> 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 <stdio.h> #include <xmms/titlestring.h> #include "xs_config.h" #include "xs_support.h" #include "xs_length.h" } #include <sidplay/sidplay2.h> #ifdef HAVE_RESID_BUILDER #include <sidplay/builders/resid.h> #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->currConfig = myPlayer->currEng->config(); /* Configure channels and stuff */ switch (xs_cfg.fmtChannels) { case XS_CHN_AUTOPAN: myPlayer->currConfig.playback = sid2_stereo; break; case XS_CHN_STEREO: myPlayer->currConfig.playback = sid2_stereo; break; case XS_CHN_MONO: default: myPlayer->currConfig.playback = sid2_mono; break; } /* Memory mode settings */ switch (xs_cfg.memoryMode) { case XS_MPU_BANK_SWITCHING: myPlayer->currConfig.environment = sid2_envBS; break; case XS_MPU_TRANSPARENT_ROM: myPlayer->currConfig.environment = sid2_envTP; break; case XS_MPU_PLAYSID_ENVIRONMENT: myPlayer->currConfig.environment = sid2_envPS; break; case XS_MPU_REAL: default: myPlayer->currConfig.environment = sid2_envR; break; } /* Clockspeed settings */ switch (xs_cfg.clockSpeed) { case XS_CLOCK_NTSC: myPlayer->currConfig.clockSpeed = myPlayer->currConfig.clockDefault = SID2_CLOCK_NTSC; break; case XS_CLOCK_PAL: default: myPlayer->currConfig.clockSpeed = myPlayer->currConfig.clockDefault = SID2_CLOCK_PAL; break; } /* Configure rest of the emulation */ myPlayer->currConfig.precision = xs_cfg.fmtBitsPerSample; myPlayer->currConfig.frequency = xs_cfg.fmtFrequency; myPlayer->currConfig.clockForced = xs_cfg.forceSpeed; myPlayer->currConfig.optimisation = (xs_cfg.optimiseLevel) ? 1 : 0; myPlayer->currConfig.sidDefault = myPlayer->currConfig.sidModel = (xs_cfg.mos8580) ? SID2_MOS8580 : SID2_MOS6581; myPlayer->currConfig.sidSamples = TRUE; // FIXME FIX ME, make configurable! #ifdef HAVE_UNSIGNEDPCM #ifdef WORDS_BIGENDIAN myPlayer->currConfig.sampleFormat = SID2_BIG_UNSIGNED; #else myPlayer->currConfig.sampleFormat = SID2_LITTLE_UNSIGNED; #endif #else #ifdef WORDS_BIGENDIAN myPlayer->currConfig.sampleFormat = SID2_BIG_SIGNED; #else myPlayer->currConfig.sampleFormat = SID2_LITTLE_SIGNED; #endif #endif /* Now set the emulator configuration */ myPlayer->currEng->config(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; if (myStatus->currFileName) { g_free(myStatus->currFileName); myStatus->currFileName = NULL; } myPlayer = (t_xs_sidplay2 *) myStatus->player; if (!myPlayer) return; if (myPlayer->currTune) { delete myPlayer->currTune; myPlayer->currTune = NULL; } } 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 */