VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
SIDBridge.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "SubComponent.h"
16#include "SIDTypes.h"
17#include "Constants.h"
18#include "Volume.h"
19#include "AudioPort.h"
20#include "SID.h"
21#include "Chrono.h"
22
23namespace vc64 {
24
25/* Architecture of the audio pipeline
26 *
27 * SidBridge
28 * -------------------------------------------------
29 * | -------- |
30 * | | SID0 |-----> |
31 * | -------- | |
32 * | | |
33 * | -------- | |
34 * | | SID1 |----->| ---------> Speaker
35 * | -------- | -------------- | |
36* | |---->| AudioPort |----| |
37 * | -------- | -------------- | |
38 * | | SID2 |----->| Volume, pan ---------> Recorder
39 * | -------- | |
40 * | | |
41 * | -------- | |
42 * | | SID3 |-----> |
43 * | -------- |
44 * -------------------------------------------------
45 */
46
47class SIDBridge final : public SubComponent {
48
49 friend C64Memory;
50 friend AudioPort;
51
52 Descriptions descriptions = {{
53
54 .name = "SIDBridge",
55 .description = "SID Bridge"
56 }};
57
58
59 //
60 // Sub components
61 //
62
63public:
64
65 SID sid[4] = {
66
67 SID(c64, 0),
68 SID(c64, 1),
69 SID(c64, 2),
70 SID(c64, 3)
71 };
72
73
74 //
75 // Methods
76 //
77
78public:
79
80 SIDBridge(C64 &ref);
81
82 SIDBridge& operator= (const SIDBridge& other) {
83
84 CLONE_ARRAY(sid)
85
86 return *this;
87 }
88
89
90 //
91 // Methods from Serializable
92 //
93
94public:
95
96 template <class T>
97 void serialize(T& worker)
98 {
99 worker
100
101 << sid;
102
103 } SERIALIZERS(serialize);
104
105
106 //
107 // Methods from CoreComponent
108 //
109
110public:
111
112 const Descriptions &getDescriptions() const override { return descriptions; }
113
114
115 //
116 // Parameterizing
117 //
118
119public:
120
121 // Adjusts the clock frequency for all SIDs
122 void setClockFrequency(u32 frequency);
123
124 // Adjusts the sample rate for all SIDs
125 void setSampleRate(double rate);
126
127
128 //
129 // Running the device
130 //
131
132public:
133
134 // Prepares for a new frame
135 void beginFrame();
136
137 // Finishes the current frame
138 void endFrame();
139
140
141 //
142 // Accessig memory
143 //
144
145public:
146
147 // Special peek function for the I/O memory range
148 u8 peek(u16 addr);
149
150 // Same as peek without side effects
151 u8 spypeek(u16 addr) const;
152
153 // Reads the pot bits that show up in register 0x19 and 0x1A
154 u8 readPotX() const;
155 u8 readPotY() const;
156
157 // Special poke function for the I/O memory range
158 void poke(u16 addr, u8 value);
159
160private:
161
162 // Translates a memory address to the mapped SID
163 isize mappedSID(u16 addr) const;
164
165
166 //
167 // Visualizing the waveform
168 //
169
170public:
171
172 /* Plots a graphical representation of the waveform. Returns the highest
173 * amplitute that was found in the ringbuffer. To implement auto-scaling,
174 * pass the returned value as parameter maxAmp in the next call to this
175 * function.
176 */
177 float draw(u32 *buffer, isize width, isize height,
178 float maxAmp, u32 color, isize sid = -1) const;
179};
180
181}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16