From a0ace860f4c7feee08607e52bc8f0b48df09dcd5 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Mon, 7 Jan 2019 01:27:58 +0100 Subject: [PATCH] MSVC: Fix SID (#4505) Use the provided working buffer instead of a local one to avoid use of VLA --- plugins/CMakeLists.txt | 2 -- plugins/sid/sid_instrument.cpp | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index b4a1081f6..4f139f8b3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -91,8 +91,6 @@ ENDIF("${PLUGIN_LIST}" STREQUAL "") IF(MSVC) SET(MSVC_INCOMPATIBLE_PLUGINS LadspaEffect - sid - #VstEffect zynaddsubfx ) message(WARNING "Compiling with MSVC. The following plugins are not available: ${MSVC_INCOMPATIBLE_PLUGINS}") diff --git a/plugins/sid/sid_instrument.cpp b/plugins/sid/sid_instrument.cpp index 2eb46be56..e671d4f05 100644 --- a/plugins/sid/sid_instrument.cpp +++ b/plugins/sid/sid_instrument.cpp @@ -324,7 +324,8 @@ void sidInstrument::playNote( NotePlayHandle * _n, cSID *sid = static_cast( _n->m_pluginData ); int delta_t = clockrate * frames / samplerate + 4; - short buf[frames]; + // avoid variable length array for msvc compat + short* buf = reinterpret_cast(_working_buffer + offset); unsigned char sidreg[NUMSIDREGS]; for (int c = 0; c < NUMSIDREGS; c++) @@ -429,7 +430,8 @@ void sidInstrument::playNote( NotePlayHandle * _n, if(num!=frames) printf("!!!Not enough samples\n"); - for( fpp_t frame = 0; frame < frames; ++frame ) + // loop backwards to avoid overwriting data in the short-to-float conversion + for( fpp_t frame = frames - 1; frame >= 0; frame-- ) { sample_t s = float(buf[frame])/32768.0; for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )