From d1824927f57b9ee29d9178260ec31e66539b18e4 Mon Sep 17 00:00:00 2001 From: bsutherland Date: Sat, 14 May 2016 13:37:38 +0900 Subject: [PATCH] Fix noise issue in Reaper (and possibly other VST hosts) caused by calls with buffer lengths > 512 bytes. --- Source/dbopl.cpp | 2 ++ Source/hiopl.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/dbopl.cpp b/Source/dbopl.cpp index 7deaead..23ba54d 100644 --- a/Source/dbopl.cpp +++ b/Source/dbopl.cpp @@ -1498,6 +1498,8 @@ void Handler::WriteReg( Bit32u addr, Bit8u val ) { } void Handler::Generate( Bitu samples, Bit32s* buffer ) { + // Not sure why this is here, possibly limited length of LUT etc? + // Limiting calls to 512 bytes at a time in HiOPL. if ( GCC_UNLIKELY(samples > 512) ) samples = 512; if ( !chip.opl3Active ) { diff --git a/Source/hiopl.cpp b/Source/hiopl.cpp index 3affaa8..9be4c5e 100644 --- a/Source/hiopl.cpp +++ b/Source/hiopl.cpp @@ -50,7 +50,15 @@ void Hiopl::SetEmulator(Emulator emulator) { void Hiopl::Generate(int length, float* buffer) { intermediateBufIdx = (intermediateBufIdx + 1) % INTERMEDIATE_BUF_N; Bit32s *iBuf = intermediateBuf[intermediateBufIdx]; - adlib->Generate(length, iBuf); + int fullCalls = length / 512; // the emulator is limited to 512 bytes per call + int c = 0; + for (; c < fullCalls; c++) { + adlib->Generate(512, iBuf + (c * 512)); + } + // final (or only) call + if (length % 512 > 0) { + adlib->Generate(length % 512, iBuf + (c * 512)); + } for (int i = 0; i < length; i++) { // Magic divisor taken from ZDoom wrapper for DOSBox emulator, line 892 // https://github.com/rheit/zdoom/blob/master/src/oplsynth/dosbox/opl.cpp