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"
|
2022-09-18 10:59:58 +00:00
|
|
|
#include "../waveSynth.h"
|
2022-03-21 07:38:12 +00:00
|
|
|
#include <queue>
|
|
|
|
#include "sound/snes/SPC_DSP.h"
|
|
|
|
|
|
|
|
class DivPlatformSNES: public DivDispatch {
|
2022-12-13 07:22:48 +00:00
|
|
|
struct Channel: public SharedChannel<int> {
|
2022-09-18 18:01:46 +00:00
|
|
|
unsigned int audPos;
|
2022-12-04 10:58:58 +00:00
|
|
|
int sample, wave;
|
2022-06-10 15:59:44 +00:00
|
|
|
int panL, panR;
|
2022-12-04 10:58:58 +00:00
|
|
|
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;
|
2022-09-18 10:59:58 +00:00
|
|
|
DivWaveSynth ws;
|
2022-03-21 07:38:12 +00:00
|
|
|
Channel():
|
2022-12-13 07:22:48 +00:00
|
|
|
SharedChannel<int>(127),
|
2022-03-21 07:38:12 +00:00
|
|
|
audPos(0),
|
|
|
|
sample(-1),
|
2022-09-18 10:59:58 +00:00
|
|
|
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),
|
2022-09-25 08:33:39 +00:00
|
|
|
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];
|
2022-06-10 15:59:44 +00:00
|
|
|
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;
|
2022-09-25 08:33:39 +00:00
|
|
|
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 echoFIR[8];
|
|
|
|
unsigned char echoDelay;
|
2022-06-10 15:59:44 +00:00
|
|
|
size_t sampleTableBase;
|
2022-09-25 08:50:33 +00:00
|
|
|
bool writeControl;
|
|
|
|
bool writeNoise;
|
|
|
|
bool writePitchMod;
|
|
|
|
bool writeEcho;
|
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;
|
|
|
|
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {}
|
|
|
|
};
|
|
|
|
std::queue<QueuedWrite> writes;
|
|
|
|
|
2022-06-10 15:59:44 +00:00
|
|
|
signed char sampleMem[65536];
|
2022-09-26 09:07:51 +00:00
|
|
|
signed char copyOfSampleMem[65536];
|
2022-06-10 15:59:44 +00:00
|
|
|
size_t sampleMemLen;
|
2022-09-26 01:07:21 +00:00
|
|
|
unsigned int sampleOff[256];
|
2022-11-26 23:44:04 +00:00
|
|
|
bool sampleLoaded[256];
|
2022-03-21 07:38:12 +00:00
|
|
|
unsigned char regPool[0x80];
|
2022-06-10 15:59:44 +00:00
|
|
|
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);
|
2022-06-10 15:59:44 +00:00
|
|
|
DivMacroInt* getChanMacroInt(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);
|
2023-01-02 00:46:08 +00:00
|
|
|
int getOutputCount();
|
2022-03-21 07:38:12 +00:00
|
|
|
void notifyInsChange(int ins);
|
2022-09-18 10:59:58 +00:00
|
|
|
void notifyWaveChange(int wave);
|
2022-09-30 01:13:40 +00:00
|
|
|
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();
|
2022-06-10 15:59:44 +00:00
|
|
|
const void* getSampleMem(int index = 0);
|
|
|
|
size_t getSampleMemCapacity(int index = 0);
|
|
|
|
size_t getSampleMemUsage(int index = 0);
|
2022-11-26 23:44:04 +00:00
|
|
|
bool isSampleLoaded(int index, int sample);
|
2022-11-27 04:50:20 +00:00
|
|
|
void renderSamples(int chipID);
|
2022-09-30 01:13:40 +00:00
|
|
|
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
|
2022-03-21 07:38:12 +00:00
|
|
|
void quit();
|
2022-06-10 15:59:44 +00:00
|
|
|
private:
|
2022-09-18 10:59:58 +00:00
|
|
|
void updateWave(int ch);
|
2022-06-10 15:59:44 +00:00
|
|
|
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
|