From 020c76097654062ecbb62e35d0ccd1edf853d4b7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Apr 2020 00:30:14 -0400 Subject: [PATCH] Simplifies the phase counter. --- Components/OPL2/Implementation/Operator.cpp | 12 +++--------- Components/OPL2/Implementation/Operator.hpp | 1 - Components/OPL2/OPL2.cpp | 2 ++ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Components/OPL2/Implementation/Operator.cpp b/Components/OPL2/Implementation/Operator.cpp index ab8791de4..ae9d66977 100644 --- a/Components/OPL2/Implementation/Operator.cpp +++ b/Components/OPL2/Implementation/Operator.cpp @@ -64,14 +64,7 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int }; // Update the raw phase. - // TODO: if this is the real formula (i.e. a downward shift for channel_octave), this is a highly - // suboptimal way to do this. Could just keep one accumulator and shift that downward for the result. - const int octave_divider = 4096 >> channel_octave; - state.divider_ %= octave_divider; - state.divider_ += channel_period; - state.raw_phase_ += multipliers[frequency_multiple_] * (state.divider_ / octave_divider); - // TODO: this last step introduces aliasing, but is a quick way to verify whether the multiplier should - // be applied also to the octave. + state.raw_phase_ += multipliers[frequency_multiple_] * channel_period << channel_octave; // Hence calculate phase (TODO: by also taking account of vibrato). constexpr int waveforms[4][4] = { @@ -80,7 +73,8 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int {511, 511, 511, 511}, // AbsSine: endlessly repeat the first half of the sine wave. {255, 0, 255, 0}, // PulseSine: act as if the first quadrant is in the first and third; lock the other two to 0. }; - state.phase = state.raw_phase_ & waveforms[int(waveform_)][(state.raw_phase_ >> 8) & 3]; + const int phase = state.raw_phase_ >> 11; + state.phase = phase & waveforms[int(waveform_)][(phase >> 8) & 3]; // Key-on logic: any time it is false, be in the release state. // On the leading edge of it becoming true, enter the attack state. diff --git a/Components/OPL2/Implementation/Operator.hpp b/Components/OPL2/Implementation/Operator.hpp index 567b738c1..23c36c868 100644 --- a/Components/OPL2/Implementation/Operator.hpp +++ b/Components/OPL2/Implementation/Operator.hpp @@ -23,7 +23,6 @@ struct OperatorState { int attenuation = 1023; // Will be in the range [0, 1023]. private: - int divider_ = 0; int raw_phase_ = 0; enum class ADSRPhase { diff --git a/Components/OPL2/OPL2.cpp b/Components/OPL2/OPL2.cpp index 207f2ed04..eb5049dae 100644 --- a/Components/OPL2/OPL2.cpp +++ b/Components/OPL2/OPL2.cpp @@ -195,6 +195,8 @@ void OPLL::update_all_chanels() { channels_[c].level = (channels_[c].update() * total_volume_) >> 14; } } + +// channels_[2].level = (channels_[2].update() * total_volume_) >> 14; } /*