libsidplayfp  2.15.0
sidemu.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2024 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 #ifndef SIDEMU_H
24 #define SIDEMU_H
25 
26 #include "sidplayfp/SidConfig.h"
27 #include "sidplayfp/siddefs.h"
28 #include "Event.h"
29 #include "EventScheduler.h"
30 
31 #include "c64/c64sid.h"
32 
33 #include "sidcxx11.h"
34 
35 #include <string>
36 #include <bitset>
37 
38 class sidbuilder;
39 
40 namespace libsidplayfp
41 {
42 
46 class sidemu : public c64sid
47 {
48 private:
49  sidbuilder* const m_builder;
50 
51 protected:
52  static const char ERR_UNSUPPORTED_FREQ[];
53  static const char ERR_INVALID_SAMPLING[];
54  static const char ERR_INVALID_CHIP[];
55 
56 protected:
57  EventScheduler *eventScheduler = nullptr;
58 
59  event_clock_t m_accessClk = 0;
60 
62  short *m_buffer = nullptr;
63 
65  int m_bufferpos = 0;
66 
67  bool m_status = true;
68  bool isLocked = false;
69 
70  bool isFilterDisabled = false;
71 
73  std::bitset<4> isMuted;
74 
75  std::string m_error;
76 
77 protected:
78  virtual void write(uint_least8_t addr, uint8_t data) = 0;
79 
80  void writeReg(uint_least8_t addr, uint8_t data) override final;
81 
82 public:
83  sidemu(sidbuilder *builder) :
84  m_builder(builder),
85  m_error("N/A")
86  {
87  isMuted.reset();
88  }
89  ~sidemu() override = default;
90 
94  virtual void clock() = 0;
95 
99  virtual bool lock(EventScheduler *scheduler);
100 
104  virtual void unlock();
105 
106  // Standard SID functions
107 
114  void voice(unsigned int voice, bool mute);
115 
119  void filter(bool enable);
120 
124  virtual void model(SidConfig::sid_model_t model, bool digiboost) = 0;
125 
134  virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED,
135  SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED) {}
136 
140  const char* error() const { return m_error.c_str(); }
141 
142  sidbuilder* builder() const { return m_builder; }
143 
147  int bufferpos() const { return m_bufferpos; }
148 
152  void bufferpos(int pos) { m_bufferpos = pos; }
153 
157  short *buffer() const { return m_buffer; }
158 };
159 
160 }
161 
162 #endif // SIDEMU_H
sid_model_t
SID chip model.
Definition: SidConfig.h:51
sampling_method_t
Sampling method.
Definition: SidConfig.h:84
Definition: EventScheduler.h:62
Definition: c64sid.h:40
Definition: sidemu.h:47
short * m_buffer
The sample buffer.
Definition: sidemu.h:62
short * buffer() const
Definition: sidemu.h:157
virtual bool lock(EventScheduler *scheduler)
Definition: sidemu.cpp:73
virtual void unlock()
Definition: sidemu.cpp:84
virtual void clock()=0
int m_bufferpos
Current position in buffer.
Definition: sidemu.h:65
virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED, SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED)
Definition: sidemu.h:134
void filter(bool enable)
Definition: sidemu.cpp:68
const char * error() const
Definition: sidemu.h:140
int bufferpos() const
Definition: sidemu.h:147
void bufferpos(int pos)
Definition: sidemu.h:152
void voice(unsigned int voice, bool mute)
Definition: sidemu.cpp:62
virtual void model(SidConfig::sid_model_t model, bool digiboost)=0
std::bitset< 4 > isMuted
Flags for muted voices.
Definition: sidemu.h:73
Definition: sidbuilder.h:41