libsidplayfp  1.1.0
player.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2000-2001 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef PLAYER_H
25 #define PLAYER_H
26 
27 #include "SidConfig.h"
28 #include "SidTune.h"
29 #include "SidTuneInfo.h"
30 #include "SidInfoImpl.h"
31 #include "sidrandom.h"
32 #include "mixer.h"
33 #include "c64/c64.h"
34 
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38 
39 #ifdef PC64_TESTSUITE
40 # include <string.h>
41 #endif
42 
43 
44 SIDPLAYFP_NAMESPACE_START
45 
46 class Player
47 #ifdef PC64_TESTSUITE
48  : public testEnv
49 #endif
50 {
51 private:
52  class configError
53  {
54  private:
55  const char* m_msg;
56 
57  public:
58  configError(const char* msg) : m_msg(msg) {}
59  const char* message() const { return m_msg; }
60  };
61 
62 private:
63  c64 m_c64;
64 
65  Mixer m_mixer;
66 
67  SidTune *m_tune;
68  SidInfoImpl m_info;
69 
70  // User Configuration Settings
71  SidConfig m_cfg;
72 
73  const char *m_errorString;
74 
75  volatile bool m_isPlaying;
76 
77  sidrandom m_rand;
78 
79 private:
80  c64::model_t c64model(SidConfig::c64_model_t defaultModel, bool forced);
81  void initialise();
82  void sidRelease();
83  void sidCreate(sidbuilder *builder, SidConfig::sid_model_t defaultModel,
84  bool forced, unsigned int channels);
85  void sidParams(double cpuFreq, int frequency,
86  SidConfig::sampling_method_t sampling, bool fastSampling);
87 
88  static SidConfig::sid_model_t getModel (SidTuneInfo::model_t sidModel, SidConfig::sid_model_t defaultModel, bool forced);
89 
90 #ifdef PC64_TESTSUITE
91  void load(const char *file)
92  {
93  char name[0x100] = PC64_TESTSUITE;
94  strcat (name, file);
95  strcat (name, ".prg");
96 
97  m_tune->load (name);
98  m_tune->selectSong(0);
99  initialise();
100  }
101 #endif
102 
103 public:
104  Player();
105  ~Player() {}
106 
107  const SidConfig &config() const { return m_cfg; }
108 
109  const SidInfo &info() const { return m_info; }
110 
111  bool config(const SidConfig &cfg);
112 
113  bool fastForward(unsigned int percent);
114 
115  bool load(SidTune *tune);
116 
117  double cpuFreq() const { return m_c64.getMainCpuSpeed(); }
118 
119  uint_least32_t play(short *buffer, uint_least32_t samples);
120 
121  bool isPlaying() const { return m_isPlaying; }
122 
123  void stop();
124 
125  uint_least32_t time() const { return (uint_least32_t)(m_c64.getEventScheduler().getTime(EVENT_CLOCK_PHI1) / cpuFreq()); }
126 
127  void debug(const bool enable, FILE *out) { m_c64.debug (enable, out); }
128 
129  void mute(unsigned int sidNum, unsigned int voice, bool enable);
130 
131  const char *error() const { return m_errorString; }
132 
133  void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character);
134 
135  EventContext *getEventScheduler() { return m_c64.getEventScheduler(); }
136 
137  uint_least16_t getCia1TimerA() const { return m_c64.getCia1TimerA(); }
138 };
139 
140 SIDPLAYFP_NAMESPACE_STOP
141 
142 #endif // PLAYER_H
Definition: mixer.h:37
double getMainCpuSpeed() const
Definition: c64.h:227
event_clock_t getTime(event_phase_t phase) const
Definition: EventScheduler.h:124
Definition: SidTune.h:40
Definition: sidrandom.h:27
Definition: SidInfo.h:31
Definition: SidInfoImpl.h:49
model_t
Definition: c64.h:72
Definition: c64.h:65
Definition: event.h:101
unsigned int selectSong(unsigned int songNum)
Definition: SidTune.cpp:94
Definition: SidConfig.h:39
Definition: sidbuilder.h:37
void load(const char *fileName, bool separatorIsSlash=false)
Definition: SidTune.cpp:64
Definition: player.h:46
EventScheduler * getEventScheduler()
Definition: c64.h:203