From cd2ab70a58df83578f10a323b06be2e36e1cee28 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 25 Apr 2020 22:21:42 -0400 Subject: [PATCH] Moves the LFSR to the LowFrequencyOscillator. Possibly I should come up with a better name for that? --- .../Implementation/LowFrequencyOscillator.cpp | 4 ++++ .../Implementation/LowFrequencyOscillator.hpp | 16 +++++++++++++++- Components/OPL2/OPL2.cpp | 1 + Components/OPL2/OPL2.hpp | 4 ---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Components/OPL2/Implementation/LowFrequencyOscillator.cpp b/Components/OPL2/Implementation/LowFrequencyOscillator.cpp index 930904b0d..142f3efb0 100644 --- a/Components/OPL2/Implementation/LowFrequencyOscillator.cpp +++ b/Components/OPL2/Implementation/LowFrequencyOscillator.cpp @@ -26,3 +26,7 @@ void LowFrequencyOscillator::update() { // Vibrato is relatively simple: it's just three bits from the counter. vibrato = (counter >> 10) & 7; } + +void LowFrequencyOscillator::update_lfsr() { + lfsr = noise_source_.next(); +} diff --git a/Components/OPL2/Implementation/LowFrequencyOscillator.hpp b/Components/OPL2/Implementation/LowFrequencyOscillator.hpp index d3c71669c..96fa4265d 100644 --- a/Components/OPL2/Implementation/LowFrequencyOscillator.hpp +++ b/Components/OPL2/Implementation/LowFrequencyOscillator.hpp @@ -9,6 +9,8 @@ #ifndef LowFrequencyOscillator_hpp #define LowFrequencyOscillator_hpp +#include "../../../Numeric/LFSR.hpp" + namespace Yamaha { namespace OPL { @@ -21,14 +23,26 @@ class LowFrequencyOscillator { public: /// Current attenuation due to tremolo / amplitude modulation, between 0 and 26. int tremolo = 0; + /// A number between 0 and 7 indicating the current vibrato offset; this should be combined by operators /// with their frequency number to get the actual vibrato. int vibrato = 0; + /// A counter of the number of operator update cycles (i.e. input clock / 72) since an arbitrary time. int counter = 0; - /// Updates the oscillator outputs + /// Describes the current output of the LFSR; will be either 0 or 1. + int lfsr = 0; + + /// Updates the oscillator outputs. Should be called at the (input clock/72) rate. void update(); + + /// Updartes the LFSR output. Should be called at the input clock rate. + void update_lfsr(); + + private: + // This is the correct LSFR per forums.submarine.org.uk. + Numeric::LFSR noise_source_; }; } diff --git a/Components/OPL2/OPL2.cpp b/Components/OPL2/OPL2.cpp index aa376215f..e4be97f71 100644 --- a/Components/OPL2/OPL2.cpp +++ b/Components/OPL2/OPL2.cpp @@ -68,6 +68,7 @@ void OPLL::get_samples(std::size_t number_of_samples, std::int16_t *target) { while(number_of_samples--) { if(!audio_offset_) update_all_chanels(); + if(!(audio_offset_&3)) oscillator_.update_lfsr(); *target = int16_t(output_levels_[audio_offset_ / channel_output_period]); ++target; diff --git a/Components/OPL2/OPL2.hpp b/Components/OPL2/OPL2.hpp index 14a8420e5..b313f2472 100644 --- a/Components/OPL2/OPL2.hpp +++ b/Components/OPL2/OPL2.hpp @@ -11,7 +11,6 @@ #include "../../Outputs/Speaker/Implementation/SampleSource.hpp" #include "../../Concurrency/AsyncTaskQueue.hpp" -#include "../../Numeric/LFSR.hpp" #include "Implementation/Channel.hpp" #include "Implementation/Operator.hpp" @@ -60,9 +59,6 @@ struct OPL2: public OPLBase { Operator operators_[18]; Channel channels_[9]; - // This is the correct LSFR per forums.submarine.org.uk. - Numeric::LFSR noise_source_; - // Synchronous properties, valid only on the emulation thread. uint8_t timers_[2] = {0, 0}; uint8_t timer_control_ = 0;