From 2bc36a6cde5b27e5bba8feec56a5157c4073c255 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 26 Apr 2020 00:21:15 -0400 Subject: [PATCH] Eliminates branch within snare output. --- Components/OPL2/Implementation/Operator.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Components/OPL2/Implementation/Operator.cpp b/Components/OPL2/Implementation/Operator.cpp index 376c153c1..c72a2ff17 100644 --- a/Components/OPL2/Implementation/Operator.cpp +++ b/Components/OPL2/Implementation/Operator.cpp @@ -274,13 +274,17 @@ LogSign Operator::snare_output(OperatorState &state) { // constexpr int masks[] = {~0, 0}; // result += masks[state.lfsr_ - if((state.raw_phase_ >> 11) & 0x200) { - // Result is -max if LFSR is 0, otherwise -0. - result = negative_log_sin(1024 + ((state.lfsr_^1) << 8)); - } else { - // Result is +max if LFSR is 1, otherwise +0. - result = negative_log_sin(state.lfsr_ << 8); - } + const int sign = (state.raw_phase_ >> 11) & 0x200; + const int level = ((state.raw_phase_ >> 20) & 1) ^ state.lfsr_; + result = negative_log_sin(sign + (level << 8)); + +// if((state.raw_phase_ >> 11) & 0x200) { +// // Result is -max if LFSR is 0, otherwise -0. +// result = negative_log_sin(512 + ((state.lfsr_^1) << 8)); +// } else { +// // Result is +max if LFSR is 1, otherwise +0. +// result = negative_log_sin(state.lfsr_ << 8); +// } // printf("%d %d: %d/%d\n", state.lfsr_, (state.raw_phase_ >> 11) & 1023, result.log, result.sign);