From 1b3dae918a72a04896fc619ae271e0727ffb4660 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 9 Apr 2018 03:39:34 -0400 Subject: [PATCH] StreamADPCM: Turn the ADPCM decoder into a class Migrates the state to be instance-based as opposed to being a flat namespace. This keeps behavior localized to its own instantiable unit (and forces uses of the class to also be localized, lest they cart around an instance all over the place). --- Source/Core/Core/HW/DVD/DVDInterface.cpp | 10 +++++--- Source/Core/Core/HW/StreamADPCM.cpp | 32 ++++++++++-------------- Source/Core/Core/HW/StreamADPCM.h | 16 +++++++++--- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index b7d897fdbc..7d94579e75 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -207,6 +207,8 @@ static UDICR s_DICR; static UDIIMMBUF s_DIIMMBUF; static UDICFG s_DICFG; +static StreamADPCM::ADPCMDecoder s_adpcm_decoder; + // DTK static bool s_stream = false; static bool s_stop_at_track_end = false; @@ -286,7 +288,7 @@ void DoState(PointerWrap& p) DVDThread::DoState(p); - StreamADPCM::DoState(p); + s_adpcm_decoder.DoState(p); } static size_t ProcessDTKSamples(std::vector* temp_pcm, const std::vector& audio_data) @@ -295,7 +297,7 @@ static size_t ProcessDTKSamples(std::vector* temp_pcm, const std::vectorsize() / 2 && bytes_processed < audio_data.size()) { - StreamADPCM::DecodeBlock(&(*temp_pcm)[samples_processed * 2], &audio_data[bytes_processed]); + s_adpcm_decoder.DecodeBlock(&(*temp_pcm)[samples_processed * 2], &audio_data[bytes_processed]); for (size_t i = 0; i < StreamADPCM::SAMPLES_PER_BLOCK * 2; ++i) { // TODO: Fix the mixer so it can accept non-byte-swapped samples. @@ -331,7 +333,7 @@ static u32 AdvanceDTK(u32 maximum_samples, u32* samples_to_process) break; } - StreamADPCM::InitFilter(); + s_adpcm_decoder.ResetFilter(); } s_audio_position += StreamADPCM::ONE_BLOCK_SIZE; @@ -933,7 +935,7 @@ void ExecuteCommand(u32 command_0, u32 command_1, u32 command_2, u32 output_addr s_current_start = s_next_start; s_current_length = s_next_length; s_audio_position = s_current_start; - StreamADPCM::InitFilter(); + s_adpcm_decoder.ResetFilter(); s_stream = true; } } diff --git a/Source/Core/Core/HW/StreamADPCM.cpp b/Source/Core/Core/HW/StreamADPCM.cpp index 1175eb8c9c..fe309b63a5 100644 --- a/Source/Core/Core/HW/StreamADPCM.cpp +++ b/Source/Core/Core/HW/StreamADPCM.cpp @@ -12,12 +12,6 @@ namespace StreamADPCM { -// STATE_TO_SAVE -static s32 histl1; -static s32 histl2; -static s32 histr1; -static s32 histr2; - static s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2) { s32 hist = 0; @@ -49,30 +43,30 @@ static s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2) return (s16)cur; } -void InitFilter() +void ADPCMDecoder::ResetFilter() { - histl1 = 0; - histl2 = 0; - histr1 = 0; - histr2 = 0; + m_histl1 = 0; + m_histl2 = 0; + m_histr1 = 0; + m_histr2 = 0; } -void DoState(PointerWrap& p) +void ADPCMDecoder::DoState(PointerWrap& p) { - p.Do(histl1); - p.Do(histl2); - p.Do(histr1); - p.Do(histr2); + p.Do(m_histl1); + p.Do(m_histl2); + p.Do(m_histr1); + p.Do(m_histr2); } -void DecodeBlock(s16* pcm, const u8* adpcm) +void ADPCMDecoder::DecodeBlock(s16* pcm, const u8* adpcm) { for (int i = 0; i < SAMPLES_PER_BLOCK; i++) { pcm[i * 2] = ADPDecodeSample(adpcm[i + (ONE_BLOCK_SIZE - SAMPLES_PER_BLOCK)] & 0xf, adpcm[0], - histl1, histl2); + m_histl1, m_histl2); pcm[i * 2 + 1] = ADPDecodeSample(adpcm[i + (ONE_BLOCK_SIZE - SAMPLES_PER_BLOCK)] >> 4, adpcm[1], - histr1, histr2); + m_histr1, m_histr2); } } } diff --git a/Source/Core/Core/HW/StreamADPCM.h b/Source/Core/Core/HW/StreamADPCM.h index 7ec6022137..e960a0a60e 100644 --- a/Source/Core/Core/HW/StreamADPCM.h +++ b/Source/Core/Core/HW/StreamADPCM.h @@ -18,7 +18,17 @@ enum SAMPLES_PER_BLOCK = 28 }; -void InitFilter(); -void DoState(PointerWrap& p); -void DecodeBlock(s16* pcm, const u8* adpcm); +class ADPCMDecoder +{ +public: + void ResetFilter(); + void DoState(PointerWrap& p); + void DecodeBlock(s16* pcm, const u8* adpcm); + +private: + s32 m_histl1 = 0; + s32 m_histl2 = 0; + s32 m_histr1 = 0; + s32 m_histr2 = 0; +}; }