1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-02 20:30:00 +00:00

Moves the LFSR to the LowFrequencyOscillator.

Possibly I should come up with a better name for that?
This commit is contained in:
Thomas Harte 2020-04-25 22:21:42 -04:00
parent a5d1941d28
commit cd2ab70a58
4 changed files with 20 additions and 5 deletions

View File

@ -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();
}

View File

@ -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<int, 0x800302> noise_source_;
};
}

View File

@ -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;

View File

@ -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<OPL2> {
Operator operators_[18];
Channel channels_[9];
// This is the correct LSFR per forums.submarine.org.uk.
Numeric::LFSR<uint32_t, 0x800302> noise_source_;
// Synchronous properties, valid only on the emulation thread.
uint8_t timers_[2] = {0, 0};
uint8_t timer_control_ = 0;