libsidplayfp  2.15.0
player.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2022 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 "sidplayfp/siddefs.h"
31 #include "sidplayfp/SidConfig.h"
32 #include "sidplayfp/SidTuneInfo.h"
33 
34 #include "SidInfoImpl.h"
35 #include "sidrandom.h"
36 #include "mixer.h"
37 #include "simpleMixer.h"
38 #include "c64/c64.h"
39 
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43 
44 #include <atomic>
45 #include <memory>
46 #include <vector>
47 
48 class SidTune;
49 class SidInfo;
50 class sidbuilder;
51 
52 
53 namespace libsidplayfp
54 {
55 
56 class Player
57 {
58 private:
59  enum class state_t
60  {
61  STOPPED,
62  PLAYING,
63  STOPPING
64  };
65 
66 private:
68  c64 m_c64;
69 
71  Mixer m_mixer;
72 
74  SidTune *m_tune;
75 
77  SidInfoImpl m_info;
78 
80  SidConfig m_cfg;
81 
83  const char *m_errorString;
84 
85  std::atomic<state_t> m_isPlaying;
86 
87  sidrandom m_rand;
88 
89  uint_least32_t m_startTime = 0;
90 
92  uint8_t videoSwitch;
93 
94  std::unique_ptr<SimpleMixer> m_simpleMixer;
95 
96 private:
103  c64::model_t c64model(SidConfig::c64_model_t defaultModel, bool forced);
104 
110  void initialise();
111 
115  void sidRelease();
116 
122  void sidCreate(sidbuilder *builder, SidConfig::sid_model_t defaultModel, bool digiboost,
123  bool forced, const std::vector<unsigned int> &extraSidAddresses);
124 
133  void sidParams(double cpuFreq, int frequency,
134  SidConfig::sampling_method_t sampling, bool fastSampling);
135 
136  inline void run(unsigned int events);
137 
138 public:
139  Player();
140  ~Player() = default;
141 
142  const SidConfig &config() const { return m_cfg; }
143 
144  const SidInfo &info() const { return m_info; }
145 
146  bool config(const SidConfig &cfg, bool force=false);
147 
148  bool fastForward(unsigned int percent);
149 
150  bool load(SidTune *tune);
151 
152  uint_least32_t play(short *buffer, uint_least32_t samples);
153 
154  void buffers(short** buffers) const;
155 
156  int play(unsigned int cycles);
157 
158  bool isPlaying() const { return m_isPlaying != state_t::STOPPED; }
159 
160  void stop();
161 
162  uint_least32_t timeMs() const { return m_c64.getTimeMs() - m_startTime; }
163 
164  void debug(const bool enable, FILE *out) { m_c64.debug(enable, out); }
165 
166  void mute(unsigned int sidNum, unsigned int voice, bool enable);
167 
168  void filter(unsigned int sidNum, bool enable);
169 
170  const char *error() const { return m_errorString; }
171 
172  void setKernal(const uint8_t* rom);
173  void setBasic(const uint8_t* rom);
174  void setChargen(const uint8_t* rom);
175 
176  uint_least16_t getCia1TimerA() const { return m_c64.getCia1TimerA(); }
177 
178  bool getSidStatus(unsigned int sidNum, uint8_t regs[32]);
179 
180  unsigned int installedSIDs() const { return m_c64.installedSIDs(); }
181 
182  void initMixer(bool stereo);
183 
184  unsigned int mix(short *buffer, unsigned int samples);
185 
186  bool reset();
187 };
188 
189 }
190 
191 #endif // PLAYER_H
Definition: SidConfig.h:40
sid_model_t
SID chip model.
Definition: SidConfig.h:51
sampling_method_t
Sampling method.
Definition: SidConfig.h:84
c64_model_t
C64 model.
Definition: SidConfig.h:74
Definition: SidInfoImpl.h:53
Definition: SidInfo.h:34
Definition: SidTune.h:43
Definition: mixer.h:42
Definition: player.h:57
Definition: c64.h:73
Definition: sidrandom.h:31
Definition: sidbuilder.h:41