From e12dc5d89445c9c6ae4d9d5d5bd7151fc899d539 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 6 May 2020 00:15:28 -0400 Subject: [PATCH] Reduce the amount of time spent installing instruments. --- Components/OPL2/OPLL.cpp | 14 +++++++++++--- Components/OPL2/OPLL.hpp | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Components/OPL2/OPLL.cpp b/Components/OPL2/OPLL.cpp index f2e1dcf13..737284c44 100644 --- a/Components/OPL2/OPLL.cpp +++ b/Components/OPL2/OPLL.cpp @@ -27,6 +27,11 @@ OPLL::OPLL(Concurrency::DeferringAsyncTaskQueue &task_queue, int audio_divider, phase_generators_[c + 9].reset(); }); } + + // Set default instrument. + for(int c = 0; c < 9; ++c) { + install_instrument(c); + } } // MARK: - Machine-facing programmatic input. @@ -112,11 +117,14 @@ void OPLL::write_register(uint8_t address, uint8_t value) { // instead nominate additional attenuations. This code reads those back // from the stored instrument values. case 0x30: - channels_[index].instrument = value >> 4; channels_[index].attenuation = value & 0xf; - if(index < 6 || !rhythm_mode_enabled_) { - install_instrument(index); + // Install an instrument only if it's new. + if(channels_[index].instrument != value >> 4) { + channels_[index].instrument = value >> 4; + if(index < 6 || !rhythm_mode_enabled_) { + install_instrument(index); + } } return; } diff --git a/Components/OPL2/OPLL.hpp b/Components/OPL2/OPLL.hpp index 7d7b409de..91beabc2e 100644 --- a/Components/OPL2/OPLL.hpp +++ b/Components/OPL2/OPLL.hpp @@ -83,7 +83,7 @@ class OPLL: public OPLBase { bool is_vrc7_ = false; // Contains the current configuration of the custom instrument. - uint8_t custom_instrument_[8]; + uint8_t custom_instrument_[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // Helpers to push per-channel information.