From 8d30ac4d3baa5b2459540838e72b9c99ac365f0b Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 17 Dec 2023 14:41:25 -0500 Subject: [PATCH] OPN: proper vol map for SSG/ADPCM/CSM/DAC parts --- src/engine/platform/fmshared_OPN.h | 11 +++++++++++ src/engine/platform/genesis.cpp | 6 ++++++ src/engine/platform/genesis.h | 1 + src/engine/platform/genesisext.cpp | 6 ++++++ src/engine/platform/genesisext.h | 1 + src/engine/platform/ym2203ext.cpp | 6 ++++++ src/engine/platform/ym2203ext.h | 1 + src/engine/platform/ym2608ext.cpp | 6 ++++++ src/engine/platform/ym2608ext.h | 1 + src/engine/platform/ym2610bext.cpp | 6 ++++++ src/engine/platform/ym2610bext.h | 1 + src/engine/platform/ym2610ext.cpp | 6 ++++++ src/engine/platform/ym2610ext.h | 1 + 13 files changed, 53 insertions(+) diff --git a/src/engine/platform/fmshared_OPN.h b/src/engine/platform/fmshared_OPN.h index 32ea4c002..3f1267739 100644 --- a/src/engine/platform/fmshared_OPN.h +++ b/src/engine/platform/fmshared_OPN.h @@ -186,6 +186,17 @@ class DivPlatformOPN: public DivPlatformFMBase { void setCombo(bool combo) { useCombo=combo; } + virtual int mapVelocity(int ch, float vel) { + if (ch==csmChan) return vel*127.0; + if (ch==adpcmBChanOffs) return vel*255.0; + if (ch>=adpcmAChanOffs) { + if (vel==0) return 0; + if (vel==127) return 31; + return CLAMP(round(32.0-(56.0-log2(vel*127.0)*8.0)),0,31); + } + if (ch>=psgChanOffs) return round(15.0*pow(vel,0.33)); + return DivPlatformFMBase::mapVelocity(ch,vel); + } }; #endif diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 633bf2886..c90404eae 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -1300,6 +1300,12 @@ DivDispatchOscBuffer* DivPlatformGenesis::getOscBuffer(int ch) { return oscBuf[ch]; } +int DivPlatformGenesis::mapVelocity(int ch, float vel) { + if (ch==csmChan) return DivPlatformOPN::mapVelocity(ch,vel); + if (ch>5) return DivPlatformOPN::mapVelocity(5,vel); + return DivPlatformOPN::mapVelocity(ch,vel); +} + unsigned char* DivPlatformGenesis::getRegisterPool() { return regPool; } diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index 82d4301b9..a12e6625d 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -112,6 +112,7 @@ class DivPlatformGenesis: public DivPlatformOPN { virtual unsigned short getPan(int chan); DivSamplePos getSamplePos(int ch); DivDispatchOscBuffer* getOscBuffer(int chan); + virtual int mapVelocity(int ch, float vel); unsigned char* getRegisterPool(); int getRegisterPoolSize(); void reset(); diff --git a/src/engine/platform/genesisext.cpp b/src/engine/platform/genesisext.cpp index aab02e1e1..0097f763f 100644 --- a/src/engine/platform/genesisext.cpp +++ b/src/engine/platform/genesisext.cpp @@ -818,6 +818,12 @@ DivDispatchOscBuffer* DivPlatformGenesisExt::getOscBuffer(int ch) { return NULL; } +int DivPlatformGenesisExt::mapVelocity(int ch, float vel) { + if (ch>=extChanOffs+4) return DivPlatformGenesis::mapVelocity(ch-3,vel); + if (ch>=extChanOffs) return DivPlatformGenesis::mapVelocity(extChanOffs,vel); + return DivPlatformGenesis::mapVelocity(ch,vel); +} + void DivPlatformGenesisExt::reset() { DivPlatformGenesis::reset(); diff --git a/src/engine/platform/genesisext.h b/src/engine/platform/genesisext.h index 63112c069..d6ab86924 100644 --- a/src/engine/platform/genesisext.h +++ b/src/engine/platform/genesisext.h @@ -36,6 +36,7 @@ class DivPlatformGenesisExt: public DivPlatformGenesis { DivMacroInt* getChanMacroInt(int ch); unsigned short getPan(int chan); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); void reset(); void forceIns(); void tick(bool sysTick=true); diff --git a/src/engine/platform/ym2203ext.cpp b/src/engine/platform/ym2203ext.cpp index adb312ad8..bcb84e19b 100644 --- a/src/engine/platform/ym2203ext.cpp +++ b/src/engine/platform/ym2203ext.cpp @@ -692,6 +692,12 @@ DivDispatchOscBuffer* DivPlatformYM2203Ext::getOscBuffer(int ch) { return NULL; } +int DivPlatformYM2203Ext::mapVelocity(int ch, float vel) { + if (ch>=extChanOffs+4) return DivPlatformOPN::mapVelocity(ch-3,vel); + if (ch>=extChanOffs) return DivPlatformOPN::mapVelocity(extChanOffs,vel); + return DivPlatformOPN::mapVelocity(ch,vel); +} + void DivPlatformYM2203Ext::reset() { DivPlatformYM2203::reset(); diff --git a/src/engine/platform/ym2203ext.h b/src/engine/platform/ym2203ext.h index 731e2a202..f0e468158 100644 --- a/src/engine/platform/ym2203ext.h +++ b/src/engine/platform/ym2203ext.h @@ -34,6 +34,7 @@ class DivPlatformYM2203Ext: public DivPlatformYM2203 { void* getChanState(int chan); DivMacroInt* getChanMacroInt(int ch); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); void reset(); void forceIns(); void tick(bool sysTick=true); diff --git a/src/engine/platform/ym2608ext.cpp b/src/engine/platform/ym2608ext.cpp index 50424d4eb..589bd542a 100644 --- a/src/engine/platform/ym2608ext.cpp +++ b/src/engine/platform/ym2608ext.cpp @@ -767,6 +767,12 @@ DivDispatchOscBuffer* DivPlatformYM2608Ext::getOscBuffer(int ch) { return NULL; } +int DivPlatformYM2608Ext::mapVelocity(int ch, float vel) { + if (ch>=extChanOffs+4) return DivPlatformOPN::mapVelocity(ch-3,vel); + if (ch>=extChanOffs) return DivPlatformOPN::mapVelocity(extChanOffs,vel); + return DivPlatformOPN::mapVelocity(ch,vel); +} + void DivPlatformYM2608Ext::reset() { DivPlatformYM2608::reset(); diff --git a/src/engine/platform/ym2608ext.h b/src/engine/platform/ym2608ext.h index 0c9c1a418..159a6c807 100644 --- a/src/engine/platform/ym2608ext.h +++ b/src/engine/platform/ym2608ext.h @@ -35,6 +35,7 @@ class DivPlatformYM2608Ext: public DivPlatformYM2608 { DivMacroInt* getChanMacroInt(int ch); unsigned short getPan(int chan); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); void reset(); void forceIns(); void tick(bool sysTick=true); diff --git a/src/engine/platform/ym2610bext.cpp b/src/engine/platform/ym2610bext.cpp index 545a80e98..c0b0282b2 100644 --- a/src/engine/platform/ym2610bext.cpp +++ b/src/engine/platform/ym2610bext.cpp @@ -757,6 +757,12 @@ DivDispatchOscBuffer* DivPlatformYM2610BExt::getOscBuffer(int ch) { return NULL; } +int DivPlatformYM2610BExt::mapVelocity(int ch, float vel) { + if (ch>=extChanOffs+4) return DivPlatformOPN::mapVelocity(ch-3,vel); + if (ch>=extChanOffs) return DivPlatformOPN::mapVelocity(extChanOffs,vel); + return DivPlatformOPN::mapVelocity(ch,vel); +} + void DivPlatformYM2610BExt::reset() { DivPlatformYM2610B::reset(); diff --git a/src/engine/platform/ym2610bext.h b/src/engine/platform/ym2610bext.h index 024119cff..e7feaf3c2 100644 --- a/src/engine/platform/ym2610bext.h +++ b/src/engine/platform/ym2610bext.h @@ -35,6 +35,7 @@ class DivPlatformYM2610BExt: public DivPlatformYM2610B { DivMacroInt* getChanMacroInt(int ch); unsigned short getPan(int chan); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); void reset(); void forceIns(); void tick(bool sysTick=true); diff --git a/src/engine/platform/ym2610ext.cpp b/src/engine/platform/ym2610ext.cpp index 39e341675..063fd5c36 100644 --- a/src/engine/platform/ym2610ext.cpp +++ b/src/engine/platform/ym2610ext.cpp @@ -757,6 +757,12 @@ DivDispatchOscBuffer* DivPlatformYM2610Ext::getOscBuffer(int ch) { return NULL; } +int DivPlatformYM2610Ext::mapVelocity(int ch, float vel) { + if (ch>=extChanOffs+4) return DivPlatformOPN::mapVelocity(ch-3,vel); + if (ch>=extChanOffs) return DivPlatformOPN::mapVelocity(extChanOffs,vel); + return DivPlatformOPN::mapVelocity(ch,vel); +} + void DivPlatformYM2610Ext::reset() { DivPlatformYM2610::reset(); diff --git a/src/engine/platform/ym2610ext.h b/src/engine/platform/ym2610ext.h index f860a36cd..666f0d40f 100644 --- a/src/engine/platform/ym2610ext.h +++ b/src/engine/platform/ym2610ext.h @@ -35,6 +35,7 @@ class DivPlatformYM2610Ext: public DivPlatformYM2610 { DivMacroInt* getChanMacroInt(int ch); unsigned short getPan(int chan); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); void reset(); void forceIns(); void tick(bool sysTick=true);