| 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 _SU_H |
| 21 |
#define _SU_H |
| 22 |
|
| 23 |
#include "../dispatch.h" |
| 24 |
#include "../../fixedQueue.h" |
| 25 |
#include "sound/su.h" |
| 26 |
|
| 27 |
class DivPlatformSoundUnit: public DivDispatch { |
| 28 |
struct Channel: public SharedChannel<signed char> { |
| 29 |
int cutoff, baseCutoff, res, control, hasOffset, sample; |
| 30 |
signed char pan; |
| 31 |
unsigned char duty; |
| 32 |
bool noise, pcm, phaseReset, filterPhaseReset, switchRoles; |
| 33 |
bool pcmLoop, timerSync, freqSweep, volSweep, cutSweep, released; |
| 34 |
unsigned short freqSweepP, volSweepP, cutSweepP; |
| 35 |
unsigned char freqSweepB, volSweepB, cutSweepB; |
| 36 |
unsigned char freqSweepV, volSweepV, cutSweepV; |
| 37 |
unsigned short syncTimer; |
| 38 |
signed short wave; |
| 39 |
unsigned short hwSeqPos; |
| 40 |
short hwSeqDelay; |
| 41 |
short cutoff_slide; |
| 42 |
short pw_slide; |
| 43 |
short virtual_duty; |
| 44 |
Channel(): |
| 45 |
SharedChannel<signed char>(127), |
| 46 |
cutoff(16383), |
| 47 |
baseCutoff(16380), |
| 48 |
res(0), |
| 49 |
control(0), |
| 50 |
hasOffset(0), |
| 51 |
sample(-1), |
| 52 |
pan(0), |
| 53 |
duty(63), |
| 54 |
noise(false), |
| 55 |
pcm(false), |
| 56 |
phaseReset(false), |
| 57 |
filterPhaseReset(false), |
| 58 |
switchRoles(false), |
| 59 |
pcmLoop(false), |
| 60 |
timerSync(false), |
| 61 |
freqSweep(false), |
| 62 |
volSweep(false), |
| 63 |
cutSweep(false), |
| 64 |
released(false), |
| 65 |
freqSweepP(0), |
| 66 |
volSweepP(0), |
| 67 |
cutSweepP(0), |
| 68 |
freqSweepB(0), |
| 69 |
volSweepB(0), |
| 70 |
cutSweepB(0), |
| 71 |
freqSweepV(0), |
| 72 |
volSweepV(0), |
| 73 |
cutSweepV(0), |
| 74 |
syncTimer(0), |
| 75 |
wave(0), |
| 76 |
hwSeqPos(0), |
| 77 |
hwSeqDelay(0), |
| 78 |
cutoff_slide(0), |
| 79 |
pw_slide(0), |
| 80 |
virtual_duty(0) {} |
| 81 |
}; |
| 82 |
Channel chan[8]; |
| 83 |
DivDispatchOscBuffer* oscBuf[8]; |
| 84 |
bool isMuted[8]; |
| 85 |
struct QueuedWrite { |
| 86 |
unsigned char addr; |
| 87 |
unsigned char val; |
| 88 |
QueuedWrite(): addr(0), val(0) {} |
| 89 |
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {} |
| 90 |
}; |
| 91 |
FixedQueue<QueuedWrite,512> writes; |
| 92 |
unsigned char lastPan; |
| 93 |
bool sampleMemSize; |
| 94 |
unsigned char ilCtrl, ilSize, fil1; |
| 95 |
unsigned char initIlCtrl, initIlSize, initFil1; |
| 96 |
signed char echoVol, initEchoVol; |
| 97 |
unsigned int* sampleOffSU; |
| 98 |
bool* sampleLoaded; |
| 99 |
|
| 100 |
int cycles, curChan, delay, sysIDCache; |
| 101 |
short tempL; |
| 102 |
short tempR; |
| 103 |
unsigned char sampleBank, lfoMode, lfoSpeed; |
| 104 |
SoundUnit* su; |
| 105 |
unsigned char* sampleMem; |
| 106 |
size_t sampleMemLen; |
| 107 |
unsigned char regPool[128]; |
| 108 |
DivMemoryComposition memCompo; |
| 109 |
double NOTE_SU(int ch, int note); |
| 110 |
void writeControl(int ch); |
| 111 |
void writeControlUpper(int ch); |
| 112 |
|
| 113 |
friend void putDispatchChip(void*,int); |
| 114 |
friend void putDispatchChan(void*,int,int); |
| 115 |
public: |
| 116 |
void acquire(short** buf, size_t len); |
| 117 |
int dispatch(DivCommand c); |
| 118 |
void* getChanState(int chan); |
| 119 |
DivMacroInt* getChanMacroInt(int ch); |
| 120 |
unsigned short getPan(int chan); |
| 121 |
DivDispatchOscBuffer* getOscBuffer(int chan); |
| 122 |
unsigned char* getRegisterPool(); |
| 123 |
int getRegisterPoolSize(); |
| 124 |
void reset(); |
| 125 |
void forceIns(); |
| 126 |
void tick(bool sysTick=true); |
| 127 |
void muteChannel(int ch, bool mute); |
| 128 |
int getOutputCount(); |
| 129 |
bool keyOffAffectsArp(int ch); |
| 130 |
void setFlags(const DivConfig& flags); |
| 131 |
void notifyInsDeletion(void* ins); |
| 132 |
void poke(unsigned int addr, unsigned short val); |
| 133 |
void poke(std::vector<DivRegWrite>& wlist); |
| 134 |
const char** getRegisterSheet(); |
| 135 |
const void* getSampleMem(int index); |
| 136 |
size_t getSampleMemCapacity(int index); |
| 137 |
size_t getSampleMemUsage(int index); |
| 138 |
bool isSampleLoaded(int index, int sample); |
| 139 |
const DivMemoryComposition* getMemCompo(int index); |
| 140 |
void renderSamples(int chipID); |
| 141 |
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); |
| 142 |
void quit(); |
| 143 |
DivPlatformSoundUnit(); |
| 144 |
~DivPlatformSoundUnit(); |
| 145 |
}; |
| 146 |
|
| 147 |
#endif |