From 33b63a62d1a3381f8e7a6a7fa9aea984771586ab Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 26 Jul 2022 18:44:04 -0700 Subject: [PATCH] DSPHLE: Support padded version of libasnd uCode This is used by libogc2 and libogc-rice. --- Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp | 16 +++++++++------- Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h | 10 ++++++++++ Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp index d00e82be03..3d8c6749e9 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp @@ -54,6 +54,11 @@ constexpr u32 FLAGS_SAMPLE_FORMAT_BYTES_SHIFT = 16; constexpr u32 SAMPLE_RATE = 48000; +bool ASndUCode::UseNewFlagMasks() const +{ + return m_crc == HASH_2011 || m_crc == HASH_2020 || m_crc == HASH_2020_PAD; +} + ASndUCode::ASndUCode(DSPHLE* dsphle, u32 crc) : UCodeInterface(dsphle, crc) { } @@ -239,9 +244,8 @@ void ASndUCode::DoMixing(u32 return_mail) // start_main - const u32 sample_format_mask = (m_crc == HASH_2011 || m_crc == HASH_2020) ? - NEW_FLAGS_SAMPLE_FORMAT_MASK : - OLD_FLAGS_SAMPLE_FORMAT_MASK; + const u32 sample_format_mask = + UseNewFlagMasks() ? NEW_FLAGS_SAMPLE_FORMAT_MASK : OLD_FLAGS_SAMPLE_FORMAT_MASK; const u32 sample_format = m_current_voice.flags & sample_format_mask; const u32 sample_format_step = (m_current_voice.flags & FLAGS_SAMPLE_FORMAT_BYTES_MASK) >> FLAGS_SAMPLE_FORMAT_BYTES_SHIFT; @@ -255,8 +259,7 @@ void ASndUCode::DoMixing(u32 return_mail) }; const auto sample_function = sample_selector[sample_format]; - const u32 pause_mask = - (m_crc == HASH_2011 || m_crc == HASH_2020) ? NEW_FLAGS_VOICE_PAUSE : OLD_FLAGS_VOICE_PAUSE; + const u32 pause_mask = UseNewFlagMasks() ? NEW_FLAGS_VOICE_PAUSE : OLD_FLAGS_VOICE_PAUSE; if ((m_current_voice.flags & pause_mask) == 0) { @@ -417,8 +420,7 @@ void ASndUCode::ChangeBuffer() m_current_voice.start_addr = m_current_voice.start_addr2; m_current_voice.backup_addr = m_current_voice.start_addr2; - const u32 loop_mask = - (m_crc == HASH_2011 || m_crc == HASH_2020) ? NEW_FLAGS_VOICE_LOOP : OLD_FLAGS_VOICE_LOOP; + const u32 loop_mask = UseNewFlagMasks() ? NEW_FLAGS_VOICE_LOOP : OLD_FLAGS_VOICE_LOOP; if ((m_current_voice.flags & loop_mask) == 0) { diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h index 419d19d92d..2849c80f8b 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h @@ -43,6 +43,14 @@ public: // provided in the repo. There appear to be no behavior differences from the 2011 version. // https://github.com/devkitPro/libogc/compare/bfb705fe1607a3031d18b65d603975b68a1cffd4~...d20f9bdcfb43260c6c759f4fb98d724931443f93 static constexpr u32 HASH_2020 = 0xdbbeeb61; + // Variant of the above used in libogc-rice and libogc2 starting on December 11, 2020 and padded + // to 0x0620 bytes. These forks have gcdsptool generate a header file instead of a bin file + // (followed by bin2o), so padding is still applied (for libogc-rice, the header is manually + // generated, while libogc2 generates it as part of the build process). + // https://github.com/extremscorner/libogc2/commit/80e01cbd8ead0370d98e092b426f851f21175e60 + // https://github.com/extremscorner/libogc2/commit/0b64f879808953d80ba06501a1c079b0fbf017d2 + // https://github.com/extremscorner/libogc-rice/commit/ce22c3269699fdbd474f2f28ca2ffca211954659 + static constexpr u32 HASH_2020_PAD = 0xbad876ef; private: void DMAInVoiceData(); @@ -52,6 +60,8 @@ private: void ChangeBuffer(); void DoMixing(u32 return_mail); + bool UseNewFlagMasks() const; + std::pair ReadSampleMono8Bits() const; std::pair ReadSampleStereo8Bits() const; std::pair ReadSampleMono16Bits() const; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp index 72c387ed5e..f8ccee5deb 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp @@ -288,6 +288,7 @@ std::unique_ptr UCodeFactory(u32 crc, DSPHLE* dsphle, bool wii) case ASndUCode::HASH_2009: case ASndUCode::HASH_2011: case ASndUCode::HASH_2020: + case ASndUCode::HASH_2020_PAD: INFO_LOG_FMT(DSPHLE, "CRC {:08x}: ASnd chosen (Homebrew)", crc); return std::make_unique(dsphle, crc);