From 94614ae4c363c76b1cbfd0a825af42fdc248aa5d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 3 May 2020 21:44:22 -0400 Subject: [PATCH] Shifts the LFO implementation inline. --- .../Implementation/LowFrequencyOscillator.cpp | 32 ------------------- .../Implementation/LowFrequencyOscillator.hpp | 21 ++++++++++-- .../Clock Signal.xcodeproj/project.pbxproj | 6 ---- 3 files changed, 19 insertions(+), 40 deletions(-) delete mode 100644 Components/OPL2/Implementation/LowFrequencyOscillator.cpp diff --git a/Components/OPL2/Implementation/LowFrequencyOscillator.cpp b/Components/OPL2/Implementation/LowFrequencyOscillator.cpp deleted file mode 100644 index 142f3efb0..000000000 --- a/Components/OPL2/Implementation/LowFrequencyOscillator.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// -// LowFrequencyOscillator.cpp -// Clock Signal -// -// Created by Thomas Harte on 23/04/2020. -// Copyright © 2020 Thomas Harte. All rights reserved. -// - -#include "LowFrequencyOscillator.hpp" - -using namespace Yamaha::OPL; - -void LowFrequencyOscillator::update() { - ++counter; - - // This produces output of: - // - // four instances of 0, four instances of 1... _three_ instances of 26, - // four instances of 25, four instances of 24... _three_ instances of 0. - // - // ... advancing once every 64th update. - const int tremolo_index = (counter >> 6) % 210; - const int tremolo_levels[2] = {tremolo_index >> 2, 52 - ((tremolo_index+1) >> 2)}; - tremolo = tremolo_levels[tremolo_index / 107]; - - // 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 96fa4265d..a3d852e67 100644 --- a/Components/OPL2/Implementation/LowFrequencyOscillator.hpp +++ b/Components/OPL2/Implementation/LowFrequencyOscillator.hpp @@ -35,10 +35,27 @@ class LowFrequencyOscillator { int lfsr = 0; /// Updates the oscillator outputs. Should be called at the (input clock/72) rate. - void update(); + void update() { + ++counter; + + // This produces output of: + // + // four instances of 0, four instances of 1... _three_ instances of 26, + // four instances of 25, four instances of 24... _three_ instances of 0. + // + // ... advancing once every 64th update. + const int tremolo_index = (counter >> 6) % 210; + const int tremolo_levels[2] = {tremolo_index >> 2, 52 - ((tremolo_index+1) >> 2)}; + tremolo = tremolo_levels[tremolo_index / 107]; + + // Vibrato is relatively simple: it's just three bits from the counter. + vibrato = (counter >> 10) & 7; + } /// Updartes the LFSR output. Should be called at the input clock rate. - void update_lfsr(); + void update_lfsr() { + lfsr = noise_source_.next(); + } private: // This is the correct LSFR per forums.submarine.org.uk. diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index f3a4930c6..a63d45e50 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -222,8 +222,6 @@ 4B595FAE2086DFBA0083CAA8 /* AudioToggle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B595FAC2086DFBA0083CAA8 /* AudioToggle.cpp */; }; 4B5FADBA1DE3151600AEC565 /* FileHolder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B5FADB81DE3151600AEC565 /* FileHolder.cpp */; }; 4B5FADC01DE3BF2B00AEC565 /* Microdisc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B5FADBE1DE3BF2B00AEC565 /* Microdisc.cpp */; }; - 4B61909024526E640013F202 /* LowFrequencyOscillator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B61908E24526E640013F202 /* LowFrequencyOscillator.cpp */; }; - 4B61909124526E640013F202 /* LowFrequencyOscillator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B61908E24526E640013F202 /* LowFrequencyOscillator.cpp */; }; 4B622AE5222E0AD5008B59F2 /* DisplayMetrics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B622AE3222E0AD5008B59F2 /* DisplayMetrics.cpp */; }; 4B643F3A1D77AD1900D431D6 /* CSStaticAnalyser.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B643F391D77AD1900D431D6 /* CSStaticAnalyser.mm */; }; 4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B643F3E1D77B88000D431D6 /* DocumentController.swift */; }; @@ -1149,7 +1147,6 @@ 4B5FADB91DE3151600AEC565 /* FileHolder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FileHolder.hpp; sourceTree = ""; }; 4B5FADBE1DE3BF2B00AEC565 /* Microdisc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Microdisc.cpp; path = Oric/Microdisc.cpp; sourceTree = ""; }; 4B5FADBF1DE3BF2B00AEC565 /* Microdisc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Microdisc.hpp; path = Oric/Microdisc.hpp; sourceTree = ""; }; - 4B61908E24526E640013F202 /* LowFrequencyOscillator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LowFrequencyOscillator.cpp; sourceTree = ""; }; 4B61908F24526E640013F202 /* LowFrequencyOscillator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = LowFrequencyOscillator.hpp; sourceTree = ""; }; 4B619092245BC1000013F202 /* PhaseGenerator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = PhaseGenerator.hpp; sourceTree = ""; }; 4B619093245CD63E0013F202 /* EnvelopeGenerator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = EnvelopeGenerator.hpp; sourceTree = ""; }; @@ -3534,7 +3531,6 @@ 4BC0CB352447EC9A00A79DBB /* Channel.cpp */, 4BC0CB362447EC9A00A79DBB /* Channel.hpp */, 4BC0CB3A2447ECAE00A79DBB /* Tables.hpp */, - 4B61908E24526E640013F202 /* LowFrequencyOscillator.cpp */, 4B61908F24526E640013F202 /* LowFrequencyOscillator.hpp */, 4B619092245BC1000013F202 /* PhaseGenerator.hpp */, 4B619093245CD63E0013F202 /* EnvelopeGenerator.hpp */, @@ -4437,7 +4433,6 @@ 4B055AB01FAE86070060FFFF /* PulseQueuedTape.cpp in Sources */, 4B055AAC1FAE85FD0060FFFF /* PCMSegment.cpp in Sources */, 4BB307BC235001C300457D33 /* 6850.cpp in Sources */, - 4B61909124526E640013F202 /* LowFrequencyOscillator.cpp in Sources */, 4B055AB31FAE860F0060FFFF /* CSW.cpp in Sources */, 4B89451D201967B4007DE474 /* Disk.cpp in Sources */, 4BDACBED22FFA5D20045EF7E /* ncr5380.cpp in Sources */, @@ -4758,7 +4753,6 @@ 4B1B88C0202E3DB200B67DFF /* MultiConfigurable.cpp in Sources */, 4BFF1D3922337B0300838EA1 /* 68000Storage.cpp in Sources */, 4B54C0BC1F8D8E790050900F /* KeyboardMachine.cpp in Sources */, - 4B61909024526E640013F202 /* LowFrequencyOscillator.cpp in Sources */, 4BB244D522AABAF600BE20E5 /* z8530.cpp in Sources */, 4BB73EA21B587A5100552FC2 /* AppDelegate.swift in Sources */, 4B894534201967B4007DE474 /* AddressMapper.cpp in Sources */,