libsidplayfp 2.11.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
38class sidbuilder;
39
40namespace libsidplayfp
41{
42
46class sidemu : public c64sid
47{
48public:
50 static constexpr unsigned int OUTPUTBUFFERSIZE = 5000;
51
52private:
53 sidbuilder* const m_builder;
54
55protected:
56 static const char ERR_UNSUPPORTED_FREQ[];
57 static const char ERR_INVALID_SAMPLING[];
58 static const char ERR_INVALID_CHIP[];
59
60protected:
61 EventScheduler *eventScheduler = nullptr;
62
63 event_clock_t m_accessClk = 0;
64
66 short *m_buffer = nullptr;
67
69 int m_bufferpos = 0;
70
71 bool m_status = true;
72 bool isLocked = false;
73
74 bool isFilterDisabled = false;
75
77 std::bitset<4> isMuted;
78
79 std::string m_error;
80
81protected:
82 virtual void write(uint_least8_t addr, uint8_t data) = 0;
83
84 void writeReg(uint_least8_t addr, uint8_t data) override final;
85
86public:
87 sidemu(sidbuilder *builder) :
88 m_builder(builder),
89 m_error("N/A")
90 {
91 isMuted.reset();
92 }
93 ~sidemu() override = default;
94
98 virtual void clock() = 0;
99
103 virtual bool lock(EventScheduler *scheduler);
104
108 virtual void unlock();
109
110 // Standard SID functions
111
118 void voice(unsigned int voice, bool mute);
119
123 void filter(bool enable);
124
128 virtual void model(SidConfig::sid_model_t model, bool digiboost) = 0;
129
138 virtual void sampling(float systemfreq SID_UNUSED, float outputfreq SID_UNUSED,
139 SidConfig::sampling_method_t method SID_UNUSED, bool fast SID_UNUSED) {}
140
144 const char* error() const { return m_error.c_str(); }
145
146 sidbuilder* builder() const { return m_builder; }
147
151 int bufferpos() const { return m_bufferpos; }
152
156 void bufferpos(int pos) { m_bufferpos = pos; }
157
161 short *buffer() const { return m_buffer; }
162};
163
164}
165
166#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:66
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:69
const char * error() const
Definition sidemu.h:144
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:138
void filter(bool enable)
Definition sidemu.cpp:68
int bufferpos() const
Definition sidemu.h:151
void bufferpos(int pos)
Definition sidemu.h:156
static constexpr unsigned int OUTPUTBUFFERSIZE
Buffer size. 5000 is roughly 5 ms at 96 kHz.
Definition sidemu.h:50
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:77
short * buffer() const
Definition sidemu.h:161
Definition sidbuilder.h:41