From c0190b81cb599858ce4bb84bd9609a0914bf1605 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 11 Feb 2023 04:21:15 -0500 Subject: [PATCH] ES5506: optimize more --- .../vgsound_emu/src/es550x/es5504.cpp | 12 +++--- .../vgsound_emu/src/es550x/es5504.hpp | 2 +- .../vgsound_emu/src/es550x/es5505.cpp | 14 +++---- .../vgsound_emu/src/es550x/es5505.hpp | 2 +- .../vgsound_emu/src/es550x/es5506.cpp | 39 +++++++++++-------- .../vgsound_emu/src/es550x/es5506.hpp | 2 +- .../vgsound_emu/src/es550x/es550x.hpp | 6 +-- .../vgsound_emu/src/es550x/es550x_alu.cpp | 4 +- src/engine/platform/es5506.h | 2 +- 9 files changed, 45 insertions(+), 38 deletions(-) diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.cpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.cpp index 0e10a9e6..bdff401e 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.cpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.cpp @@ -23,7 +23,7 @@ void es5504_core::tick() // /CAS low, E low: fetch sample if (!m_e.current_edge()) { - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } } } @@ -41,7 +41,7 @@ void es5504_core::tick() if (m_e.falling_edge()) // Voice memory { m_host_intf.clear_host_access(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } } if (m_e.current_edge()) // Host interface @@ -81,7 +81,7 @@ void es5504_core::tick_perf() m_intf.e_pin(false); m_host_intf.clear_host_access(); m_host_intf.clear_strobe(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); voice_tick(); // rising edge m_e.edge().set(true); @@ -92,7 +92,7 @@ void es5504_core::tick_perf() m_intf.e_pin(false); m_host_intf.clear_host_access(); m_host_intf.clear_strobe(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); voice_tick(); // rising edge m_e.edge().set(true); @@ -126,11 +126,11 @@ void es5504_core::voice_tick() } } -void es5504_core::voice_t::fetch(u8 voice, u8 cycle) +void es5504_core::voice_t::fetch(u8 cycle) { m_alu.set_sample( cycle, - m_host.m_intf.read_sample(voice, + m_host.m_intf.read_sample( bitfield(m_cr.ca(), 0, 3), bitfield(m_alu.get_accum_integer() + cycle, 0, m_alu.m_integer))); } diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.hpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.hpp index b30bc3a9..8f5fc47c 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5504.hpp @@ -32,7 +32,7 @@ class es5504_core : public es550x_shared_core // internal state virtual void reset() override; - virtual void fetch(u8 voice, u8 cycle) override; + virtual void fetch(u8 cycle) override; virtual void tick(u8 voice) override; // setters diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.cpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.cpp index 67afd69c..c07280ef 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.cpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.cpp @@ -97,7 +97,7 @@ void es5505_core::tick() // /CAS low, E low: fetch sample if (!m_e.current_edge()) { - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } } } @@ -113,7 +113,7 @@ void es5505_core::tick() else if (m_e.falling_edge()) // Voice memory { m_host_intf.clear_host_access(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } if (m_e.current_edge()) // Host interface { @@ -159,7 +159,7 @@ void es5505_core::tick_perf() m_intf.e_pin(false); m_host_intf.clear_host_access(); m_host_intf.clear_strobe(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); voice_tick(); // rising edge m_e.edge().set(true); @@ -170,7 +170,7 @@ void es5505_core::tick_perf() m_intf.e_pin(false); m_host_intf.clear_host_access(); m_host_intf.clear_strobe(); - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); voice_tick(); // rising edge m_e.edge().set(true); @@ -211,12 +211,12 @@ void es5505_core::voice_tick() } } -void es5505_core::voice_t::fetch(u8 voice, u8 cycle) +void es5505_core::voice_t::fetch(u8 cycle) { m_alu.set_sample( cycle, - m_host.m_intf.read_sample(voice, - bitfield(m_cr.bs(), 0), + m_host.m_intf.read_sample( + bitfield(m_cr.m_bs, 0), bitfield(m_alu.get_accum_integer() + cycle, 0, m_alu.m_integer))); } diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.hpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.hpp index ebe61b72..b7370631 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5505.hpp @@ -112,7 +112,7 @@ class es5505_core : public es550x_shared_core // internal state virtual void reset() override; - virtual void fetch(u8 voice, u8 cycle) override; + virtual void fetch(u8 cycle) override; virtual void tick(u8 voice) override; // setters 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 aff50543..6acd2ac5 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.cpp @@ -134,7 +134,7 @@ void es5506_core::tick() // sample if (m_mode.master()) { - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } } else if (m_e.current_edge()) @@ -142,7 +142,7 @@ void es5506_core::tick() // dual OTTO slave mode, /CAS low, E high: fetch sample if (m_mode.dual() && (!m_mode.master())) { // Dual OTTO, slave mode - m_voice[m_voice_cycle].fetch(m_voice_cycle, m_voice_fetch); + m_voice[m_voice_cycle].fetch(m_voice_fetch); } } } @@ -228,8 +228,7 @@ void es5506_core::tick_perf() m_host_intf.clear_host_access(); m_host_intf.clear_strobe(); } - m_voice[m_voice_cycle].fetch(m_voice_cycle, 0); - m_voice[m_voice_cycle].fetch(m_voice_cycle, 1); + m_voice[m_voice_cycle].fetch(0); voice_tick(); if (bounce) { // rising edge @@ -250,19 +249,19 @@ void es5506_core::voice_tick() { m_voice_end = true; m_voice_cycle = 0; - for (output_t &elem : m_ch) + for (int i=0; i<6; i++) { - elem.reset(); + m_ch[i].reset(); } - for (voice_t &elem : m_voice) + for (int i=0; i<32; i++) { - const u8 ca = elem.cr().ca()&7; + const u8 ca = m_voice[i].cr().ca()&7; if (ca < 6) { - m_ch[ca] += elem.ch(); + m_ch[ca] += m_voice[i].ch(); } - elem.ch().reset(); + m_voice[i].ch().reset(); } } else @@ -271,16 +270,24 @@ void es5506_core::voice_tick() } } -void es5506_core::voice_t::fetch(u8 voice, u8 cycle) +void es5506_core::voice_t::fetch(u8 cycle) { m_alu.set_sample( - cycle, - m_host.m_intf.read_sample(voice, - m_cr.bs(), - (m_alu.get_accum_integer() + cycle)&((1<>8)&255)); + m_alu.set_sample(0, decompress((m_alu.sample(0)>>8)&255)); + } + + m_alu.set_sample( + 1, + m_host.m_intf.read_sample(m_cr.m_bs, + (m_alu.get_accum_integer() + 1)&((1<>8)&255)); } } 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 841dcddf..df441816 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es5506.hpp @@ -152,7 +152,7 @@ class es5506_core : public es550x_shared_core // internal state virtual void reset() override; - virtual void fetch(u8 voice, u8 cycle) override; + virtual void fetch(u8 cycle) override; virtual void tick(u8 voice) override; // Setters diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x.hpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x.hpp index 181b8dce..16836da9 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x.hpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x.hpp @@ -41,7 +41,7 @@ class es550x_intf : public vgsound_emu_core virtual void adc_w(u16 data) {} // ADC output - virtual s16 read_sample(u8 voice, u8 bank, u32 address) { return 0; } + virtual s16 read_sample(u8 bank, u32 address) { return 0; } }; // Shared functions for ES5504/ES5505/ES5506 @@ -137,7 +137,7 @@ class es550x_shared_core : public vgsound_emu_core inline bool cmpd() { return m_cmpd; } - protected: + public: // Channel assign - // 4 bit (16 channel or Bank) for ES5504 // 2 bit (4 stereo channels) for ES5505 @@ -456,7 +456,7 @@ class es550x_shared_core : public vgsound_emu_core // internal state virtual void reset(); - virtual void fetch(u8 voice, u8 cycle) = 0; + virtual void fetch(u8 cycle) = 0; virtual void tick(u8 voice) = 0; void irq_update(es550x_intf &intf, es550x_irq_t &irqv) diff --git a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x_alu.cpp b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x_alu.cpp index 2118266f..6e72238d 100644 --- a/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x_alu.cpp +++ b/extern/vgsound_emu-modified/vgsound_emu/src/es550x/es550x_alu.cpp @@ -101,14 +101,14 @@ void es550x_shared_core::es550x_voice_t::es550x_alu_t::loop_exec() s32 es550x_shared_core::es550x_voice_t::es550x_alu_t::interpolation() { // SF = S1 + ACCfr * (S2 - S1) - return m_sample[0] + ((bitfield(m_accum, m_fraction_m9, 9) * + return m_sample[0] + (((((int)m_accum>>(int)2)&(int)511) * (m_sample[1] - m_sample[0])) >> 9); } u32 es550x_shared_core::es550x_voice_t::es550x_alu_t::get_accum_integer() { - return bitfield(m_accum, m_fraction, m_integer); + return (m_accum>>m_fraction)&((1<