From 0208883fa1c5be5f92af5566d11002cf65cae3f2 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 17 Dec 2023 14:54:38 -0500 Subject: [PATCH] OPL and OPLL vol map --- src/engine/platform/fmshared_OPN.h | 2 +- src/engine/platform/fmsharedbase.h | 2 +- src/engine/platform/opl.cpp | 15 +++++++++++++++ src/engine/platform/opl.h | 1 + src/engine/platform/opll.cpp | 7 +++++++ src/engine/platform/opll.h | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/fmshared_OPN.h b/src/engine/platform/fmshared_OPN.h index 3f1267739..e7d06c7f5 100644 --- a/src/engine/platform/fmshared_OPN.h +++ b/src/engine/platform/fmshared_OPN.h @@ -191,7 +191,7 @@ class DivPlatformOPN: public DivPlatformFMBase { if (ch==adpcmBChanOffs) return vel*255.0; if (ch>=adpcmAChanOffs) { if (vel==0) return 0; - if (vel==127) return 31; + if (vel>=1.0) 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)); diff --git a/src/engine/platform/fmsharedbase.h b/src/engine/platform/fmsharedbase.h index 3a12f96e6..f20292a0d 100644 --- a/src/engine/platform/fmsharedbase.h +++ b/src/engine/platform/fmsharedbase.h @@ -132,7 +132,7 @@ class DivPlatformFMBase: public DivDispatch { // -36: 2: 48 // -42: 1: 56 if (vel==0) return 0; - if (vel==127) return 127; + if (vel>=1.0) return 127; return CLAMP(round(128.0-(56.0-log2(vel*127.0)*8.0)),0,127); } diff --git a/src/engine/platform/opl.cpp b/src/engine/platform/opl.cpp index 8eb95fc28..c68271743 100644 --- a/src/engine/platform/opl.cpp +++ b/src/engine/platform/opl.cpp @@ -2104,6 +2104,21 @@ DivDispatchOscBuffer* DivPlatformOPL::getOscBuffer(int ch) { return oscBuf[ch]; } +int DivPlatformOPL::mapVelocity(int ch, float vel) { + if (ch==adpcmChan) return vel*255.0; + // -0.75dB per step + // -6: 64: 8 + // -12: 32: 16 + // -18: 16: 24 + // -24: 8: 32 + // -30: 4: 40 + // -36: 2: 48 + // -42: 1: 56 + if (vel==0) return 0; + if (vel>=1.0) return 63; + return CLAMP(round(64.0-(56.0-log2(vel*127.0)*8.0)),0,63); +} + unsigned char* DivPlatformOPL::getRegisterPool() { return regPool; } diff --git a/src/engine/platform/opl.h b/src/engine/platform/opl.h index c4346a21e..bef02db5e 100644 --- a/src/engine/platform/opl.h +++ b/src/engine/platform/opl.h @@ -150,6 +150,7 @@ class DivPlatformOPL: public DivDispatch { unsigned short getPan(int chan); DivChannelPair getPaired(int chan); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); unsigned char* getRegisterPool(); int getRegisterPoolSize(); void reset(); diff --git a/src/engine/platform/opll.cpp b/src/engine/platform/opll.cpp index 3f1621c02..9228568ef 100644 --- a/src/engine/platform/opll.cpp +++ b/src/engine/platform/opll.cpp @@ -962,6 +962,13 @@ DivDispatchOscBuffer* DivPlatformOPLL::getOscBuffer(int ch) { return oscBuf[ch]; } +int DivPlatformOPLL::mapVelocity(int ch, float vel) { + // -3dB per step + if (vel==0) return 0; + if (vel>=1.0) return 15; + return CLAMP(round(16.0-(14.0-log2(vel*127.0)*2.0)),0,15); +} + unsigned char* DivPlatformOPLL::getRegisterPool() { return regPool; } diff --git a/src/engine/platform/opll.h b/src/engine/platform/opll.h index e8bd627a4..70ece9c1e 100644 --- a/src/engine/platform/opll.h +++ b/src/engine/platform/opll.h @@ -95,6 +95,7 @@ class DivPlatformOPLL: public DivDispatch { void* getChanState(int chan); DivMacroInt* getChanMacroInt(int ch); DivDispatchOscBuffer* getOscBuffer(int chan); + int mapVelocity(int ch, float vel); unsigned char* getRegisterPool(); int getRegisterPoolSize(); void reset();