diff --git a/Components/OPL2/Implementation/Channel.cpp b/Components/OPL2/Implementation/Channel.cpp index 5a04369bc..20b141f63 100644 --- a/Components/OPL2/Implementation/Channel.cpp +++ b/Components/OPL2/Implementation/Channel.cpp @@ -7,7 +7,6 @@ // #include "Channel.hpp" -#include "Tables.h" using namespace Yamaha::OPL; diff --git a/Components/OPL2/Implementation/Operator.cpp b/Components/OPL2/Implementation/Operator.cpp index afad9e198..ef0b04ecf 100644 --- a/Components/OPL2/Implementation/Operator.cpp +++ b/Components/OPL2/Implementation/Operator.cpp @@ -9,12 +9,11 @@ #include "Operator.hpp" #include -#include "Tables.h" using namespace Yamaha::OPL; int OperatorState::level() { - return power_two(attenuation.logsin) * attenuation.sign; + return power_two(attenuation); } void Operator::set_attack_decay(uint8_t value) { @@ -179,10 +178,10 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int // Overrides here represent per-channel volume on an OPLL. The bits are defined to represent // attenuations of 24db to 3db; the main envelope generator is stated to have a resolution of // 0.325db (which I've assumed is supposed to say 0.375db). - state.attenuation.logsin += state.adsr_attenuation_ + (overrides->attenuation << 4); + state.attenuation.log += state.adsr_attenuation_ + (overrides->attenuation << 4); } else { // Overrides here represent per-channel volume on an OPLL. The bits are defined to represent // attenuations of 24db to 0.75db. - state.attenuation.logsin += (state.adsr_attenuation_ << 3) + (attenuation_ << 5); + state.attenuation.log += (state.adsr_attenuation_ << 3) + (attenuation_ << 5); } } diff --git a/Components/OPL2/Implementation/Operator.hpp b/Components/OPL2/Implementation/Operator.hpp index 7e16881ae..1c5f73b87 100644 --- a/Components/OPL2/Implementation/Operator.hpp +++ b/Components/OPL2/Implementation/Operator.hpp @@ -10,7 +10,7 @@ #define Operator_hpp #include -#include "Tables.h" +#include "Tables.hpp" namespace Yamaha { namespace OPL { @@ -24,7 +24,7 @@ struct OperatorState { int level(); private: - LogSin attenuation; + LogSign attenuation; int raw_phase_ = 0; enum class ADSRPhase { diff --git a/Components/OPL2/Implementation/Tables.h b/Components/OPL2/Implementation/Tables.hpp similarity index 95% rename from Components/OPL2/Implementation/Tables.h rename to Components/OPL2/Implementation/Tables.hpp index 2d3474056..849a8d1aa 100644 --- a/Components/OPL2/Implementation/Tables.h +++ b/Components/OPL2/Implementation/Tables.hpp @@ -1,13 +1,13 @@ // -// Tables.h +// Tables.hpp // Clock Signal // // Created by Thomas Harte on 15/04/2020. // Copyright © 2020 Thomas Harte. All rights reserved. // -#ifndef Tables_h -#define Tables_h +#ifndef Tables_hpp +#define Tables_hpp namespace Yamaha { namespace OPL { @@ -21,14 +21,14 @@ namespace OPL { */ -struct LogSin { - int logsin; +struct LogSign { + int log; int sign; }; /*! @returns Negative log sin of x, assuming a 1024-unit circle. */ -constexpr LogSin negative_log_sin(int x) { +constexpr LogSign negative_log_sin(int x) { /// Defines the first quadrant of 1024-unit negative log to the base two of sine (that conveniently misses sin(0)). /// /// Expected branchless usage for a full 1024 unit output: @@ -77,7 +77,7 @@ constexpr LogSin negative_log_sin(int x) { constexpr int16_t mask[] = { 0, 255 }; return { - .logsin = log_sin[x & 255] ^ mask[(x >> 8) & 1], + .log = log_sin[x & 255] ^ mask[(x >> 8) & 1], .sign = sign[(x >> 9) & 1] }; } @@ -85,7 +85,7 @@ constexpr LogSin negative_log_sin(int x) { /*! @returns 2 ^ -x/256 in 0.10 fixed-point form. */ -constexpr int power_two(int x) { +constexpr int power_two(LogSign ls) { /// A derivative of the exponent table in a real OPL2; mapped_exp[x] = (source[c ^ 0xff] << 1) | 0x800. /// /// The ahead-of-time transformation represents fixed work the OPL2 does when reading its table @@ -102,7 +102,7 @@ constexpr int power_two(int x) { /// be achieved more easily. Specifically, to convert a logarithmic attenuation to a linear one, just perform: /// /// result = mapped_exp[x & 0xff] >> (x >> 8) - constexpr int mapped_exp[] = { + constexpr int16_t mapped_exp[] = { 4084, 4074, 4062, 4052, 4040, 4030, 4020, 4008, 3998, 3986, 3976, 3966, 3954, 3944, 3932, 3922, 3912, 3902, 3890, 3880, 3870, 3860, 3848, 3838, @@ -137,7 +137,7 @@ constexpr int power_two(int x) { 2088, 2082, 2076, 2070, 2064, 2060, 2054, 2048, }; - return mapped_exp[x & 0xff] >> (x >> 8); + return (mapped_exp[ls.log & 0xff] >> (ls.log >> 8)) * ls.sign; } /* @@ -195,4 +195,4 @@ constexpr uint8_t percussion_patch_set[] = { } } -#endif /* Tables_h */ +#endif /* Tables_hpp */ diff --git a/Components/OPL2/OPL2.cpp b/Components/OPL2/OPL2.cpp index be77dbd93..43b1b6278 100644 --- a/Components/OPL2/OPL2.cpp +++ b/Components/OPL2/OPL2.cpp @@ -11,8 +11,6 @@ #include #include -#include "Implementation/Tables.h" - using namespace Yamaha::OPL; template diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 7dd146177..9fc317b2d 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1660,7 +1660,7 @@ 4BC0CB312447EC7C00A79DBB /* Operator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Operator.hpp; sourceTree = ""; }; 4BC0CB352447EC9A00A79DBB /* Channel.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Channel.cpp; sourceTree = ""; }; 4BC0CB362447EC9A00A79DBB /* Channel.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Channel.hpp; sourceTree = ""; }; - 4BC0CB3A2447ECAE00A79DBB /* Tables.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tables.h; sourceTree = ""; }; + 4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Tables.hpp; sourceTree = ""; }; 4BC1316D2346DE5000E4FF3D /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaticAnalyser.hpp; sourceTree = ""; }; 4BC1316E2346DE5000E4FF3D /* Target.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Target.hpp; sourceTree = ""; }; 4BC1316F2346DE5000E4FF3D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticAnalyser.cpp; sourceTree = ""; }; @@ -3514,7 +3514,7 @@ 4BC0CB312447EC7C00A79DBB /* Operator.hpp */, 4BC0CB352447EC9A00A79DBB /* Channel.cpp */, 4BC0CB362447EC9A00A79DBB /* Channel.hpp */, - 4BC0CB3A2447ECAE00A79DBB /* Tables.h */, + 4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */, ); path = Implementation; sourceTree = "";