libsidplayfp  1.0.3
player.h
00001 /*
00002  * This file is part of libsidplayfp, a SID player engine.
00003  *
00004  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
00005  * Copyright 2007-2010 Antti Lankila
00006  * Copyright 2000-2001 Simon White
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021  */
00022 
00023 
00024 #ifndef PLAYER_H
00025 #define PLAYER_H
00026 
00027 #include "SidConfig.h"
00028 #include "SidTune.h"
00029 #include "SidTuneInfo.h"
00030 #include "SidInfoImpl.h"
00031 #include "sidrandom.h"
00032 #include "mixer.h"
00033 #include "c64/c64.h"
00034 
00035 #ifdef HAVE_CONFIG_H
00036 #  include "config.h"
00037 #endif
00038 
00039 #ifdef PC64_TESTSUITE
00040 #  include <string.h>
00041 #endif
00042 
00043 
00044 SIDPLAYFP_NAMESPACE_START
00045 
00046 class Player
00047 #ifdef PC64_TESTSUITE
00048   : public testEnv
00049 #endif
00050 {
00051 private:
00052     class configError
00053     {
00054     private:
00055         const char* m_msg;
00056 
00057     public:
00058         configError(const char* msg) : m_msg(msg) {}
00059         const char* message() const { return m_msg; }
00060     };
00061 
00062 private:
00063     c64 m_c64;
00064 
00065     Mixer m_mixer;
00066 
00067     SidTune *m_tune;
00068     SidInfoImpl m_info;
00069 
00070     // User Configuration Settings
00071     SidConfig m_cfg;
00072 
00073     const char *m_errorString;
00074 
00075     volatile bool m_isPlaying;
00076 
00077     sidrandom m_rand;
00078 
00079 private:
00080     c64::model_t c64model(SidConfig::c64_model_t defaultModel, bool forced);
00081     void initialise();
00082     void sidRelease();
00083     void sidCreate(sidbuilder *builder, SidConfig::sid_model_t defaultModel,
00084                     bool forced, unsigned int channels);
00085     void sidParams(double cpuFreq, int frequency,
00086                     SidConfig::sampling_method_t sampling, bool fastSampling);
00087 
00088     static SidConfig::sid_model_t getModel (SidTuneInfo::model_t sidModel, SidConfig::sid_model_t defaultModel, bool forced);
00089 
00090 #ifdef PC64_TESTSUITE
00091     void load(const char *file)
00092     {
00093         char name[0x100] = PC64_TESTSUITE;
00094         strcat (name, file);
00095         strcat (name, ".prg");
00096 
00097         m_tune->load (name);
00098         m_tune->selectSong(0);
00099         initialise();
00100     }
00101 #endif
00102 
00103 public:
00104     Player();
00105     ~Player() {}
00106 
00107     const SidConfig &config() const { return m_cfg; }
00108 
00109     const SidInfo &info() const { return m_info; }
00110 
00111     bool config(const SidConfig &cfg);
00112 
00113     bool fastForward(unsigned int percent);
00114 
00115     bool load(SidTune *tune);
00116 
00117     double cpuFreq() const { return m_c64.getMainCpuSpeed(); }
00118 
00119     uint_least32_t play(short *buffer, uint_least32_t samples);
00120 
00121     bool isPlaying() const { return m_isPlaying; }
00122 
00123     void stop();
00124 
00125     uint_least32_t time() const { return (uint_least32_t)(m_c64.getEventScheduler().getTime(EVENT_CLOCK_PHI1) / cpuFreq()); }
00126 
00127     void debug(const bool enable, FILE *out) { m_c64.debug (enable, out); }
00128 
00129     void mute(unsigned int sidNum, unsigned int voice, bool enable);
00130 
00131     const char *error() const { return m_errorString; }
00132 
00133     void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character);
00134 
00135     EventContext *getEventScheduler() { return m_c64.getEventScheduler(); }
00136 
00137     uint_least16_t getCia1TimerA() const { return m_c64.getCia1TimerA(); }
00138 };
00139 
00140 SIDPLAYFP_NAMESPACE_STOP
00141 
00142 #endif // PLAYER_H