Debian Codegraph @

src/engine/platform/opll.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 _OPLL_H
21 #define _OPLL_H
22
23 #include "../dispatch.h"
24 #include "../../fixedQueue.h"
25
26 extern "C" {
27 #include "../../../extern/Nuked-OPLL/opll.h"
28 }
29 #include "../../../extern/emu2413/emu2413.h"
30
31 class DivPlatformOPLL: public DivDispatch {
32 protected:
33 struct Channel: public SharedChannel<int> {
34 DivInstrumentFM state;
35 unsigned char freqH, freqL;
36 int fixedFreq;
37 bool furnaceDac;
38 unsigned char pan;
39 Channel():
40 SharedChannel<int>(0),
41 freqH(0),
42 freqL(0),
43 fixedFreq(0),
44 furnaceDac(false),
45 pan(3) {}
46 };
47 Channel chan[11];
48 bool isMuted[11];
49 DivDispatchOscBuffer* oscBuf[11];
50 struct QueuedWrite {
51 unsigned short addr;
52 unsigned char val;
53 bool addrOrVal;
54 QueuedWrite(): addr(0), val(0), addrOrVal(false) {}
55 QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {}
56 };
57 FixedQueue<QueuedWrite,512> writes;
58 opll_t fm;
59 OPLL* fm_emu;
60 int delay, lastCustomMemory;
61 unsigned char lastBusy;
62 unsigned char drumState;
63 unsigned char drumVol[5];
64 bool drumActivated[5];
65
66 // -1: undefined
67 // 0: snare/tom
68 // 1: hi-hat/top
69 signed char lastFreqSH, lastFreqTT;
70
71 unsigned char regPool[256];
72
73 unsigned char selCore;
74 bool crapDrums;
75 bool properDrums, properDrumsSys, noTopHatFreq, fixedAll;
76 bool vrc7;
77
78 unsigned char patchSet;
79
80 short oldWrites[256];
81 short pendingWrites[256];
82
83 int octave(int freq, int fixedBlock);
84 int toFreq(int freq, int fixedBlock);
85 void commitState(int ch, DivInstrument* ins);
86 void switchMode(bool mode);
87
88 friend void putDispatchChip(void*,int);
89 friend void putDispatchChan(void*,int,int);
90
91 void acquire_nuked(short** buf, size_t len);
92 void acquire_ymfm(short** buf, size_t len);
93 void acquire_emu(short** buf, size_t len);
94
95 public:
96 void acquire(short** buf, size_t len);
97 int dispatch(DivCommand c);
98 void* getChanState(int chan);
99 DivMacroInt* getChanMacroInt(int ch);
100 DivDispatchOscBuffer* getOscBuffer(int chan);
101 int mapVelocity(int ch, float vel);
102 float getGain(int ch, int vol);
103 unsigned char* getRegisterPool();
104 int getRegisterPoolSize();
105 void reset();
106 void forceIns();
107 void tick(bool sysTick=true);
108 void muteChannel(int ch, bool mute);
109 void setCore(unsigned char which);
110 bool keyOffAffectsArp(int ch);
111 bool keyOffAffectsPorta(int ch);
112 bool getLegacyAlwaysSetVolume();
113 float getPostAmp();
114 void toggleRegisterDump(bool enable);
115 void setVRC7(bool vrc);
116 void setProperDrums(bool pd);
117 void setFlags(const DivConfig& flags);
118 void notifyInsChange(int ins);
119 void notifyInsDeletion(void* ins);
120 int getPortaFloor(int ch);
121 void poke(unsigned int addr, unsigned short val);
122 void poke(std::vector<DivRegWrite>& wlist);
123 int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
124 void quit();
125 ~DivPlatformOPLL();
126 };
127 #endif