diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/core/util.hpp b/extern/vgsound_emu-modified/vgsound_emu/src/core/util.hpp index 5df967f66..b85548be2 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/core/util.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/core/util.hpp @@ -19,6 +19,10 @@ #include #include +#define VGS_MIN(a,b) (((a)<(b))?(a):(b)) +#define VGS_MAX(a,b) (((a)>(b))?(a):(b)) +#define VGS_CLAMP(x,xMin,xMax) (VGS_MIN(VGS_MAX((x),(xMin)),(xMax))) + namespace vgsound_emu { typedef unsigned char u8; @@ -43,7 +47,7 @@ namespace vgsound_emu return std::clamp(in, min, max); #else // otherwise, use my own implementation of std::clamp - return std::min(std::max(in, min), max); + return VGS_CLAMP(in,min,max); #endif } @@ -58,7 +62,7 @@ namespace vgsound_emu template static inline T sign_ext(T in, u8 len) { - len = std::max(0, (8 * sizeof(T)) - len); + len = VGS_MAX(0, (8 * sizeof(T)) - len); return T(T(in) << len) >> len; } diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp index f511f31ee..aff50543a 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp @@ -195,12 +195,18 @@ void es5506_core::tick_perf() // output if (((!m_mode.lrclk_en()) && (!m_mode.bclk_en()) && (!m_mode.wclk_en())) && (m_w_st < m_w_end)) { - const int output_bits = 20 - (m_w_end - m_w_st); + const int output_bits = (20 - (m_w_end - m_w_st)) * 2; if (output_bits < 20) { for (int c = 0; c < 6; c++) { - m_output[c].clamp20(m_ch[c] >> output_bits); + m_output[c].m_left=m_ch[c].m_left>>output_bits; + if (m_output[c].m_left<-0x80000) m_output[c].m_left=-0x80000; + if (m_output[c].m_left>0x7ffff) m_output[c].m_left=0x7ffff; + + m_output[c].m_right=m_ch[c].m_right>>output_bits; + if (m_output[c].m_right<-0x80000) m_output[c].m_right=-0x80000; + if (m_output[c].m_right>0x7ffff) m_output[c].m_right=0x7ffff; } } } @@ -240,7 +246,7 @@ void es5506_core::voice_tick() m_voice[m_voice_cycle].tick(m_voice_cycle); // Refresh output - if ((++m_voice_cycle) > clamp(m_active, 4, 31)) // 5 ~ 32 voices + if ((++m_voice_cycle) > VGS_CLAMP(m_active, 4, 31)) // 5 ~ 32 voices { m_voice_end = true; m_voice_cycle = 0; @@ -251,7 +257,7 @@ void es5506_core::voice_tick() for (voice_t &elem : m_voice) { - const u8 ca = bitfield(elem.cr().ca(), 0, 3); + const u8 ca = elem.cr().ca()&7; if (ca < 6) { m_ch[ca] += elem.ch(); @@ -271,10 +277,10 @@ void es5506_core::voice_t::fetch(u8 voice, u8 cycle) cycle, m_host.m_intf.read_sample(voice, m_cr.bs(), - bitfield(m_alu.get_accum_integer() + cycle, 0, m_alu.m_integer))); + (m_alu.get_accum_integer() + cycle)&((1<>8)&255)); } } @@ -307,11 +313,11 @@ void es5506_core::voice_t::tick(u8 voice) // Left and Right volume if (bitfield(m_lvramp, 0, 8) != 0) { - m_lvol = clamp(m_lvol + sign_ext(bitfield(m_lvramp, 0, 8), 8), 0, 0xffff); + m_lvol = VGS_CLAMP(m_lvol + sign_ext(bitfield(m_lvramp, 0, 8), 8), 0, 0xffff); } if (bitfield(m_rvramp, 0, 8) != 0) { - m_rvol = clamp(m_rvol + sign_ext(bitfield(m_rvramp, 0, 8), 8), 0, 0xffff); + m_rvol = VGS_CLAMP(m_rvol + sign_ext(bitfield(m_rvramp, 0, 8), 8), 0, 0xffff); } // Filter coeffcient @@ -319,13 +325,13 @@ void es5506_core::voice_t::tick(u8 voice) ((m_k1ramp.slow() == 0) || (bitfield(m_filtcount, 0, 3) == 0))) { m_filter.set_k1( - clamp(m_filter.k1() + sign_ext(m_k1ramp.ramp(), 8), 0, 0xffff)); + VGS_CLAMP(m_filter.k1() + sign_ext(m_k1ramp.ramp(), 8), 0, 0xffff)); } if ((m_k2ramp.ramp() != 0) && ((m_k2ramp.slow() == 0) || (bitfield(m_filtcount, 0, 3) == 0))) { m_filter.set_k2( - clamp(m_filter.k2() + sign_ext(m_k2ramp.ramp(), 8), 0, 0xffff)); + VGS_CLAMP(m_filter.k2() + sign_ext(m_k2ramp.ramp(), 8), 0, 0xffff)); } m_ecount--; diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp index e2b793cd5..841dcddf2 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp @@ -39,7 +39,7 @@ class es5506_core : public es550x_shared_core m_right = src.right(); } - inline s32 clamp20(s32 in) { return clamp(in, -0x80000, 0x7ffff); } + inline s32 clamp20(s32 in) { return VGS_CLAMP(in, -0x80000, 0x7ffff); } inline void clamp20(output_t &src) { @@ -89,7 +89,7 @@ class es5506_core : public es550x_shared_core return *this; } - private: + public: // oh my... s32 m_left = 0; s32 m_right = 0; };