From 0505b82384f360c519bec8441e2964555ba7540f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 5 May 2020 00:28:24 -0400 Subject: [PATCH] Restores top bit of channel period, propagates it to the envelope generator. --- Components/OPL2/OPLL.cpp | 8 ++++++-- OSBindings/Mac/Clock SignalTests/OPLTests.mm | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Components/OPL2/OPLL.cpp b/Components/OPL2/OPLL.cpp index c4f66e141..a644e6702 100644 --- a/Components/OPL2/OPLL.cpp +++ b/Components/OPL2/OPLL.cpp @@ -79,7 +79,7 @@ void OPLL::write_register(uint8_t address, uint8_t value) { // Address 2x Sets the octave and a single bit of the frequency, as well // as setting key on and sustain mode. case 0x20: - channels_[index].period = (channels_[index].period & 0xff) | (value & 1); + channels_[index].period = (channels_[index].period & 0xff) | ((value & 1) << 8); channels_[index].octave = (value >> 1) & 7; set_channel_period(index); @@ -116,6 +116,9 @@ void OPLL::set_channel_period(int channel) { phase_generators_[channel + 0].set_period(channels_[channel].period, channels_[channel].octave); phase_generators_[channel + 9].set_period(channels_[channel].period, channels_[channel].octave); + envelope_generators_[channel + 0].set_period(channels_[channel].period, channels_[channel].octave); + envelope_generators_[channel + 9].set_period(channels_[channel].period, channels_[channel].octave); + key_level_scalers_[channel + 0].set_period(channels_[channel].period, channels_[channel].octave); key_level_scalers_[channel + 9].set_period(channels_[channel].period, channels_[channel].octave); } @@ -278,8 +281,9 @@ void OPLL::update_all_channels() { int OPLL::melodic_output(int channel) { + // TODO: key-rate scaling. auto modulation = WaveformGenerator::wave(channels_[channel].modulator_waveform, phase_generators_[channel + 9].phase()); modulation += envelope_generators_[channel + 9].attenuation() + channels_[channel].modulator_attenuation; - return WaveformGenerator::wave(channels_[channel].carrier_waveform, phase_generators_[channel].scaled_phase(), modulation).level(); + return WaveformGenerator::wave(channels_[channel].carrier_waveform, phase_generators_[channel].scaled_phase(), modulation).level() + channels_[channel].attenuation; } diff --git a/OSBindings/Mac/Clock SignalTests/OPLTests.mm b/OSBindings/Mac/Clock SignalTests/OPLTests.mm index 995ff8915..6691ad860 100644 --- a/OSBindings/Mac/Clock SignalTests/OPLTests.mm +++ b/OSBindings/Mac/Clock SignalTests/OPLTests.mm @@ -8,7 +8,8 @@ #import -#include "OPL2.hpp" +#include "Tables.hpp" + #include @interface OPLTests: XCTestCase @@ -32,7 +33,7 @@ // MARK: - Two-operator FM tests -- (void)compareFMTo:(NSArray *)knownGood atAttenuation:(int)attenuation { +/*- (void)compareFMTo:(NSArray *)knownGood atAttenuation:(int)attenuation { Yamaha::OPL::Operator modulator, carrier; Yamaha::OPL::Channel channel; Yamaha::OPL::LowFrequencyOscillator oscillator; @@ -165,6 +166,6 @@ // test_operator.update(test_state, true, 0, 0, 0); // NSLog(@"%d", test_state.level()); // } -} +}*/ @end