view src/xs_sidplay2.cc @ 73:2bc607888f53

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...
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 14 Sep 2003 03:14:01 +0000
parents
children 8cb66a3f75f7
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->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 */