Debian Codegraph @

src/engine/platform/segapcm.h

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef _SEGAPCM_H
21 #define _SEGAPCM_H
22
23 #include "../dispatch.h"
24 #include "../instrument.h"
25 #include "sound/segapcm.h"
26 #include "../../fixedQueue.h"
27
28 class DivPlatformSegaPCM: public DivDispatch {
29 protected:
30 struct Channel: public SharedChannel<int> {
31 bool furnacePCM, isNewSegaPCM, setPos;
32 unsigned char chVolL, chVolR;
33 unsigned char chPanL, chPanR;
34 int macroVolMul;
35
36 struct PCMChannel {
37 int sample;
38 unsigned int pos; // <<8
39 unsigned short len;
40 unsigned char freq;
41 PCMChannel(): sample(-1), pos(0), len(0), freq(0) {}
42 } pcm;
43 Channel():
44 SharedChannel<int>(127),
45 furnacePCM(false),
46 isNewSegaPCM(false),
47 setPos(false),
48 chVolL(127),
49 chVolR(127),
50 chPanL(127),
51 chPanR(127),
52 macroVolMul(64),
53 pcm(PCMChannel()) {}
54 };
55 Channel chan[16];
56 DivDispatchOscBuffer* oscBuf[16];
57 unsigned char* sampleMem;
58 size_t sampleMemLen;
59 struct QueuedWrite {
60 unsigned short addr;
61 unsigned char val;
62 bool addrOrVal;
63 QueuedWrite(): addr(0), val(0), addrOrVal(false) {}
64 QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {}
65 };
66 FixedQueue<QueuedWrite,1024> writes;
67 segapcm_device pcm;
68 int delay;
69 int pcmL, pcmR, pcmCycles;
70 bool oldSlides;
71 unsigned char sampleBank;
72 unsigned char lastBusy;
73
74 unsigned char regPool[256];
75
76 bool isMuted[16];
77
78 short oldWrites[256];
79 short pendingWrites[256];
80
81 unsigned int* sampleOffSegaPCM;
82 unsigned char* sampleEndSegaPCM;
83 bool* sampleLoaded;
84
85 DivMemoryComposition memCompo;
86
87 friend void putDispatchChip(void*,int);
88 friend void putDispatchChan(void*,int,int);
89
90 public:
91 void acquire(short** buf, size_t len);
92 int dispatch(DivCommand c);
93 void* getChanState(int chan);
94 DivMacroInt* getChanMacroInt(int ch);
95 unsigned short getPan(int chan);
96 DivSamplePos getSamplePos(int ch);
97 DivDispatchOscBuffer* getOscBuffer(int chan);
98 unsigned char* getRegisterPool();
99 int getRegisterPoolSize();
100 void reset();
101 void forceIns();
102 void tick(bool sysTick=true);
103 void muteChannel(int ch, bool mute);
104 void notifyInsChange(int ins);
105 void notifyInsDeletion(void* ins);
106 void renderSamples(int chipID);
107 void setFlags(const DivConfig& flags);
108 int getOutputCount();
109 bool getLegacyAlwaysSetVolume();
110 void poke(unsigned int addr, unsigned short val);
111 void poke(std::vector<DivRegWrite>& wlist);
112 const void* getSampleMem(int index=0);
113 size_t getSampleMemCapacity(int index=0);
114 size_t getSampleMemUsage(int index=0);
115 bool isSampleLoaded(int index, int sample);
116 const DivMemoryComposition* getMemCompo(int index);
117 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
118 void quit();
119 DivPlatformSegaPCM();
120 ~DivPlatformSegaPCM();
121 };
122 #endif