# HG changeset patch # User Matti Hamalainen # Date 1352400425 -7200 # Node ID a7ee5dc23e780914aceaac6088389a16b202e04a # Parent c0e892fa914ab53cb1ed66394dce6558156e051d Rename .cc -> .cpp. diff -r c0e892fa914a -r a7ee5dc23e78 Makefile.am --- a/Makefile.am Thu Nov 08 20:45:28 2012 +0200 +++ b/Makefile.am Thu Nov 08 20:47:05 2012 +0200 @@ -116,8 +116,8 @@ src/xs_title.c src/xs_title.h \ src/xs_fileinfo.c src/xs_fileinfo.h \ src/xs_sidplay.h \ - src/xs_sidplay1.cc src/xs_sidplay1.h \ - src/xs_sidplay2.cc src/xs_sidplay2.h \ + src/xs_sidplay1.cpp src/xs_sidplay1.h \ + src/xs_sidplay2.cpp src/xs_sidplay2.h \ src/xs_slsup.c src/xs_slsup.h \ src/xs_player.h \ src/xmms-sid.c src/xmms-sid.h diff -r c0e892fa914a -r a7ee5dc23e78 src/xs_sidplay1.cc --- a/src/xs_sidplay1.cc Thu Nov 08 20:45:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,352 +0,0 @@ -/* - XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) - - libSIDPlay v1 support - - Programmed and designed by Matti 'ccr' Hamalainen - (C) Copyright 1999-2007 Tecnic Software productions (TNSP) - - 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "xmms-sid.h" - -#ifdef HAVE_SIDPLAY1 - -#include "xs_sidplay1.h" -#include "xs_slsup.h" -#include "xs_config.h" - -#include -#include -#include - - -/* Maximum audio frequency supported by libSIDPlay v1 */ -#define SIDPLAY1_MAX_FREQ (48000) - - -typedef struct { - emuEngine *emu; - emuConfig currConfig; - sidTune *tune; - guint8 *buf; - size_t bufSize; -} XSSIDPlay1; - - -/* We need to 'export' all this pseudo-C++ crap */ -extern "C" { - - -/* Return song information - */ -#define TFUNCTION xs_sidplay1_getinfo -#define TFUNCTION2 xs_sidplay1_updateinfo -#define TTUNEINFO sidTuneInfo -#define TTUNE sidTune -#define TENGINE XSSIDPlay1 -#include "xs_sidplay.h" - - -/* Check if we can play the given file - */ -gboolean xs_sidplay1_probe(XSFile *f) -{ - gchar tmpBuf[4]; - - if (!f) return FALSE; - - if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4) - return FALSE; - - if (!strncmp(tmpBuf, "PSID", 4)) - return TRUE; - else - return FALSE; -} - - -/* Initialize SIDPlay1 - */ -gboolean xs_sidplay1_init(XSEngineState * state) -{ - gint tmpFreq; - XSSIDPlay1 *engine; - assert(state); - - /* Allocate internal structures */ - engine = (XSSIDPlay1 *) g_malloc0(sizeof(XSSIDPlay1)); - if (!engine) return FALSE; - - /* Initialize engine */ - engine->emu = new emuEngine(); - if (!engine->emu) { - xs_error("[SIDPlay1] Could not initialize emulation engine.\n"); - g_free(engine); - return FALSE; - } - - /* Verify endianess */ - if (!engine->emu->verifyEndianess()) { - xs_error("[SIDPlay1] Endianess verification failed.\n"); - delete engine->emu; - g_free(engine); - return FALSE; - } - - state->internal = engine; - - /* Get current configuration */ - engine->emu->getConfig(engine->currConfig); - - /* Configure channel parameters */ - switch (state->audioChannels) { - - case XS_CHN_AUTOPAN: - engine->currConfig.channels = SIDEMU_STEREO; - engine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING; - engine->currConfig.volumeControl = SIDEMU_FULLPANNING; - break; - - case XS_CHN_STEREO: - engine->currConfig.channels = SIDEMU_STEREO; - engine->currConfig.autoPanning = SIDEMU_NONE; - engine->currConfig.volumeControl = SIDEMU_NONE; - break; - - case XS_CHN_MONO: - default: - engine->currConfig.channels = SIDEMU_MONO; - engine->currConfig.autoPanning = SIDEMU_NONE; - engine->currConfig.volumeControl = SIDEMU_NONE; - state->audioChannels = XS_CHN_MONO; - break; - } - - - /* Memory mode settings */ - switch (xs_cfg.memoryMode) { - case XS_MPU_TRANSPARENT_ROM: - engine->currConfig.memoryMode = MPU_TRANSPARENT_ROM; - break; - - case XS_MPU_PLAYSID_ENVIRONMENT: - engine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; - break; - - case XS_MPU_BANK_SWITCHING: - default: - engine->currConfig.memoryMode = MPU_BANK_SWITCHING; - xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING; - break; - } - - - /* Audio parameters sanity checking and setup */ - engine->currConfig.bitsPerSample = state->audioBitsPerSample; - tmpFreq = state->audioFrequency; - - if (tmpFreq > SIDPLAY1_MAX_FREQ) - tmpFreq = SIDPLAY1_MAX_FREQ; - - engine->currConfig.frequency = tmpFreq; - - switch (state->audioBitsPerSample) { - case XS_RES_8BIT: - switch (state->audioFormat) { - case FMT_S8: - state->audioFormat = FMT_S8; - engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; - break; - - case FMT_U8: - default: - state->audioFormat = FMT_U8; - engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; - break; - } - break; - - case XS_RES_16BIT: - default: - switch (state->audioFormat) { - case FMT_U16_NE: - case FMT_U16_LE: - case FMT_U16_BE: - state->audioFormat = FMT_U16_NE; - engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; - break; - - case FMT_S16_NE: - case FMT_S16_LE: - case FMT_S16_BE: - default: - state->audioFormat = FMT_S16_NE; - engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; - break; - } - break; - } - - /* Clockspeed settings */ - switch (xs_cfg.clockSpeed) { - case XS_CLOCK_NTSC: - engine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC; - break; - - case XS_CLOCK_PAL: - default: - engine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL; - xs_cfg.clockSpeed = XS_CLOCK_PAL; - break; - } - - engine->currConfig.forceSongSpeed = xs_cfg.forceSpeed; - - - /* Configure rest of the emulation */ - /* if (xs_cfg.forceModel) */ - engine->currConfig.mos8580 = xs_cfg.mos8580; - engine->currConfig.emulateFilter = xs_cfg.emulateFilters; - engine->currConfig.filterFs = xs_cfg.sid1Filter.fs; - engine->currConfig.filterFm = xs_cfg.sid1Filter.fm; - engine->currConfig.filterFt = xs_cfg.sid1Filter.ft; - - - /* Now set the emulator configuration */ - if (!engine->emu->setConfig(engine->currConfig)) { - xs_error("[SIDPlay1] Emulator engine configuration failed!\n"); - return FALSE; - } - - /* Create sidtune object */ - engine->tune = new sidTune(0); - if (!engine->tune) { - xs_error("[SIDPlay1] Could not initialize SIDTune object.\n"); - return FALSE; - } - - return TRUE; -} - - -/* Close SIDPlay1 engine - */ -void xs_sidplay1_close(XSEngineState * state) -{ - XSSIDPlay1 *engine; - assert(state); - - engine = (XSSIDPlay1 *) state->internal; - - /* Free internals */ - if (engine->emu) { - delete engine->emu; - engine->emu = NULL; - } - - if (engine->tune) { - delete engine->tune; - engine->tune = NULL; - } - - xs_sidplay1_delete(state); - - g_free(engine); - state->internal = NULL; -} - - -/* Initialize current song and sub-tune - */ -gboolean xs_sidplay1_initsong(XSEngineState * state) -{ - XSSIDPlay1 *engine; - assert(state); - - engine = (XSSIDPlay1 *) state->internal; - if (!engine) return FALSE; - - if (!engine->tune) { - xs_error("[SIDPlay1] SID-tune struct pointer was NULL. This should not happen, report to XMMS-SID author.\n"); - return FALSE; - } - - if (!engine->tune->getStatus()) { - xs_error("[SIDPlay1] SID-tune status check failed. This should not happen, report to XMMS-SID author.\n"); - return FALSE; - } - - return sidEmuInitializeSong(*engine->emu, *engine->tune, state->currSong); -} - - -/* Emulate and render audio data to given buffer - */ -guint xs_sidplay1_fillbuffer(XSEngineState * state, gchar * audioBuffer, guint audioBufSize) -{ - XSSIDPlay1 *engine; - assert(state); - - engine = (XSSIDPlay1 *) state->internal; - if (!engine) return 0; - - sidEmuFillBuffer(*engine->emu, *engine->tune, audioBuffer, audioBufSize); - - return audioBufSize; -} - - -/* Load a given SID-tune file - */ -gboolean xs_sidplay1_load(XSEngineState * state, gchar * filename) -{ - XSSIDPlay1 *engine; - assert(state); - - engine = (XSSIDPlay1 *) state->internal; - if (!engine) return FALSE; - - /* Try to get the tune */ - if (!filename) return FALSE; - - if (xs_fload_buffer(filename, &(engine->buf), &(engine->bufSize)) != 0) - return FALSE; - - if (!engine->tune->load(engine->buf, engine->bufSize)) - return FALSE; - - return TRUE; -} - - -/* Delete INTERNAL information - */ -void xs_sidplay1_delete(XSEngineState * state) -{ - XSSIDPlay1 *engine; - assert(state); - - engine = (XSSIDPlay1 *) state->internal; - if (!engine) return; - - g_free(engine->buf); - engine->buf = NULL; - engine->bufSize = 0; -} - - -} /* extern "C" */ -#endif /* HAVE_SIDPLAY1 */ diff -r c0e892fa914a -r a7ee5dc23e78 src/xs_sidplay1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_sidplay1.cpp Thu Nov 08 20:47:05 2012 +0200 @@ -0,0 +1,352 @@ +/* + XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) + + libSIDPlay v1 support + + Programmed and designed by Matti 'ccr' Hamalainen + (C) Copyright 1999-2007 Tecnic Software productions (TNSP) + + 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "xmms-sid.h" + +#ifdef HAVE_SIDPLAY1 + +#include "xs_sidplay1.h" +#include "xs_slsup.h" +#include "xs_config.h" + +#include +#include +#include + + +/* Maximum audio frequency supported by libSIDPlay v1 */ +#define SIDPLAY1_MAX_FREQ (48000) + + +typedef struct { + emuEngine *emu; + emuConfig currConfig; + sidTune *tune; + guint8 *buf; + size_t bufSize; +} XSSIDPlay1; + + +/* We need to 'export' all this pseudo-C++ crap */ +extern "C" { + + +/* Return song information + */ +#define TFUNCTION xs_sidplay1_getinfo +#define TFUNCTION2 xs_sidplay1_updateinfo +#define TTUNEINFO sidTuneInfo +#define TTUNE sidTune +#define TENGINE XSSIDPlay1 +#include "xs_sidplay.h" + + +/* Check if we can play the given file + */ +gboolean xs_sidplay1_probe(XSFile *f) +{ + gchar tmpBuf[4]; + + if (!f) return FALSE; + + if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4) + return FALSE; + + if (!strncmp(tmpBuf, "PSID", 4)) + return TRUE; + else + return FALSE; +} + + +/* Initialize SIDPlay1 + */ +gboolean xs_sidplay1_init(XSEngineState * state) +{ + gint tmpFreq; + XSSIDPlay1 *engine; + assert(state); + + /* Allocate internal structures */ + engine = (XSSIDPlay1 *) g_malloc0(sizeof(XSSIDPlay1)); + if (!engine) return FALSE; + + /* Initialize engine */ + engine->emu = new emuEngine(); + if (!engine->emu) { + xs_error("[SIDPlay1] Could not initialize emulation engine.\n"); + g_free(engine); + return FALSE; + } + + /* Verify endianess */ + if (!engine->emu->verifyEndianess()) { + xs_error("[SIDPlay1] Endianess verification failed.\n"); + delete engine->emu; + g_free(engine); + return FALSE; + } + + state->internal = engine; + + /* Get current configuration */ + engine->emu->getConfig(engine->currConfig); + + /* Configure channel parameters */ + switch (state->audioChannels) { + + case XS_CHN_AUTOPAN: + engine->currConfig.channels = SIDEMU_STEREO; + engine->currConfig.autoPanning = SIDEMU_CENTEREDAUTOPANNING; + engine->currConfig.volumeControl = SIDEMU_FULLPANNING; + break; + + case XS_CHN_STEREO: + engine->currConfig.channels = SIDEMU_STEREO; + engine->currConfig.autoPanning = SIDEMU_NONE; + engine->currConfig.volumeControl = SIDEMU_NONE; + break; + + case XS_CHN_MONO: + default: + engine->currConfig.channels = SIDEMU_MONO; + engine->currConfig.autoPanning = SIDEMU_NONE; + engine->currConfig.volumeControl = SIDEMU_NONE; + state->audioChannels = XS_CHN_MONO; + break; + } + + + /* Memory mode settings */ + switch (xs_cfg.memoryMode) { + case XS_MPU_TRANSPARENT_ROM: + engine->currConfig.memoryMode = MPU_TRANSPARENT_ROM; + break; + + case XS_MPU_PLAYSID_ENVIRONMENT: + engine->currConfig.memoryMode = MPU_PLAYSID_ENVIRONMENT; + break; + + case XS_MPU_BANK_SWITCHING: + default: + engine->currConfig.memoryMode = MPU_BANK_SWITCHING; + xs_cfg.memoryMode = XS_MPU_BANK_SWITCHING; + break; + } + + + /* Audio parameters sanity checking and setup */ + engine->currConfig.bitsPerSample = state->audioBitsPerSample; + tmpFreq = state->audioFrequency; + + if (tmpFreq > SIDPLAY1_MAX_FREQ) + tmpFreq = SIDPLAY1_MAX_FREQ; + + engine->currConfig.frequency = tmpFreq; + + switch (state->audioBitsPerSample) { + case XS_RES_8BIT: + switch (state->audioFormat) { + case FMT_S8: + state->audioFormat = FMT_S8; + engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; + break; + + case FMT_U8: + default: + state->audioFormat = FMT_U8; + engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; + break; + } + break; + + case XS_RES_16BIT: + default: + switch (state->audioFormat) { + case FMT_U16_NE: + case FMT_U16_LE: + case FMT_U16_BE: + state->audioFormat = FMT_U16_NE; + engine->currConfig.sampleFormat = SIDEMU_UNSIGNED_PCM; + break; + + case FMT_S16_NE: + case FMT_S16_LE: + case FMT_S16_BE: + default: + state->audioFormat = FMT_S16_NE; + engine->currConfig.sampleFormat = SIDEMU_SIGNED_PCM; + break; + } + break; + } + + /* Clockspeed settings */ + switch (xs_cfg.clockSpeed) { + case XS_CLOCK_NTSC: + engine->currConfig.clockSpeed = SIDTUNE_CLOCK_NTSC; + break; + + case XS_CLOCK_PAL: + default: + engine->currConfig.clockSpeed = SIDTUNE_CLOCK_PAL; + xs_cfg.clockSpeed = XS_CLOCK_PAL; + break; + } + + engine->currConfig.forceSongSpeed = xs_cfg.forceSpeed; + + + /* Configure rest of the emulation */ + /* if (xs_cfg.forceModel) */ + engine->currConfig.mos8580 = xs_cfg.mos8580; + engine->currConfig.emulateFilter = xs_cfg.emulateFilters; + engine->currConfig.filterFs = xs_cfg.sid1Filter.fs; + engine->currConfig.filterFm = xs_cfg.sid1Filter.fm; + engine->currConfig.filterFt = xs_cfg.sid1Filter.ft; + + + /* Now set the emulator configuration */ + if (!engine->emu->setConfig(engine->currConfig)) { + xs_error("[SIDPlay1] Emulator engine configuration failed!\n"); + return FALSE; + } + + /* Create sidtune object */ + engine->tune = new sidTune(0); + if (!engine->tune) { + xs_error("[SIDPlay1] Could not initialize SIDTune object.\n"); + return FALSE; + } + + return TRUE; +} + + +/* Close SIDPlay1 engine + */ +void xs_sidplay1_close(XSEngineState * state) +{ + XSSIDPlay1 *engine; + assert(state); + + engine = (XSSIDPlay1 *) state->internal; + + /* Free internals */ + if (engine->emu) { + delete engine->emu; + engine->emu = NULL; + } + + if (engine->tune) { + delete engine->tune; + engine->tune = NULL; + } + + xs_sidplay1_delete(state); + + g_free(engine); + state->internal = NULL; +} + + +/* Initialize current song and sub-tune + */ +gboolean xs_sidplay1_initsong(XSEngineState * state) +{ + XSSIDPlay1 *engine; + assert(state); + + engine = (XSSIDPlay1 *) state->internal; + if (!engine) return FALSE; + + if (!engine->tune) { + xs_error("[SIDPlay1] SID-tune struct pointer was NULL. This should not happen, report to XMMS-SID author.\n"); + return FALSE; + } + + if (!engine->tune->getStatus()) { + xs_error("[SIDPlay1] SID-tune status check failed. This should not happen, report to XMMS-SID author.\n"); + return FALSE; + } + + return sidEmuInitializeSong(*engine->emu, *engine->tune, state->currSong); +} + + +/* Emulate and render audio data to given buffer + */ +guint xs_sidplay1_fillbuffer(XSEngineState * state, gchar * audioBuffer, guint audioBufSize) +{ + XSSIDPlay1 *engine; + assert(state); + + engine = (XSSIDPlay1 *) state->internal; + if (!engine) return 0; + + sidEmuFillBuffer(*engine->emu, *engine->tune, audioBuffer, audioBufSize); + + return audioBufSize; +} + + +/* Load a given SID-tune file + */ +gboolean xs_sidplay1_load(XSEngineState * state, gchar * filename) +{ + XSSIDPlay1 *engine; + assert(state); + + engine = (XSSIDPlay1 *) state->internal; + if (!engine) return FALSE; + + /* Try to get the tune */ + if (!filename) return FALSE; + + if (xs_fload_buffer(filename, &(engine->buf), &(engine->bufSize)) != 0) + return FALSE; + + if (!engine->tune->load(engine->buf, engine->bufSize)) + return FALSE; + + return TRUE; +} + + +/* Delete INTERNAL information + */ +void xs_sidplay1_delete(XSEngineState * state) +{ + XSSIDPlay1 *engine; + assert(state); + + engine = (XSSIDPlay1 *) state->internal; + if (!engine) return; + + g_free(engine->buf); + engine->buf = NULL; + engine->bufSize = 0; +} + + +} /* extern "C" */ +#endif /* HAVE_SIDPLAY1 */ diff -r c0e892fa914a -r a7ee5dc23e78 src/xs_sidplay2.cc --- a/src/xs_sidplay2.cc Thu Nov 08 20:45:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,441 +0,0 @@ -/* - XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) - - libSIDPlay v2 support - - Programmed and designed by Matti 'ccr' Hamalainen - (C) Copyright 1999-2012 Tecnic Software productions (TNSP) - - 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "xmms-sid.h" - -#ifdef HAVE_SIDPLAY2 - -#include "xs_sidplay2.h" -#include "xs_slsup.h" -#include "xs_config.h" - -#include -#if G_BYTE_ORDER == G_BIG_ENDIAN -# define SID2_NATIVE_UNSIGNED SID2_BIG_UNSIGNED -# define SID2_NATIVE_SIGNED SID2_BIG_SIGNED -#elif G_BYTE_ORDER == G_LITTLE_ENDIAN -# define SID2_NATIVE_UNSIGNED SID2_LITTLE_UNSIGNED -# define SID2_NATIVE_SIGNED SID2_LITTLE_SIGNED -#else -# error Unsupported endianess! -#endif - - -class XSSIDPlay2 { -public: - sidplay2 emu; - sid2_config_t config; - SidTune tune; - - XSSIDPlay2(void); - virtual ~XSSIDPlay2(void); -}; - - -#ifdef HAVE_RESID_BUILDER -# include -#endif - -#ifdef HAVE_HARDSID_BUILDER -# include -#endif - - -XSSIDPlay2::XSSIDPlay2(void) : tune(0) -{ -} - - -XSSIDPlay2::~XSSIDPlay2(void) -{ - emu.load(NULL); -} - - -/* We need to 'export' all this pseudo-C++ crap */ -extern "C" { - - -/* Return song information - */ -#define TFUNCTION xs_sidplay2_getinfo -#define TFUNCTION2 xs_sidplay2_updateinfo -#define TTUNEINFO SidTuneInfo -#define TTUNE SidTune -#define TENGINE XSSIDPlay2 -#include "xs_sidplay.h" - - -/* Check if we can play the given file - */ -gboolean xs_sidplay2_probe(XSFile *f) -{ - gchar tmpBuf[5]; - - if (!f) return FALSE; - - if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4) - return FALSE; - - if (!strncmp(tmpBuf, "PSID", 4) || !strncmp(tmpBuf, "RSID", 4)) - return TRUE; - else - return FALSE; -} - - -/* Initialize SIDPlay2 - */ -gboolean xs_sidplay2_init(XSEngineState * state) -{ - XSSIDPlay2 *engine; - sid_filter_t tmpFilter; - xs_sid_filter_t *f; - gint i; - assert(state); - - /* Allocate internal structures */ - engine = new XSSIDPlay2(); - state->internal = engine; - if (!engine) - return FALSE; - - /* Get current configuration */ - engine->config = engine->emu.config(); - - /* Configure channels and stuff */ - switch (state->audioChannels) - { - case XS_CHN_AUTOPAN: - engine->config.playback = sid2_stereo; - break; - - case XS_CHN_STEREO: - engine->config.playback = sid2_stereo; - break; - - case XS_CHN_MONO: - default: - engine->config.playback = sid2_mono; - state->audioChannels = XS_CHN_MONO; - break; - } - - - /* Memory mode settings */ - switch (xs_cfg.memoryMode) - { - case XS_MPU_BANK_SWITCHING: - engine->config.environment = sid2_envBS; - break; - - case XS_MPU_TRANSPARENT_ROM: - engine->config.environment = sid2_envTP; - break; - - case XS_MPU_PLAYSID_ENVIRONMENT: - engine->config.environment = sid2_envPS; - break; - - case XS_MPU_REAL: - default: - engine->config.environment = sid2_envR; - xs_cfg.memoryMode = XS_MPU_REAL; - break; - } - - - /* Audio parameters sanity checking and setup */ - engine->config.precision = state->audioBitsPerSample; - engine->config.frequency = state->audioFrequency; - - - switch (state->audioBitsPerSample) - { - case XS_RES_8BIT: - state->audioFormat = FMT_U8; - engine->config.sampleFormat = SID2_LITTLE_UNSIGNED; - break; - - case XS_RES_16BIT: - default: - switch (state->audioFormat) - { - case FMT_U16_LE: - engine->config.sampleFormat = SID2_LITTLE_UNSIGNED; - break; - - case FMT_U16_BE: - engine->config.sampleFormat = SID2_BIG_UNSIGNED; - break; - - case FMT_U16_NE: - engine->config.sampleFormat = SID2_NATIVE_UNSIGNED; - break; - - case FMT_S16_LE: - engine->config.sampleFormat = SID2_LITTLE_SIGNED; - break; - - case FMT_S16_BE: - engine->config.sampleFormat = SID2_BIG_SIGNED; - break; - - default: - state->audioFormat = FMT_S16_NE; - engine->config.sampleFormat = SID2_NATIVE_SIGNED; - break; - } - break; - } - - /* Convert filter */ - f = &(xs_cfg.sid2Filter); - XSDEBUG("using filter '%s', %d points\n", f->name, f->npoints); - if (f->npoints > XS_SIDPLAY2_NFPOINTS) - { - xs_error("[SIDPlay2] Invalid number of filter curve points (%d > %d)\n", - f->npoints, XS_SIDPLAY2_NFPOINTS); - f->npoints = XS_SIDPLAY2_NFPOINTS; - } - - tmpFilter.points = f->npoints; - for (i = 0; i < f->npoints; i++) - { - tmpFilter.cutoff[i][0] = f->points[i].x; - tmpFilter.cutoff[i][1] = f->points[i].y; - } - - /* Initialize builder object */ - XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids); - - switch (xs_cfg.sid2Builder) - { -#ifdef HAVE_RESID_BUILDER - case XS_BLD_RESID: - { - ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder"); - if (rs) - { - engine->config.sidEmulation = rs; - if (!*rs) return FALSE; - rs->create((engine->emu.info()).maxsids); - if (!*rs) return FALSE; - } - } - break; -#endif - -#ifdef HAVE_HARDSID_BUILDER - case XS_BLD_HARDSID: - { - HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); - engine->config.sidEmulation = (sidbuilder *) hs; - if (hs) - { - hs->create((engine->emu.info()).maxsids); - if (!*hs) - { - xs_error("hardSID->create() failed.\n"); - return FALSE; - } - } - } - break; -#endif - - default: - xs_error("[SIDPlay2] Invalid or unsupported builder selected.\n"); - break; - } - - if (!engine->config.sidEmulation) - { - xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); - return FALSE; - } - -#if 0 - // Setup filter - engine->config.sidEmulation->filter(xs_cfg.emulateFilters); - if (!*(engine->config.sidEmulation)) - { - xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); - return FALSE; - } -#endif - - XSDEBUG("%s\n", engine->config.sidEmulation->credits()); - - /* Clockspeed settings */ - switch (xs_cfg.clockSpeed) - { - case XS_CLOCK_NTSC: - engine->config.clockDefault = SID2_CLOCK_NTSC; - break; - - default: - case XS_CLOCK_PAL: - engine->config.clockDefault = SID2_CLOCK_PAL; - xs_cfg.clockSpeed = XS_CLOCK_PAL; - break; - } - - - /* Configure rest of the emulation */ - if (xs_cfg.forceSpeed) - { - engine->config.clockForced = true; - engine->config.clockSpeed = engine->config.clockDefault; - } - else - { - engine->config.clockForced = false; - engine->config.clockSpeed = SID2_CLOCK_CORRECT; - } - - - if (xs_cfg.sid2OptLevel < 0 || xs_cfg.sid2OptLevel > SID2_MAX_OPTIMISATION) - { - xs_error("Invalid sid2OptLevel=%d, falling back to %d.\n", - xs_cfg.sid2OptLevel, SID2_DEFAULT_OPTIMISATION); - - xs_cfg.sid2OptLevel = SID2_DEFAULT_OPTIMISATION; - } - engine->config.optimisation = xs_cfg.sid2OptLevel; - - engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581; - engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; - engine->config.sidSamples = TRUE; - - return TRUE; -} - - -/* Close SIDPlay2 engine - */ -void xs_sidplay2_close(XSEngineState * state) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; - - xs_sidplay2_delete(state); - - if (engine) - { - delete engine; - engine = NULL; - } - - state->internal = NULL; -} - - -/* Initialize current song and sub-tune - */ -gboolean xs_sidplay2_initsong(XSEngineState * state) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; - - if (!engine) - return FALSE; - - if (!engine->tune.selectSong(state->currSong)) - { - xs_error("[SIDPlay2] tune.selectSong() failed\n"); - return FALSE; - } - - if (engine->emu.load(&(engine->tune)) < 0) - { - xs_error("[SIDPlay2] emu.load() failed\n"); - return FALSE; - } - - if (engine->emu.config(engine->config) < 0) - { - xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); - return FALSE; - } - - return TRUE; -} - - -/* Emulate and render audio data to given buffer - */ -guint xs_sidplay2_fillbuffer(XSEngineState * state, gchar * audioBuffer, guint audioBufSize) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; - - if (!engine) - return 0; - - return engine->emu.play(audioBuffer, audioBufSize); -} - - -/* Load a given SID-tune file - */ -gboolean xs_sidplay2_load(XSEngineState * state, gchar * filename) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; - - if (!engine || !filename) - return FALSE; - - engine->tune.load(filename); - if (!engine->tune) - { - xs_error("Could not load file '%s': %s\n", - filename, (engine->tune.getInfo()).statusString); - return FALSE; - } - - return TRUE; -} - - -/* Delete INTERNAL information - */ -void xs_sidplay2_delete(XSEngineState * state) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; -} - - -/* Hardware backend flushing - */ -void xs_sidplay2_flush(XSEngineState * state) -{ - XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; - -#ifdef HAVE_HARDSID_BUILDER - if (xs_cfg.sid2Builder == XS_BLD_HARDSID) - { - ((HardSIDBuilder *) engine->config.sidEmulation)->flush(); - } -#endif -} - - -} /* extern "C" */ -#endif /* HAVE_SIDPLAY2 */ diff -r c0e892fa914a -r a7ee5dc23e78 src/xs_sidplay2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_sidplay2.cpp Thu Nov 08 20:47:05 2012 +0200 @@ -0,0 +1,441 @@ +/* + XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) + + libSIDPlay v2 support + + Programmed and designed by Matti 'ccr' Hamalainen + (C) Copyright 1999-2012 Tecnic Software productions (TNSP) + + 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "xmms-sid.h" + +#ifdef HAVE_SIDPLAY2 + +#include "xs_sidplay2.h" +#include "xs_slsup.h" +#include "xs_config.h" + +#include +#if G_BYTE_ORDER == G_BIG_ENDIAN +# define SID2_NATIVE_UNSIGNED SID2_BIG_UNSIGNED +# define SID2_NATIVE_SIGNED SID2_BIG_SIGNED +#elif G_BYTE_ORDER == G_LITTLE_ENDIAN +# define SID2_NATIVE_UNSIGNED SID2_LITTLE_UNSIGNED +# define SID2_NATIVE_SIGNED SID2_LITTLE_SIGNED +#else +# error Unsupported endianess! +#endif + + +class XSSIDPlay2 { +public: + sidplay2 emu; + sid2_config_t config; + SidTune tune; + + XSSIDPlay2(void); + virtual ~XSSIDPlay2(void); +}; + + +#ifdef HAVE_RESID_BUILDER +# include +#endif + +#ifdef HAVE_HARDSID_BUILDER +# include +#endif + + +XSSIDPlay2::XSSIDPlay2(void) : tune(0) +{ +} + + +XSSIDPlay2::~XSSIDPlay2(void) +{ + emu.load(NULL); +} + + +/* We need to 'export' all this pseudo-C++ crap */ +extern "C" { + + +/* Return song information + */ +#define TFUNCTION xs_sidplay2_getinfo +#define TFUNCTION2 xs_sidplay2_updateinfo +#define TTUNEINFO SidTuneInfo +#define TTUNE SidTune +#define TENGINE XSSIDPlay2 +#include "xs_sidplay.h" + + +/* Check if we can play the given file + */ +gboolean xs_sidplay2_probe(XSFile *f) +{ + gchar tmpBuf[5]; + + if (!f) return FALSE; + + if (xs_fread(tmpBuf, sizeof(gchar), 4, f) != 4) + return FALSE; + + if (!strncmp(tmpBuf, "PSID", 4) || !strncmp(tmpBuf, "RSID", 4)) + return TRUE; + else + return FALSE; +} + + +/* Initialize SIDPlay2 + */ +gboolean xs_sidplay2_init(XSEngineState * state) +{ + XSSIDPlay2 *engine; + sid_filter_t tmpFilter; + xs_sid_filter_t *f; + gint i; + assert(state); + + /* Allocate internal structures */ + engine = new XSSIDPlay2(); + state->internal = engine; + if (!engine) + return FALSE; + + /* Get current configuration */ + engine->config = engine->emu.config(); + + /* Configure channels and stuff */ + switch (state->audioChannels) + { + case XS_CHN_AUTOPAN: + engine->config.playback = sid2_stereo; + break; + + case XS_CHN_STEREO: + engine->config.playback = sid2_stereo; + break; + + case XS_CHN_MONO: + default: + engine->config.playback = sid2_mono; + state->audioChannels = XS_CHN_MONO; + break; + } + + + /* Memory mode settings */ + switch (xs_cfg.memoryMode) + { + case XS_MPU_BANK_SWITCHING: + engine->config.environment = sid2_envBS; + break; + + case XS_MPU_TRANSPARENT_ROM: + engine->config.environment = sid2_envTP; + break; + + case XS_MPU_PLAYSID_ENVIRONMENT: + engine->config.environment = sid2_envPS; + break; + + case XS_MPU_REAL: + default: + engine->config.environment = sid2_envR; + xs_cfg.memoryMode = XS_MPU_REAL; + break; + } + + + /* Audio parameters sanity checking and setup */ + engine->config.precision = state->audioBitsPerSample; + engine->config.frequency = state->audioFrequency; + + + switch (state->audioBitsPerSample) + { + case XS_RES_8BIT: + state->audioFormat = FMT_U8; + engine->config.sampleFormat = SID2_LITTLE_UNSIGNED; + break; + + case XS_RES_16BIT: + default: + switch (state->audioFormat) + { + case FMT_U16_LE: + engine->config.sampleFormat = SID2_LITTLE_UNSIGNED; + break; + + case FMT_U16_BE: + engine->config.sampleFormat = SID2_BIG_UNSIGNED; + break; + + case FMT_U16_NE: + engine->config.sampleFormat = SID2_NATIVE_UNSIGNED; + break; + + case FMT_S16_LE: + engine->config.sampleFormat = SID2_LITTLE_SIGNED; + break; + + case FMT_S16_BE: + engine->config.sampleFormat = SID2_BIG_SIGNED; + break; + + default: + state->audioFormat = FMT_S16_NE; + engine->config.sampleFormat = SID2_NATIVE_SIGNED; + break; + } + break; + } + + /* Convert filter */ + f = &(xs_cfg.sid2Filter); + XSDEBUG("using filter '%s', %d points\n", f->name, f->npoints); + if (f->npoints > XS_SIDPLAY2_NFPOINTS) + { + xs_error("[SIDPlay2] Invalid number of filter curve points (%d > %d)\n", + f->npoints, XS_SIDPLAY2_NFPOINTS); + f->npoints = XS_SIDPLAY2_NFPOINTS; + } + + tmpFilter.points = f->npoints; + for (i = 0; i < f->npoints; i++) + { + tmpFilter.cutoff[i][0] = f->points[i].x; + tmpFilter.cutoff[i][1] = f->points[i].y; + } + + /* Initialize builder object */ + XSDEBUG("init builder #%i, maxsids=%i\n", xs_cfg.sid2Builder, (engine->emu.info()).maxsids); + + switch (xs_cfg.sid2Builder) + { +#ifdef HAVE_RESID_BUILDER + case XS_BLD_RESID: + { + ReSIDBuilder *rs = new ReSIDBuilder("ReSID builder"); + if (rs) + { + engine->config.sidEmulation = rs; + if (!*rs) return FALSE; + rs->create((engine->emu.info()).maxsids); + if (!*rs) return FALSE; + } + } + break; +#endif + +#ifdef HAVE_HARDSID_BUILDER + case XS_BLD_HARDSID: + { + HardSIDBuilder *hs = new HardSIDBuilder("HardSID builder (FP)"); + engine->config.sidEmulation = (sidbuilder *) hs; + if (hs) + { + hs->create((engine->emu.info()).maxsids); + if (!*hs) + { + xs_error("hardSID->create() failed.\n"); + return FALSE; + } + } + } + break; +#endif + + default: + xs_error("[SIDPlay2] Invalid or unsupported builder selected.\n"); + break; + } + + if (!engine->config.sidEmulation) + { + xs_error("[SIDPlay2] Could not initialize SIDBuilder object.\n"); + return FALSE; + } + +#if 0 + // Setup filter + engine->config.sidEmulation->filter(xs_cfg.emulateFilters); + if (!*(engine->config.sidEmulation)) + { + xs_error("builder->filter(%d) failed.\n", xs_cfg.emulateFilters); + return FALSE; + } +#endif + + XSDEBUG("%s\n", engine->config.sidEmulation->credits()); + + /* Clockspeed settings */ + switch (xs_cfg.clockSpeed) + { + case XS_CLOCK_NTSC: + engine->config.clockDefault = SID2_CLOCK_NTSC; + break; + + default: + case XS_CLOCK_PAL: + engine->config.clockDefault = SID2_CLOCK_PAL; + xs_cfg.clockSpeed = XS_CLOCK_PAL; + break; + } + + + /* Configure rest of the emulation */ + if (xs_cfg.forceSpeed) + { + engine->config.clockForced = true; + engine->config.clockSpeed = engine->config.clockDefault; + } + else + { + engine->config.clockForced = false; + engine->config.clockSpeed = SID2_CLOCK_CORRECT; + } + + + if (xs_cfg.sid2OptLevel < 0 || xs_cfg.sid2OptLevel > SID2_MAX_OPTIMISATION) + { + xs_error("Invalid sid2OptLevel=%d, falling back to %d.\n", + xs_cfg.sid2OptLevel, SID2_DEFAULT_OPTIMISATION); + + xs_cfg.sid2OptLevel = SID2_DEFAULT_OPTIMISATION; + } + engine->config.optimisation = xs_cfg.sid2OptLevel; + + engine->config.sidDefault = xs_cfg.mos8580 ? SID2_MOS8580 : SID2_MOS6581; + engine->config.sidModel = xs_cfg.forceModel ? engine->config.sidDefault : SID2_MODEL_CORRECT; + engine->config.sidSamples = TRUE; + + return TRUE; +} + + +/* Close SIDPlay2 engine + */ +void xs_sidplay2_close(XSEngineState * state) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; + + xs_sidplay2_delete(state); + + if (engine) + { + delete engine; + engine = NULL; + } + + state->internal = NULL; +} + + +/* Initialize current song and sub-tune + */ +gboolean xs_sidplay2_initsong(XSEngineState * state) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; + + if (!engine) + return FALSE; + + if (!engine->tune.selectSong(state->currSong)) + { + xs_error("[SIDPlay2] tune.selectSong() failed\n"); + return FALSE; + } + + if (engine->emu.load(&(engine->tune)) < 0) + { + xs_error("[SIDPlay2] emu.load() failed\n"); + return FALSE; + } + + if (engine->emu.config(engine->config) < 0) + { + xs_error("[SIDPlay2] Emulator engine configuration failed!\n"); + return FALSE; + } + + return TRUE; +} + + +/* Emulate and render audio data to given buffer + */ +guint xs_sidplay2_fillbuffer(XSEngineState * state, gchar * audioBuffer, guint audioBufSize) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; + + if (!engine) + return 0; + + return engine->emu.play(audioBuffer, audioBufSize); +} + + +/* Load a given SID-tune file + */ +gboolean xs_sidplay2_load(XSEngineState * state, gchar * filename) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; + + if (!engine || !filename) + return FALSE; + + engine->tune.load(filename); + if (!engine->tune) + { + xs_error("Could not load file '%s': %s\n", + filename, (engine->tune.getInfo()).statusString); + return FALSE; + } + + return TRUE; +} + + +/* Delete INTERNAL information + */ +void xs_sidplay2_delete(XSEngineState * state) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; +} + + +/* Hardware backend flushing + */ +void xs_sidplay2_flush(XSEngineState * state) +{ + XSSIDPlay2 *engine = (XSSIDPlay2 *) state->internal; + +#ifdef HAVE_HARDSID_BUILDER + if (xs_cfg.sid2Builder == XS_BLD_HARDSID) + { + ((HardSIDBuilder *) engine->config.sidEmulation)->flush(); + } +#endif +} + + +} /* extern "C" */ +#endif /* HAVE_SIDPLAY2 */