GUI: prepare for a per-channel oscilloscope?

currently supported systems:
- Amiga
- AY-3-8910
- Dummy System
- OPLL
- SegaPCM

no trigger supported yet!
This commit is contained in:
tildearrow 2022-04-30 03:58:30 -05:00
parent ba657fe4db
commit 4197fa44fb
20 changed files with 269 additions and 14 deletions

View file

@ -21,6 +21,7 @@
#define _DISPATCH_H
#include <stdlib.h>
#include <string.h>
#include <vector>
#define ONE_SEMITONE 2200
@ -205,6 +206,18 @@ struct DivRegWrite {
addr(a), val(v) {}
};
struct DivDispatchOscBuffer {
unsigned int rate;
unsigned short needle;
short data[65536];
DivDispatchOscBuffer():
rate(65536),
needle(0) {
memset(data,0,65536*sizeof(short));
}
};
class DivEngine;
class DivMacroInt;
@ -268,6 +281,12 @@ class DivDispatch {
* @return a pointer, or NULL.
*/
virtual DivMacroInt* getChanMacroInt(int chan);
/**
* get an oscilloscope buffer for a channel.
* @return a pointer to a DivDispatchOscBuffer, or NULL if not supported.
*/
virtual DivDispatchOscBuffer* getOscBuffer(int chan);
/**
* get the register pool of this dispatch.

View file

@ -986,6 +986,16 @@ unsigned char* DivEngine::getRegisterPool(int sys, int& size, int& depth) {
return disCont[sys].dispatch->getRegisterPool();
}
DivMacroInt* DivEngine::getMacroInt(int chan) {
if (chan<0 || chan>=chans) return NULL;
return disCont[dispatchOfChan[chan]].dispatch->getChanMacroInt(dispatchChanOfChan[chan]);
}
DivDispatchOscBuffer* DivEngine::getOscBuffer(int chan) {
if (chan<0 || chan>=chans) return NULL;
return disCont[dispatchOfChan[chan]].dispatch->getOscBuffer(dispatchChanOfChan[chan]);
}
void DivEngine::enableCommandStream(bool enable) {
cmdStreamEnabled=enable;
}

View file

@ -722,6 +722,12 @@ class DivEngine {
// get register pool
unsigned char* getRegisterPool(int sys, int& size, int& depth);
// get macro interpreter
DivMacroInt* getMacroInt(int chan);
// get osc buffer
DivDispatchOscBuffer* getOscBuffer(int chan);
// enable command stream dumping
void enableCommandStream(bool enable);

View file

@ -33,6 +33,10 @@ DivMacroInt* DivDispatch::getChanMacroInt(int chan) {
return NULL;
}
DivDispatchOscBuffer* DivDispatch::getOscBuffer(int chan) {
return NULL;
}
unsigned char* DivDispatch::getRegisterPool() {
return NULL;
}

View file

@ -91,12 +91,15 @@ const char* DivPlatformAmiga::getEffectName(unsigned char effect) {
}
void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t len) {
static int outL, outR;
static int outL, outR, output;
for (size_t h=start; h<start+len; h++) {
outL=0;
outR=0;
for (int i=0; i<4; i++) {
if (!chan[i].active) continue;
if (!chan[i].active) {
oscBuf[i]->data[oscBuf[i]->needle++]=0;
continue;
}
if (chan[i].useWave || (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen)) {
chan[i].audSub-=AMIGA_DIVIDER;
if (chan[i].audSub<0) {
@ -139,13 +142,17 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le
}
}
if (!isMuted[i]) {
output=chan[i].audDat*chan[i].outVol;
if (i==0 || i==3) {
outL+=((chan[i].audDat*chan[i].outVol)*sep1)>>7;
outR+=((chan[i].audDat*chan[i].outVol)*sep2)>>7;
outL+=(output*sep1)>>7;
outR+=(output*sep2)>>7;
} else {
outL+=((chan[i].audDat*chan[i].outVol)*sep2)>>7;
outR+=((chan[i].audDat*chan[i].outVol)*sep1)>>7;
outL+=(output*sep2)>>7;
outR+=(output*sep1)>>7;
}
oscBuf[i]->data[oscBuf[i]->needle++]=output<<2;
} else {
oscBuf[i]->data[oscBuf[i]->needle++]=0;
}
}
filter[0][0]+=(filtConst*(outL-filter[0][0]))>>12;
@ -419,6 +426,10 @@ void* DivPlatformAmiga::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformAmiga::getOscBuffer(int ch) {
return oscBuf[ch];
}
void DivPlatformAmiga::reset() {
for (int i=0; i<4; i++) {
chan[i]=DivPlatformAmiga::Channel();
@ -469,6 +480,9 @@ void DivPlatformAmiga::setFlags(unsigned int flags) {
chipClock=COLOR_NTSC;
}
rate=chipClock/AMIGA_DIVIDER;
for (int i=0; i<4; i++) {
oscBuf[i]->rate=rate;
}
sep1=((flags>>8)&127)+127;
sep2=127-((flags>>8)&127);
amigaModel=flags&2;
@ -487,6 +501,7 @@ int DivPlatformAmiga::init(DivEngine* p, int channels, int sugRate, unsigned int
dumpWrites=false;
skipRegisterWrites=false;
for (int i=0; i<4; i++) {
oscBuf[i]=new DivDispatchOscBuffer;
isMuted[i]=false;
}
setFlags(flags);
@ -495,4 +510,7 @@ int DivPlatformAmiga::init(DivEngine* p, int channels, int sugRate, unsigned int
}
void DivPlatformAmiga::quit() {
for (int i=0; i<4; i++) {
delete oscBuf[i];
}
}

View file

@ -74,6 +74,7 @@ class DivPlatformAmiga: public DivDispatch {
outVol(64) {}
};
Channel chan[4];
DivDispatchOscBuffer* oscBuf[4];
bool isMuted[4];
bool bypassLimits;
bool amigaModel;
@ -91,6 +92,7 @@ class DivPlatformAmiga: public DivDispatch {
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivDispatchOscBuffer* getOscBuffer(int chan);
void reset();
void forceIns();
void tick(bool sysTick=true);

View file

@ -146,6 +146,12 @@ void DivPlatformAY8910::acquire(short* bufL, short* bufR, size_t start, size_t l
bufR[i+start]=bufL[i+start];
}
}
for (int ch=0; ch<3; ch++) {
for (size_t i=0; i<len; i++) {
oscBuf[ch]->data[oscBuf[ch]->needle++]=ayBuf[ch][i];
}
}
}
void DivPlatformAY8910::updateOutSel(bool immediate) {
@ -500,6 +506,10 @@ void* DivPlatformAY8910::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformAY8910::getOscBuffer(int ch) {
return oscBuf[ch];
}
unsigned char* DivPlatformAY8910::getRegisterPool() {
return regPool;
}
@ -615,6 +625,9 @@ void DivPlatformAY8910::setFlags(unsigned int flags) {
break;
}
rate=chipClock/8;
for (int i=0; i<3; i++) {
oscBuf[i]->rate=rate;
}
if (ay!=NULL) delete ay;
switch ((flags>>4)&3) {
@ -650,6 +663,7 @@ int DivPlatformAY8910::init(DivEngine* p, int channels, int sugRate, unsigned in
skipRegisterWrites=false;
for (int i=0; i<3; i++) {
isMuted[i]=false;
oscBuf[i]=new DivDispatchOscBuffer;
}
ay=NULL;
setFlags(flags);
@ -660,6 +674,9 @@ int DivPlatformAY8910::init(DivEngine* p, int channels, int sugRate, unsigned in
}
void DivPlatformAY8910::quit() {
for (int i=0; i<3; i++) delete[] ayBuf[i];
for (int i=0; i<3; i++) {
delete oscBuf[i];
delete[] ayBuf[i];
}
if (ay!=NULL) delete ay;
}

View file

@ -56,6 +56,7 @@ class DivPlatformAY8910: public DivDispatch {
};
std::queue<QueuedWrite> writes;
ay8910_device* ay;
DivDispatchOscBuffer* oscBuf[3];
unsigned char regPool[16];
unsigned char lastBusy;
@ -90,6 +91,7 @@ class DivPlatformAY8910: public DivDispatch {
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivDispatchOscBuffer* getOscBuffer(int chan);
unsigned char* getRegisterPool();
int getRegisterPoolSize();
void flushWrites();

View file

@ -25,12 +25,21 @@
#define CHIP_FREQBASE 2048
void DivPlatformDummy::acquire(short* bufL, short* bufR, size_t start, size_t len) {
int chanOut;
for (size_t i=start; i<start+len; i++) {
int out=0;
for (unsigned char j=0; j<chans; j++) {
if (chan[j].active) {
if (!isMuted[j]) out+=(((signed short)chan[j].pos)*chan[j].amp*chan[j].vol)>>12;
if (!isMuted[j]) {
chanOut=(((signed short)chan[j].pos)*chan[j].amp*chan[j].vol)>>12;
oscBuf[j]->data[oscBuf[j]->needle++]=chanOut;
out+=chanOut;
} else {
oscBuf[j]->data[oscBuf[j]->needle++]=0;
}
chan[j].pos+=chan[j].freq;
} else {
oscBuf[j]->data[oscBuf[j]->needle++]=0;
}
}
if (out<-32768) out=-32768;
@ -61,6 +70,10 @@ void* DivPlatformDummy::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformDummy::getOscBuffer(int ch) {
return oscBuf[ch];
}
int DivPlatformDummy::dispatch(DivCommand c) {
switch (c.cmd) {
case DIV_CMD_NOTE_ON:
@ -131,6 +144,10 @@ int DivPlatformDummy::init(DivEngine* p, int channels, int sugRate, unsigned int
skipRegisterWrites=false;
for (int i=0; i<DIV_MAX_CHANS; i++) {
isMuted[i]=false;
if (i<channels) {
oscBuf[i]=new DivDispatchOscBuffer;
oscBuf[i]->rate=65536;
}
}
rate=65536;
chipClock=65536;
@ -140,6 +157,9 @@ int DivPlatformDummy::init(DivEngine* p, int channels, int sugRate, unsigned int
}
void DivPlatformDummy::quit() {
for (int i=0; i<chans; i++) {
delete oscBuf[i];
}
}
DivPlatformDummy::~DivPlatformDummy() {

View file

@ -31,6 +31,7 @@ class DivPlatformDummy: public DivDispatch {
Channel(): freq(0), baseFreq(0), pitch(0), pos(0), active(false), freqChanged(false), vol(0), amp(64) {}
};
Channel chan[128];
DivDispatchOscBuffer* oscBuf[128];
bool isMuted[128];
unsigned char chans;
friend void putDispatchChan(void*,int,int);
@ -39,6 +40,7 @@ class DivPlatformDummy: public DivDispatch {
void muteChannel(int ch, bool mute);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivDispatchOscBuffer* getOscBuffer(int chan);
void reset();
void tick(bool sysTick=true);
int init(DivEngine* parent, int channels, int sugRate, unsigned int flags);

View file

@ -94,7 +94,10 @@ void DivPlatformOPLL::acquire_nuked(short* bufL, short* bufR, size_t start, size
OPLL_Clock(&fm,o);
unsigned char nextOut=cycleMapOPLL[fm.cycles];
if ((nextOut>=6 && properDrums) || !isMuted[nextOut]) {
oscBuf[nextOut]->data[oscBuf[nextOut]->needle++]=(o[0]+o[1])<<6;
os+=(o[0]+o[1]);
} else {
oscBuf[nextOut]->data[oscBuf[nextOut]->needle++]=0;
}
}
os*=50;
@ -731,6 +734,10 @@ void* DivPlatformOPLL::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformOPLL::getOscBuffer(int ch) {
return oscBuf[ch];
}
unsigned char* DivPlatformOPLL::getRegisterPool() {
return regPool;
}
@ -842,6 +849,9 @@ void DivPlatformOPLL::setFlags(unsigned int flags) {
}
rate=chipClock/36;
patchSet=flags>>4;
for (int i=0; i<11; i++) {
oscBuf[i]->rate=rate/2;
}
}
int DivPlatformOPLL::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
@ -851,14 +861,18 @@ int DivPlatformOPLL::init(DivEngine* p, int channels, int sugRate, unsigned int
patchSet=0;
for (int i=0; i<11; i++) {
isMuted[i]=false;
oscBuf[i]=new DivDispatchOscBuffer;
}
setFlags(flags);
reset();
return 10;
return 11;
}
void DivPlatformOPLL::quit() {
for (int i=0; i<11; i++) {
delete oscBuf[i];
}
}
DivPlatformOPLL::~DivPlatformOPLL() {

View file

@ -63,6 +63,7 @@ class DivPlatformOPLL: public DivDispatch {
};
Channel chan[11];
bool isMuted[11];
DivDispatchOscBuffer* oscBuf[11];
struct QueuedWrite {
unsigned short addr;
unsigned char val;
@ -100,6 +101,7 @@ class DivPlatformOPLL: public DivDispatch {
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivDispatchOscBuffer* getOscBuffer(int chan);
unsigned char* getRegisterPool();
int getRegisterPoolSize();
void reset();

View file

@ -46,9 +46,11 @@ void DivPlatformSegaPCM::acquire(short* bufL, short* bufR, size_t start, size_t
DivSample* s=parent->getSample(chan[i].pcm.sample);
if (s->samples<=0) {
chan[i].pcm.sample=-1;
oscBuf[i]->data[oscBuf[i]->needle++]=0;
continue;
}
if (!isMuted[i]) {
oscBuf[i]->data[oscBuf[i]->needle++]=s->data8[chan[i].pcm.pos>>8]*(chan[i].chVolL+chan[i].chVolR)>>1;
pcmL+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolL);
pcmR+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolR);
}
@ -60,6 +62,8 @@ void DivPlatformSegaPCM::acquire(short* bufL, short* bufR, size_t start, size_t
chan[i].pcm.sample=-1;
}
}
} else {
oscBuf[i]->data[oscBuf[i]->needle++]=0;
}
}
@ -359,6 +363,10 @@ void* DivPlatformSegaPCM::getChanState(int ch) {
return &chan[ch];
}
DivDispatchOscBuffer* DivPlatformSegaPCM::getOscBuffer(int ch) {
return oscBuf[ch];
}
unsigned char* DivPlatformSegaPCM::getRegisterPool() {
return regPool;
}
@ -408,6 +416,9 @@ void DivPlatformSegaPCM::reset() {
void DivPlatformSegaPCM::setFlags(unsigned int flags) {
chipClock=8000000.0;
rate=31250;
for (int i=0; i<16; i++) {
oscBuf[i]->rate=rate;
}
}
bool DivPlatformSegaPCM::isStereo() {
@ -420,6 +431,7 @@ int DivPlatformSegaPCM::init(DivEngine* p, int channels, int sugRate, unsigned i
skipRegisterWrites=false;
for (int i=0; i<16; i++) {
isMuted[i]=false;
oscBuf[i]=new DivDispatchOscBuffer;
}
setFlags(flags);
reset();
@ -428,6 +440,9 @@ int DivPlatformSegaPCM::init(DivEngine* p, int channels, int sugRate, unsigned i
}
void DivPlatformSegaPCM::quit() {
for (int i=0; i<16; i++) {
delete oscBuf[i];
}
}
DivPlatformSegaPCM::~DivPlatformSegaPCM() {

View file

@ -49,6 +49,7 @@ class DivPlatformSegaPCM: public DivDispatch {
Channel(): freqH(0), freqL(0), freq(0), baseFreq(0), pitch(0), pitch2(0), note(0), ins(-1), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), inPorta(false), portaPause(false), furnacePCM(false), vol(0), outVol(0), chVolL(127), chVolR(127) {}
};
Channel chan[16];
DivDispatchOscBuffer* oscBuf[16];
struct QueuedWrite {
unsigned short addr;
unsigned char val;
@ -77,6 +78,7 @@ class DivPlatformSegaPCM: public DivDispatch {
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void* getChanState(int chan);
DivDispatchOscBuffer* getOscBuffer(int chan);
unsigned char* getRegisterPool();
int getRegisterPoolSize();
void reset();