furnace/src/engine/platform/snes.h

134 lines
3.9 KiB
C
Raw Normal View History

2022-03-21 07:38:12 +00:00
/**
* Furnace Tracker - multi-system chiptune tracker
2023-01-20 00:18:40 +00:00
* Copyright (C) 2021-2023 tildearrow and contributors
2022-03-21 07:38:12 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _SNES_H
#define _SNES_H
#include "../dispatch.h"
#include "../waveSynth.h"
2023-07-13 09:09:20 +00:00
#include "../fixedQueue.h"
2022-03-21 07:38:12 +00:00
#include "sound/snes/SPC_DSP.h"
class DivPlatformSNES: public DivDispatch {
struct Channel: public SharedChannel<int> {
2022-09-18 18:01:46 +00:00
unsigned int audPos;
int sample, wave;
int panL, panR;
bool useWave, setPos, noise, echo, pitchMod, invertL, invertR, shallWriteVol, shallWriteEnv;
2022-09-18 18:01:46 +00:00
int wtLen;
2022-09-25 00:40:03 +00:00
DivInstrumentSNES state;
DivWaveSynth ws;
2022-03-21 07:38:12 +00:00
Channel():
SharedChannel<int>(127),
2022-03-21 07:38:12 +00:00
audPos(0),
sample(-1),
wave(-1),
2022-09-25 00:40:03 +00:00
panL(127),
panR(127),
2022-03-21 07:38:12 +00:00
useWave(false),
setPos(false),
noise(false),
2022-09-25 08:50:33 +00:00
echo(false),
pitchMod(false),
invertL(false),
invertR(false),
2022-10-09 03:22:01 +00:00
shallWriteVol(false),
shallWriteEnv(false),
2022-09-25 00:40:03 +00:00
wtLen(16) {}
2022-03-21 07:38:12 +00:00
};
Channel chan[8];
DivDispatchOscBuffer* oscBuf[8];
2022-03-21 07:38:12 +00:00
bool isMuted[8];
2022-09-26 08:23:34 +00:00
int globalVolL, globalVolR;
unsigned char noiseFreq;
2022-10-09 03:22:01 +00:00
signed char delay;
2022-09-26 09:07:51 +00:00
signed char echoVolL, echoVolR, echoFeedback;
signed char dryVolL, dryVolR;
2022-09-26 09:07:51 +00:00
signed char echoFIR[8];
unsigned char echoDelay;
size_t sampleTableBase;
2022-09-25 08:50:33 +00:00
bool writeControl;
bool writeNoise;
bool writePitchMod;
bool writeEcho;
bool writeDryVol;
2022-09-26 09:07:51 +00:00
bool echoOn;
2022-03-21 07:38:12 +00:00
2022-09-30 09:02:11 +00:00
bool initEchoOn;
signed char initEchoVolL;
signed char initEchoVolR;
signed char initEchoFeedback;
signed char initEchoFIR[8];
unsigned char initEchoDelay;
unsigned char initEchoMask;
2022-09-24 09:27:53 +00:00
struct QueuedWrite {
unsigned char addr;
unsigned char val;
2023-07-13 09:09:20 +00:00
QueuedWrite(): addr(0), val(0) {}
2022-09-24 09:27:53 +00:00
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {}
};
2023-07-13 09:09:20 +00:00
FixedQueue<QueuedWrite,256> writes;
2022-09-24 09:27:53 +00:00
signed char sampleMem[65536];
2022-09-26 09:07:51 +00:00
signed char copyOfSampleMem[65536];
size_t sampleMemLen;
unsigned int sampleOff[256];
bool sampleLoaded[256];
2022-03-21 07:38:12 +00:00
unsigned char regPool[0x80];
SPC_DSP dsp;
2022-03-21 07:38:12 +00:00
friend void putDispatchChan(void*,int,int);
public:
2023-01-02 09:53:37 +00:00
void acquire(short** buf, size_t len);
2022-03-21 07:38:12 +00:00
int dispatch(DivCommand c);
void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch);
DivSamplePos getSamplePos(int ch);
DivDispatchOscBuffer* getOscBuffer(int chan);
2022-03-21 07:38:12 +00:00
unsigned char* getRegisterPool();
int getRegisterPoolSize();
void reset();
void forceIns();
2022-06-12 07:42:16 +00:00
void tick(bool sysTick=true);
2022-03-21 07:38:12 +00:00
void muteChannel(int ch, bool mute);
int getOutputCount();
2022-03-21 07:38:12 +00:00
void notifyInsChange(int ins);
void notifyWaveChange(int wave);
void setFlags(const DivConfig& flags);
2022-03-21 07:38:12 +00:00
void notifyInsDeletion(void* ins);
void poke(unsigned int addr, unsigned short val);
void poke(std::vector<DivRegWrite>& wlist);
const char** getRegisterSheet();
const void* getSampleMem(int index = 0);
size_t getSampleMemCapacity(int index = 0);
size_t getSampleMemUsage(int index = 0);
bool isSampleLoaded(int index, int sample);
void renderSamples(int chipID);
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
2022-03-21 07:38:12 +00:00
void quit();
private:
void updateWave(int ch);
void writeOutVol(int ch);
2022-09-28 23:28:01 +00:00
void writeEnv(int ch);
2022-09-26 09:07:51 +00:00
void initEcho();
2022-03-21 07:38:12 +00:00
};
#endif