DSPHLE: Support padded version of libasnd uCode

This is used by libogc2 and libogc-rice.
This commit is contained in:
Pokechu22 2022-07-26 18:44:04 -07:00
parent 97100290ee
commit 33b63a62d1
3 changed files with 20 additions and 7 deletions

View file

@ -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)
{

View file

@ -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<s16, s16> ReadSampleMono8Bits() const;
std::pair<s16, s16> ReadSampleStereo8Bits() const;
std::pair<s16, s16> ReadSampleMono16Bits() const;

View file

@ -288,6 +288,7 @@ std::unique_ptr<UCodeInterface> 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<ASndUCode>(dsphle, crc);