diff --git a/src/engine/platform/gb.cpp b/src/engine/platform/gb.cpp index 76915716..8ca75f92 100644 --- a/src/engine/platform/gb.cpp +++ b/src/engine/platform/gb.cpp @@ -29,21 +29,59 @@ static unsigned char gbVolMap[16]={ 0x20, 0x20, 0x20, 0x20 }; +static unsigned char noiseTable[256]={ + 0, + 0xf7, 0xf6, 0xf5, 0xf4, + 0xe7, 0xe6, 0xe5, 0xe4, + 0xd7, 0xd6, 0xd5, 0xd4, + 0xc7, 0xc6, 0xc5, 0xc4, + 0xb7, 0xb6, 0xb5, 0xb4, + 0xa7, 0xa6, 0xa5, 0xa4, + 0x97, 0x96, 0x95, 0x94, + 0x87, 0x86, 0x85, 0x84, + 0x77, 0x76, 0x75, 0x74, + 0x67, 0x66, 0x65, 0x64, + 0x57, 0x56, 0x55, 0x54, + 0x47, 0x46, 0x45, 0x44, + 0x37, 0x36, 0x35, 0x34, + 0x27, 0x26, 0x25, 0x24, + 0x17, 0x16, 0x15, 0x14, + 0x07, 0x06, 0x05, 0x04, + 0x03, 0x02, 0x01, 0x00, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + void DivPlatformGB::tick() { for (int i=0; i<4; i++) { chan[i].std.next(); if (chan[i].std.hadArp) { - if (chan[i].std.arpMode) { - chan[i].baseFreq=round(FREQ_BASE/pow(2.0f,((float)(chan[i].std.arp)/12.0f))); + if (i==3) { // noise + if (chan[i].std.arpMode) { + chan[i].baseFreq=chan[i].std.arp; + } else { + chan[i].baseFreq=chan[i].note+chan[i].std.arp-12; + } } else { - chan[i].baseFreq=round(FREQ_BASE/pow(2.0f,((float)(chan[i].note+chan[i].std.arp-12)/12.0f))); + if (chan[i].std.arpMode) { + chan[i].baseFreq=round(FREQ_BASE/pow(2.0f,((float)(chan[i].std.arp)/12.0f))); + } else { + chan[i].baseFreq=round(FREQ_BASE/pow(2.0f,((float)(chan[i].note+chan[i].std.arp-12)/12.0f))); + } } chan[i].freqChanged=true; } if (chan[i].std.hadDuty) { chan[i].duty=chan[i].std.duty; + DivInstrument* ins=parent->getIns(chan[i].ins); if (i!=2) { - rWrite(16+i*5+1,(chan[i].duty&3)<<6); + rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63))); } } if (chan[i].std.hadWave) { @@ -56,10 +94,14 @@ void DivPlatformGB::tick() { } } if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { - chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE-chan[i].pitch))/ONE_SEMITONE; + DivInstrument* ins=parent->getIns(chan[i].ins); + if (i==3) { // noise + chan[i].freq=noiseTable[chan[i].baseFreq]; + } else { + chan[i].freq=(chan[i].baseFreq*(ONE_SEMITONE-chan[i].pitch))/ONE_SEMITONE; + } if (chan[i].note>0x5d) chan[i].freq=0x01; if (chan[i].keyOn) { - DivInstrument* ins=parent->getIns(chan[i].ins); if (i==2) { // wave if (chan[i].wave<0) { chan[i].wave=0; @@ -69,6 +111,7 @@ void DivPlatformGB::tick() { rWrite(16+i*5+2,gbVolMap[chan[i].vol]); } else { rWrite(16+i*5,0x00); + rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63))); rWrite(16+i*5+2,((chan[i].vol<<4))|(ins->gb.envLen&7)|((ins->gb.envDir&1)<<3)); } } @@ -79,8 +122,13 @@ void DivPlatformGB::tick() { rWrite(16+i*5+2,8); } } - rWrite(16+i*5+3,(2048-chan[i].freq)&0xff); - rWrite(16+i*5+4,(((2048-chan[i].freq)>>8)&7)|((chan[i].keyOn||chan[i].keyOff)?0x80:0x00)); + if (i==3) { // noise + rWrite(16+i*5+3,chan[i].freq&0xff); + rWrite(16+i*5+4,((chan[i].keyOn||chan[i].keyOff)?0x80:0x00)|((ins->gb.soundLen<64)<<6)); + } else { + rWrite(16+i*5+3,(2048-chan[i].freq)&0xff); + rWrite(16+i*5+4,(((2048-chan[i].freq)>>8)&7)|((chan[i].keyOn||chan[i].keyOff)?0x80:0x00)|((ins->gb.soundLen<63)<<6)); + } if (chan[i].keyOn) chan[i].keyOn=false; if (chan[i].keyOff) chan[i].keyOff=false; chan[i].freqChanged=false; @@ -98,7 +146,11 @@ void DivPlatformGB::tick() { int DivPlatformGB::dispatch(DivCommand c) { switch (c.cmd) { case DIV_CMD_NOTE_ON: - chan[c.chan].baseFreq=round(FREQ_BASE/pow(2.0f,((float)c.value/12.0f))); + if (c.chan==3) { // noise + chan[c.chan].baseFreq=c.value; + } else { + chan[c.chan].baseFreq=round(FREQ_BASE/pow(2.0f,((float)c.value/12.0f))); + } chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; chan[c.chan].active=true; @@ -156,6 +208,7 @@ int DivPlatformGB::dispatch(DivCommand c) { updateSNMode=true; break; case DIV_CMD_LEGATO: + if (c.chan==3) break; chan[c.chan].baseFreq=round(FREQ_BASE/pow(2.0f,((float)c.value/12.0f))); chan[c.chan].freqChanged=true; chan[c.chan].note=c.value; diff --git a/src/engine/platform/gb.h b/src/engine/platform/gb.h index 302f7c45..6e008536 100644 --- a/src/engine/platform/gb.h +++ b/src/engine/platform/gb.h @@ -19,13 +19,13 @@ class DivPlatformGB: public DivDispatch { ins(-1), note(0), duty(0), - wave(-1), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), - vol(15) {} + vol(15), + wave(-1) {} }; Channel chan[4]; unsigned char snNoiseMode; diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 714447f3..88a04542 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -5,6 +5,13 @@ #include "genesisshared.h" +static int dacRates[6]={ + 160,160,116,80,58,40 +}; +static unsigned char konOffs[6]={ + 0, 1, 2, 4, 5, 6 +}; + void DivPlatformGenesis::acquire(int& l, int& r) { static short o[2]; diff --git a/src/engine/platform/genesisshared.h b/src/engine/platform/genesisshared.h index 8fd58120..cf0047e7 100644 --- a/src/engine/platform/genesisshared.h +++ b/src/engine/platform/genesisshared.h @@ -4,9 +4,6 @@ static unsigned short chanOffs[6]={ static unsigned short opOffs[4]={ 0x00, 0x04, 0x08, 0x0c }; -static unsigned char konOffs[6]={ - 0, 1, 2, 4, 5, 6 -}; static bool isOutput[8][4]={ // 1 3 2 4 {false,false,false,true}, @@ -21,9 +18,7 @@ static bool isOutput[8][4]={ static unsigned char dtTable[8]={ 7,6,5,0,1,2,3,0 }; -static int dacRates[6]={ - 160,160,116,80,58,40 -}; + static int orderedOps[4]={ 0,2,1,3 }; diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index 24d89ce0..9af28b49 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -156,7 +156,7 @@ int DivPlatformSMS::dispatch(DivCommand c) { int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate) { parent=p; rate=223722; - sn=new sn76496_device("sn",223722); + sn=new sn76496_device(223722); sn->device_start(); snNoiseMode=3; updateSNMode=false; diff --git a/src/engine/platform/sound/gb/apu.c b/src/engine/platform/sound/gb/apu.c index 7abac902..092dd29f 100644 --- a/src/engine/platform/sound/gb/apu.c +++ b/src/engine/platform/sound/gb/apu.c @@ -266,7 +266,6 @@ static void render(GB_gameboy_t *gb) } - /* if (gb->apu_output.interference_volume) { signed interference_bias = interference(gb); int16_t interference_sample = (interference_bias - gb->apu_output.interference_highpass); @@ -276,7 +275,7 @@ static void render(GB_gameboy_t *gb) filtered_output.left = MAX(MIN(filtered_output.left + interference_bias, 0x7FFF), -0x8000); filtered_output.right = MAX(MIN(filtered_output.right + interference_bias, 0x7FFF), -0x8000); - }*/ + } gb->apu_output.final_sample=filtered_output; } diff --git a/src/engine/platform/sound/sn76496.cpp b/src/engine/platform/sound/sn76496.cpp index e0c896b6..08c4cc38 100644 --- a/src/engine/platform/sound/sn76496.cpp +++ b/src/engine/platform/sound/sn76496.cpp @@ -148,7 +148,6 @@ //#define NOISE_START 0x0f35 sn76496_base_device::sn76496_base_device( - const char *tag, int feedbackmask, int noisetap1, int noisetap2, @@ -167,8 +166,8 @@ sn76496_base_device::sn76496_base_device( { } -sn76496_device::sn76496_device(const char *tag, uint32_t clock) - : sn76496_base_device(tag, 0x8000, 0x01, 0x08, false, 1, false, false, clock) +sn76496_device::sn76496_device(uint32_t clock) + : sn76496_base_device(0x8000, 0x01, 0x08, false, 1, false, false, clock) { } diff --git a/src/engine/platform/sound/sn76496.h b/src/engine/platform/sound/sn76496.h index 2c02d6d4..4311766d 100644 --- a/src/engine/platform/sound/sn76496.h +++ b/src/engine/platform/sound/sn76496.h @@ -20,7 +20,6 @@ public: protected: sn76496_base_device( - const char *tag, int feedbackmask, int noisetap1, int noisetap2, @@ -59,7 +58,7 @@ private: class sn76496_device : public sn76496_base_device { public: - sn76496_device(const char *tag, uint32_t clock); + sn76496_device(uint32_t clock); }; #endif // MAME_SOUND_SN76496_H