a lot of work
- round to nearest instead of round to zero in SMS period calc - implement arpeggio - implement arp macro (kinda) - polish the SMS platform - correct the DIV_CMD_PITCH range to 1 semitone - fix PSG volume in Genesis - use a better register write strat in Genesis - fix a bug caused by legacy code - implement ECxx command - implement EDxx command - implement SN noise mode command - vibrato table is now 64 positions long (instead of 60)
This commit is contained in:
parent
f2c70df4a8
commit
dbc2e6285f
12 changed files with 264 additions and 173 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include "../dispatch.h"
|
||||
|
||||
void DivDispatch::acquire(short& l, short& r) {
|
||||
void DivDispatch::acquire(int& l, int& r) {
|
||||
l=0;
|
||||
r=0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "dummy.h"
|
||||
#include <math.h>
|
||||
|
||||
void DivPlatformDummy::acquire(short& l, short& r) {
|
||||
void DivPlatformDummy::acquire(int& l, int& r) {
|
||||
l=0;
|
||||
for (unsigned char i=0; i<chans; i++) {
|
||||
if (chan[i].active) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class DivPlatformDummy: public DivDispatch {
|
|||
Channel chan[17];
|
||||
unsigned char chans;
|
||||
public:
|
||||
void acquire(short& l, short& r);
|
||||
void acquire(int& l, int& r);
|
||||
int dispatch(DivCommand c);
|
||||
void tick();
|
||||
int init(DivEngine* parent, int channels, int sugRate);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
// TODO fix all the writes.
|
||||
// i think there is no wait for data writes, just for ON/OFF writes
|
||||
void DivPlatformGenesis::acquire(short& l, short& r) {
|
||||
void DivPlatformGenesis::acquire(int& l, int& r) {
|
||||
static short o[2];
|
||||
|
||||
if (dacMode && dacSample!=-1) {
|
||||
|
|
@ -43,7 +43,7 @@ void DivPlatformGenesis::acquire(short& l, short& r) {
|
|||
if (psgClocks>=rate) {
|
||||
psg.acquire(psgOut,psgOut);
|
||||
psgClocks-=rate;
|
||||
psgOut>>=2;
|
||||
psgOut=(psgOut>>2)+(psgOut>>3);
|
||||
}
|
||||
|
||||
l=(o[0]<<7)+psgOut;
|
||||
|
|
@ -89,9 +89,9 @@ void DivPlatformGenesis::tick() {
|
|||
}
|
||||
|
||||
for (int i=0; i<512; i++) {
|
||||
if (pendingWrites[i]!=-1) {
|
||||
if (pendingWrites[i]!=oldWrites[i]) {
|
||||
writes.emplace(i,pendingWrites[i]&0xff);
|
||||
pendingWrites[i]=-1;
|
||||
oldWrites[i]=pendingWrites[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,28 +156,25 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
}
|
||||
DivInstrument* ins=parent->song.ins[chan[c.chan].ins];
|
||||
|
||||
if (chan[c.chan].insChanged) {
|
||||
chan[c.chan].insChanged=false;
|
||||
for (int i=0; i<4; i++) {
|
||||
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[i];
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
if (isOutput[ins->fm.alg][i]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-op.tl)*chan[c.chan].vol)/127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6));
|
||||
rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7));
|
||||
rWrite(baseAddr+0x70,op.d2r&31);
|
||||
rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4));
|
||||
rWrite(baseAddr+0x90,op.ssgEnv&15);
|
||||
for (int i=0; i<4; i++) {
|
||||
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[i];
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
if (isOutput[ins->fm.alg][i]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-op.tl)*chan[c.chan].vol)/127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
rWrite(chanOffs[c.chan]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[c.chan]+0xb4,(chan[c.chan].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6));
|
||||
rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7));
|
||||
rWrite(baseAddr+0x70,op.d2r&31);
|
||||
rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4));
|
||||
rWrite(baseAddr+0x90,op.ssgEnv&15);
|
||||
}
|
||||
rWrite(chanOffs[c.chan]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[c.chan]+0xb4,(chan[c.chan].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f));
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(2048+chan[c.chan].pitch))>>11;
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(ONE_SEMITONE+chan[c.chan].pitch))/ONE_SEMITONE;
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].keyOn=true;
|
||||
chan[c.chan].active=true;
|
||||
|
|
@ -225,7 +222,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
}
|
||||
case DIV_CMD_PITCH: {
|
||||
chan[c.chan].pitch=c.value;
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(2048+chan[c.chan].pitch))>>11;
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(ONE_SEMITONE+chan[c.chan].pitch))/ONE_SEMITONE;
|
||||
chan[c.chan].freqChanged=true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -245,7 +242,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
return2=true;
|
||||
}
|
||||
}
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(2048+chan[c.chan].pitch))>>11;
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(ONE_SEMITONE+chan[c.chan].pitch))/ONE_SEMITONE;
|
||||
chan[c.chan].freqChanged=true;
|
||||
if (return2) return 2;
|
||||
break;
|
||||
|
|
@ -259,7 +256,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
}
|
||||
case DIV_CMD_LEGATO: {
|
||||
chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f));
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(2048+chan[c.chan].pitch))>>11;
|
||||
chan[c.chan].freq=(chan[c.chan].baseFreq*(ONE_SEMITONE+chan[c.chan].pitch))/ONE_SEMITONE;
|
||||
chan[c.chan].freqChanged=true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -312,6 +309,7 @@ int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) {
|
|||
}
|
||||
|
||||
for (int i=0; i<512; i++) {
|
||||
oldWrites[i]=-1;
|
||||
pendingWrites[i]=-1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class DivPlatformGenesis: public DivDispatch {
|
|||
ym3438_t fm;
|
||||
DivPlatformSMS psg;
|
||||
int psgClocks;
|
||||
short psgOut;
|
||||
int psgOut;
|
||||
int delay;
|
||||
unsigned char lastBusy;
|
||||
|
||||
|
|
@ -36,10 +36,11 @@ class DivPlatformGenesis: public DivDispatch {
|
|||
int dacPos;
|
||||
int dacSample;
|
||||
|
||||
short oldWrites[512];
|
||||
short pendingWrites[512];
|
||||
|
||||
public:
|
||||
void acquire(short& l, short& r);
|
||||
void acquire(int& l, int& r);
|
||||
int dispatch(DivCommand c);
|
||||
void tick();
|
||||
int init(DivEngine* parent, int channels, int sugRate);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include "../engine.h"
|
||||
#include <math.h>
|
||||
|
||||
void DivPlatformSMS::acquire(short& l, short& r) {
|
||||
void DivPlatformSMS::acquire(int& l, int& r) {
|
||||
short v;
|
||||
sn->sound_stream_update(&v,1);
|
||||
l=v;
|
||||
|
|
@ -13,10 +13,14 @@ void DivPlatformSMS::tick() {
|
|||
for (int i=0; i<4; i++) {
|
||||
chan[i].std.next();
|
||||
if (chan[i].std.hadVol) sn->write(0x90|(i<<5)|(15-((chan[i].vol*chan[i].std.vol)>>4)));
|
||||
if (chan[i].std.hadArp) {
|
||||
chan[i].baseFreq=round(1712.0f/pow(2.0f,((float)(chan[i].note+chan[i].std.arp-12)/12.0f)));
|
||||
chan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
for (int i=0; i<3; i++) {
|
||||
if (chan[i].freqChanged) {
|
||||
chan[i].freq=(chan[i].baseFreq*(2048-chan[i].pitch))>>11;
|
||||
chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE-chan[i].pitch))/ONE_SEMITONE;
|
||||
sn->write(0x80|i<<5|(chan[i].freq&15));
|
||||
sn->write(chan[i].freq>>4);
|
||||
chan[i].freqChanged=false;
|
||||
|
|
@ -24,7 +28,7 @@ void DivPlatformSMS::tick() {
|
|||
}
|
||||
if (chan[3].freqChanged || updateSNMode) {
|
||||
updateSNMode=false;
|
||||
chan[3].freq=(chan[3].baseFreq*(2048-chan[3].pitch))>>11;
|
||||
chan[3].freq=(chan[3].baseFreq*(ONE_SEMITONE-chan[3].pitch))/ONE_SEMITONE;
|
||||
chan[3].freqChanged=false;
|
||||
if (snNoiseMode&2) { // take period from channel 3
|
||||
if (snNoiseMode&1) {
|
||||
|
|
@ -47,7 +51,7 @@ void DivPlatformSMS::tick() {
|
|||
int DivPlatformSMS::dispatch(DivCommand c) {
|
||||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON:
|
||||
chan[c.chan].baseFreq=1712/pow(2.0f,((float)c.value/12.0f));
|
||||
chan[c.chan].baseFreq=round(1712.0f/pow(2.0f,((float)c.value/12.0f)));
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
chan[c.chan].active=true;
|
||||
|
|
@ -61,7 +65,7 @@ int DivPlatformSMS::dispatch(DivCommand c) {
|
|||
break;
|
||||
case DIV_CMD_INSTRUMENT:
|
||||
chan[c.chan].ins=c.value;
|
||||
chan[c.chan].std.init(parent->song.ins[chan[c.chan].ins]);
|
||||
//chan[c.chan].std.init(parent->song.ins[chan[c.chan].ins]);
|
||||
break;
|
||||
case DIV_CMD_VOLUME:
|
||||
chan[c.chan].vol=c.value;
|
||||
|
|
@ -71,10 +75,35 @@ int DivPlatformSMS::dispatch(DivCommand c) {
|
|||
chan[c.chan].pitch=c.value;
|
||||
chan[c.chan].freqChanged=true;
|
||||
break;
|
||||
case DIV_CMD_NOTE_PORTA: {
|
||||
int destFreq=round(1712.0f/pow(2.0f,((float)c.value2/12.0f)));
|
||||
bool return2=false;
|
||||
if (destFreq>chan[c.chan].baseFreq) {
|
||||
chan[c.chan].baseFreq+=c.value;
|
||||
if (chan[c.chan].baseFreq>=destFreq) {
|
||||
chan[c.chan].baseFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
} else {
|
||||
chan[c.chan].baseFreq-=c.value;
|
||||
if (chan[c.chan].baseFreq<=destFreq) {
|
||||
chan[c.chan].baseFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
}
|
||||
chan[c.chan].freqChanged=true;
|
||||
if (return2) return 2;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_STD_NOISE_MODE:
|
||||
snNoiseMode=(c.value&1)|((c.value&16)>>3);
|
||||
updateSNMode=true;
|
||||
break;
|
||||
case DIV_CMD_LEGATO:
|
||||
chan[c.chan].baseFreq=round(1712.0f/pow(2.0f,((float)c.value/12.0f)));
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class DivPlatformSMS: public DivDispatch {
|
|||
bool updateSNMode;
|
||||
sn76496_device* sn;
|
||||
public:
|
||||
void acquire(short& l, short& r);
|
||||
void acquire(int& l, int& r);
|
||||
int dispatch(DivCommand c);
|
||||
void tick();
|
||||
int init(DivEngine* parent, int channels, int sugRate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue