libsidplayfp  1.4.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 <stdint.h>
28 #include <cstdio>
29 
30 #include "siddefs.h"
31 #include "SidConfig.h"
32 #include "SidTuneInfo.h"
33 #include "SidInfoImpl.h"
34 #include "sidrandom.h"
35 #include "mixer.h"
36 #include "event.h"
37 #include "c64/c64.h"
38 
39 #ifdef HAVE_CONFIG_H
40 # include "config.h"
41 #endif
42 
43 #ifdef PC64_TESTSUITE
44 # include <string>
45 # include "SidTune.h"
46 #else
47 class SidTune;
48 #endif
49 
50 class SidInfo;
51 class sidbuilder;
52 
53 
54 SIDPLAYFP_NAMESPACE_START
55 
56 class Player
57 #ifdef PC64_TESTSUITE
58  : public testEnv
59 #endif
60 {
61 private:
62  class configError
63  {
64  private:
65  const char* m_msg;
66 
67  public:
68  configError(const char* msg) : m_msg(msg) {}
69  const char* message() const { return m_msg; }
70  };
71 
72 private:
73  c64 m_c64;
74 
75  Mixer m_mixer;
76 
77  SidTune *m_tune;
78  SidInfoImpl m_info;
79 
80  // User Configuration Settings
81  SidConfig m_cfg;
82 
83  const char *m_errorString;
84 
85  volatile bool m_isPlaying;
86 
87  sidrandom m_rand;
88 
89 private:
90  c64::model_t c64model(SidConfig::c64_model_t defaultModel, bool forced);
91  void initialise();
92  void sidRelease();
93  void sidCreate(sidbuilder *builder, SidConfig::sid_model_t defaultModel,
94  bool forced, unsigned int channels);
95  void sidParams(double cpuFreq, int frequency,
96  SidConfig::sampling_method_t sampling, bool fastSampling);
97 
98  static SidConfig::sid_model_t getModel (SidTuneInfo::model_t sidModel, SidConfig::sid_model_t defaultModel, bool forced);
99 
100 #ifdef PC64_TESTSUITE
101  void load(const char *file)
102  {
103  std::string name(PC64_TESTSUITE);
104  name.append(file);
105  name.append(".prg");
106 
107  m_tune->load(name.c_str());
108  m_tune->selectSong(0);
109  initialise();
110  }
111 #endif
112 
113 public:
114  Player();
115  ~Player() {}
116 
117  const SidConfig &config() const { return m_cfg; }
118 
119  const SidInfo &info() const { return m_info; }
120 
121  bool config(const SidConfig &cfg);
122 
123  bool fastForward(unsigned int percent);
124 
125  bool load(SidTune *tune);
126 
127  double cpuFreq() const { return m_c64.getMainCpuSpeed(); }
128 
129  uint_least32_t play(short *buffer, uint_least32_t samples);
130 
131  bool isPlaying() const { return m_isPlaying; }
132 
133  void stop();
134 
135  uint_least32_t time() const { return (uint_least32_t)(m_c64.getEventScheduler().getTime(EVENT_CLOCK_PHI1) / cpuFreq()); }
136 
137  void debug(const bool enable, FILE *out) { m_c64.debug (enable, out); }
138 
139  void mute(unsigned int sidNum, unsigned int voice, bool enable);
140 
141  const char *error() const { return m_errorString; }
142 
143  void setRoms(const uint8_t* kernal, const uint8_t* basic, const uint8_t* character);
144 
145  EventContext *getEventScheduler() { return m_c64.getEventScheduler(); }
146 
147  uint_least16_t getCia1TimerA() const { return m_c64.getCia1TimerA(); }
148 };
149 
150 SIDPLAYFP_NAMESPACE_STOP
151 
152 #endif // PLAYER_H
Definition: mixer.h:37
double getMainCpuSpeed() const
Definition: c64.h:237
event_clock_t getTime(event_phase_t phase) const
Definition: EventScheduler.h:122
Definition: SidTune.h:38
Definition: sidrandom.h:27
Definition: SidInfo.h:31
Definition: SidInfoImpl.h:49
model_t
Definition: c64.h:82
Definition: c64.h:75
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:56
EventScheduler * getEventScheduler()
Definition: c64.h:213