mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
Merge pull request #10058 from AdmiralCurtiss/dsp-cleanup
DSPHLE: Minor cleanup & savestate fix for AX coefficients.
This commit is contained in:
commit
1fa74ab824
@ -21,10 +21,10 @@ bool DSPHLE::Initialize(bool wii, bool dsp_thread)
|
|||||||
m_wii = wii;
|
m_wii = wii;
|
||||||
m_ucode = nullptr;
|
m_ucode = nullptr;
|
||||||
m_last_ucode = nullptr;
|
m_last_ucode = nullptr;
|
||||||
m_halt = false;
|
|
||||||
m_assert_interrupt = false;
|
|
||||||
|
|
||||||
SetUCode(UCODE_ROM);
|
SetUCode(UCODE_ROM);
|
||||||
|
|
||||||
|
m_dsp_control.Hex = 0;
|
||||||
m_dsp_control.DSPHalt = 1;
|
m_dsp_control.DSPHalt = 1;
|
||||||
m_dsp_control.DSPInit = 1;
|
m_dsp_control.DSPInit = 1;
|
||||||
|
|
||||||
|
@ -66,8 +66,5 @@ private:
|
|||||||
|
|
||||||
DSP::UDSPControl m_dsp_control;
|
DSP::UDSPControl m_dsp_control;
|
||||||
CMailHandler m_mail_handler;
|
CMailHandler m_mail_handler;
|
||||||
|
|
||||||
bool m_halt;
|
|
||||||
bool m_assert_interrupt;
|
|
||||||
};
|
};
|
||||||
} // namespace DSP::HLE
|
} // namespace DSP::HLE
|
||||||
|
@ -5,14 +5,17 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
#include "Common/ChunkFile.h"
|
#include "Common/ChunkFile.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/Hash.h"
|
||||||
#include "Common/IOFile.h"
|
#include "Common/IOFile.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
|
#include "Core/Core.h"
|
||||||
#include "Core/DolphinAnalytics.h"
|
#include "Core/DolphinAnalytics.h"
|
||||||
#include "Core/HW/DSP.h"
|
#include "Core/HW/DSP.h"
|
||||||
#include "Core/HW/DSPHLE/DSPHLE.h"
|
#include "Core/HW/DSPHLE/DSPHLE.h"
|
||||||
@ -24,8 +27,7 @@
|
|||||||
|
|
||||||
namespace DSP::HLE
|
namespace DSP::HLE
|
||||||
{
|
{
|
||||||
AXUCode::AXUCode(DSPHLE* dsphle, u32 crc)
|
AXUCode::AXUCode(DSPHLE* dsphle, u32 crc) : UCodeInterface(dsphle, crc)
|
||||||
: UCodeInterface(dsphle, crc), m_cmdlist_size(0), m_compressor_pos(0)
|
|
||||||
{
|
{
|
||||||
INFO_LOG_FMT(DSPHLE, "Instantiating AXUCode: crc={:08x}", crc);
|
INFO_LOG_FMT(DSPHLE, "Instantiating AXUCode: crc={:08x}", crc);
|
||||||
}
|
}
|
||||||
@ -39,41 +41,44 @@ void AXUCode::Initialize()
|
|||||||
{
|
{
|
||||||
m_mail_handler.PushMail(DSP_INIT, true);
|
m_mail_handler.PushMail(DSP_INIT, true);
|
||||||
|
|
||||||
LoadResamplingCoefficients();
|
LoadResamplingCoefficients(false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AXUCode::LoadResamplingCoefficients()
|
bool AXUCode::LoadResamplingCoefficients(bool require_same_checksum, u32 desired_checksum)
|
||||||
{
|
{
|
||||||
m_coeffs_available = false;
|
constexpr size_t raw_coeffs_size = 0x800 * 2;
|
||||||
|
m_coeffs_checksum = std::nullopt;
|
||||||
|
|
||||||
const std::array<std::string, 2> filenames{
|
const std::array<std::string, 2> filenames{
|
||||||
File::GetUserPath(D_GCUSER_IDX) + "dsp_coef.bin",
|
File::GetUserPath(D_GCUSER_IDX) + "dsp_coef.bin",
|
||||||
File::GetSysDirectory() + "/GC/dsp_coef.bin",
|
File::GetSysDirectory() + "/GC/dsp_coef.bin",
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t fidx;
|
for (const std::string& filename : filenames)
|
||||||
std::string filename;
|
|
||||||
for (fidx = 0; fidx < filenames.size(); ++fidx)
|
|
||||||
{
|
{
|
||||||
filename = filenames[fidx];
|
INFO_LOG_FMT(DSPHLE, "Checking for polyphase resampling coeffs at {}", filename);
|
||||||
if (File::GetSize(filename) != 0x1000)
|
|
||||||
|
if (File::GetSize(filename) != raw_coeffs_size)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
break;
|
File::IOFile fp(filename, "rb");
|
||||||
|
std::array<u8, raw_coeffs_size> raw_coeffs;
|
||||||
|
fp.ReadBytes(raw_coeffs.data(), raw_coeffs_size);
|
||||||
|
|
||||||
|
u32 checksum = Common::HashAdler32(raw_coeffs.data(), raw_coeffs_size);
|
||||||
|
if (require_same_checksum && checksum != desired_checksum)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::memcpy(m_coeffs.data(), raw_coeffs.data(), raw_coeffs_size);
|
||||||
|
for (auto& coef : m_coeffs)
|
||||||
|
coef = Common::swap16(coef);
|
||||||
|
|
||||||
|
INFO_LOG_FMT(DSPHLE, "Using polyphase resampling coeffs from {}", filename);
|
||||||
|
m_coeffs_checksum = checksum;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fidx >= filenames.size())
|
return false;
|
||||||
return;
|
|
||||||
|
|
||||||
INFO_LOG_FMT(DSPHLE, "Loading polyphase resampling coeffs from {}", filename);
|
|
||||||
|
|
||||||
File::IOFile fp(filename, "rb");
|
|
||||||
fp.ReadBytes(m_coeffs, 0x1000);
|
|
||||||
|
|
||||||
for (auto& coef : m_coeffs)
|
|
||||||
coef = Common::swap16(coef);
|
|
||||||
|
|
||||||
m_coeffs_available = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AXUCode::SignalWorkEnd()
|
void AXUCode::SignalWorkEnd()
|
||||||
@ -433,7 +438,7 @@ void AXUCode::ProcessPBList(u32 pb_addr)
|
|||||||
ApplyUpdatesForMs(curr_ms, pb, pb.updates.num_updates, updates);
|
ApplyUpdatesForMs(curr_ms, pb, pb.updates.num_updates, updates);
|
||||||
|
|
||||||
ProcessVoice(pb, buffers, spms, ConvertMixerControl(pb.mixer_control),
|
ProcessVoice(pb, buffers, spms, ConvertMixerControl(pb.mixer_control),
|
||||||
m_coeffs_available ? m_coeffs : nullptr);
|
m_coeffs_checksum ? m_coeffs.data() : nullptr);
|
||||||
|
|
||||||
// Forward the buffers
|
// Forward the buffers
|
||||||
for (auto& ptr : buffers.ptrs)
|
for (auto& ptr : buffers.ptrs)
|
||||||
@ -750,6 +755,22 @@ void AXUCode::DoAXState(PointerWrap& p)
|
|||||||
p.Do(m_samples_auxB_right);
|
p.Do(m_samples_auxB_right);
|
||||||
p.Do(m_samples_auxB_surround);
|
p.Do(m_samples_auxB_surround);
|
||||||
|
|
||||||
|
auto old_checksum = m_coeffs_checksum;
|
||||||
|
p.Do(m_coeffs_checksum);
|
||||||
|
|
||||||
|
if (p.GetMode() == PointerWrap::MODE_READ && m_coeffs_checksum &&
|
||||||
|
old_checksum != m_coeffs_checksum)
|
||||||
|
{
|
||||||
|
if (!LoadResamplingCoefficients(true, *m_coeffs_checksum))
|
||||||
|
{
|
||||||
|
Core::DisplayMessage("Could not find the DSP polyphase resampling coefficients used by the "
|
||||||
|
"savestate. Aborting load state.",
|
||||||
|
3000);
|
||||||
|
p.SetMode(PointerWrap::MODE_VERIFY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.Do(m_compressor_pos);
|
p.Do(m_compressor_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "Common/BitUtils.h"
|
#include "Common/BitUtils.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
@ -90,17 +93,17 @@ protected:
|
|||||||
int m_samples_auxB_surround[32 * 5];
|
int m_samples_auxB_surround[32 * 5];
|
||||||
|
|
||||||
u16 m_cmdlist[512];
|
u16 m_cmdlist[512];
|
||||||
u32 m_cmdlist_size;
|
u32 m_cmdlist_size = 0;
|
||||||
|
|
||||||
// Table of coefficients for polyphase sample rate conversion.
|
// Table of coefficients for polyphase sample rate conversion.
|
||||||
// The coefficients aren't always available (they are part of the DSP DROM)
|
// The coefficients aren't always available (they are part of the DSP DROM)
|
||||||
// so we also need to know if they are valid or not.
|
// so we also need to know if they are valid or not.
|
||||||
bool m_coeffs_available;
|
std::optional<u32> m_coeffs_checksum = std::nullopt;
|
||||||
s16 m_coeffs[0x800];
|
std::array<s16, 0x800> m_coeffs;
|
||||||
|
|
||||||
u16 m_compressor_pos;
|
u16 m_compressor_pos = 0;
|
||||||
|
|
||||||
void LoadResamplingCoefficients();
|
bool LoadResamplingCoefficients(bool require_same_checksum, u32 desired_checksum);
|
||||||
|
|
||||||
// Copy a command list from memory to our temp buffer
|
// Copy a command list from memory to our temp buffer
|
||||||
void CopyCmdList(u32 addr, u16 size);
|
void CopyCmdList(u32 addr, u16 size);
|
||||||
|
@ -472,7 +472,7 @@ void AXWiiUCode::ProcessPBList(u32 pb_addr)
|
|||||||
{
|
{
|
||||||
ApplyUpdatesForMs(curr_ms, pb, num_updates, updates);
|
ApplyUpdatesForMs(curr_ms, pb, num_updates, updates);
|
||||||
ProcessVoice(pb, buffers, spms, ConvertMixerControl(HILO_TO_32(pb.mixer_control)),
|
ProcessVoice(pb, buffers, spms, ConvertMixerControl(HILO_TO_32(pb.mixer_control)),
|
||||||
m_coeffs_available ? m_coeffs : nullptr);
|
m_coeffs_checksum ? m_coeffs.data() : nullptr);
|
||||||
|
|
||||||
// Forward the buffers
|
// Forward the buffers
|
||||||
for (auto& ptr : buffers.ptrs)
|
for (auto& ptr : buffers.ptrs)
|
||||||
@ -483,7 +483,7 @@ void AXWiiUCode::ProcessPBList(u32 pb_addr)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ProcessVoice(pb, buffers, 96, ConvertMixerControl(HILO_TO_32(pb.mixer_control)),
|
ProcessVoice(pb, buffers, 96, ConvertMixerControl(HILO_TO_32(pb.mixer_control)),
|
||||||
m_coeffs_available ? m_coeffs : nullptr);
|
m_coeffs_checksum ? m_coeffs.data() : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
WritePB(pb_addr, pb, m_crc);
|
WritePB(pb_addr, pb, m_crc);
|
||||||
|
@ -73,7 +73,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
|
|||||||
static std::thread g_save_thread;
|
static std::thread g_save_thread;
|
||||||
|
|
||||||
// Don't forget to increase this after doing changes on the savestate system
|
// Don't forget to increase this after doing changes on the savestate system
|
||||||
constexpr u32 STATE_VERSION = 135; // Last changed in PR 9976
|
constexpr u32 STATE_VERSION = 136; // Last changed in PR 10058
|
||||||
|
|
||||||
// Maps savestate versions to Dolphin versions.
|
// Maps savestate versions to Dolphin versions.
|
||||||
// Versions after 42 don't need to be added to this list,
|
// Versions after 42 don't need to be added to this list,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user