Refactored the SystemTimers to allow for per-UCode timing. Fixes issue 6237.

This commit is contained in:
skidau 2013-04-12 12:08:05 +10:00
parent addd3926d9
commit ef4d59a21e
21 changed files with 69 additions and 17 deletions

View File

@ -44,6 +44,7 @@ public:
virtual void DSP_Update(int cycles) = 0;
virtual void DSP_StopSoundStream() = 0;
virtual void DSP_ClearAudioBuffer(bool mute) = 0;
virtual u32 DSP_UpdateRate() = 0;
protected:
SoundStream *soundStream;

View File

@ -28,6 +28,7 @@
#include "../AudioInterface.h"
#include "ConfigManager.h"
#include "Core.h"
#include "HW/SystemTimers.h"
DSPHLE::DSPHLE() {
m_InitMixer = false;
@ -87,6 +88,16 @@ void DSPHLE::DSP_Update(int cycles)
m_pUCode->Update(cycles / 6);
}
u32 DSPHLE::DSP_UpdateRate()
{
// AX HLE uses 3ms (Wii) or 5ms (GC) timing period
int fields = SConfig::GetInstance().m_LocalCoreStartupParameter.bVBeam ? 2 : 1;
if (m_pUCode != NULL)
return (SystemTimers::GetTicksPerSecond() / 1000) * m_pUCode->GetUpdateMs() / fields;
else
return SystemTimers::GetTicksPerSecond() / 1000;
}
void DSPHLE::SendMailToDSP(u32 _uMail)
{
if (m_pUCode != NULL) {

View File

@ -46,6 +46,7 @@ public:
virtual void DSP_Update(int cycles);
virtual void DSP_StopSoundStream();
virtual void DSP_ClearAudioBuffer(bool mute);
virtual u32 DSP_UpdateRate();
CMailHandler& AccessMailHandler() { return m_MailHandler; }

View File

@ -738,6 +738,11 @@ void CUCode_AX::Update(int cycles)
}
}
u32 CUCode_AX::GetUpdateMs()
{
return 5;
}
void CUCode_AX::DoAXState(PointerWrap& p)
{
p.Do(m_cmdlist);

View File

@ -73,6 +73,7 @@ public:
virtual void MixAdd(short* out_buffer, int nsamples);
virtual void Update(int cycles);
virtual void DoState(PointerWrap& p);
u32 GetUpdateMs();
// Needed because StdThread.h std::thread implem does not support member
// pointers. TODO(delroth): obsolete.

View File

@ -672,6 +672,11 @@ void CUCode_AXWii::OutputWMSamples(u32* addresses)
}
}
u32 CUCode_AXWii::GetUpdateMs()
{
return 3;
}
void CUCode_AXWii::DoState(PointerWrap &p)
{
std::lock_guard<std::mutex> lk(m_processing);

View File

@ -25,6 +25,7 @@ class CUCode_AXWii : public CUCode_AX
public:
CUCode_AXWii(DSPHLE *dsp_hle, u32 _CRC);
virtual ~CUCode_AXWii();
u32 GetUpdateMs();
virtual void DoState(PointerWrap &p);

View File

@ -19,6 +19,7 @@
#include "UCodes.h"
#include "UCode_CARD.h"
#include "../../DSP.h"
#include "ConfigManager.h"
CUCode_CARD::CUCode_CARD(DSPHLE *dsp_hle, u32 crc)
@ -44,6 +45,11 @@ void CUCode_CARD::Update(int cycles)
}
}
u32 CUCode_CARD::GetUpdateMs()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
}
void CUCode_CARD::HandleMail(u32 _uMail)
{
if (_uMail == 0xFF000000) // unlock card

View File

@ -25,6 +25,7 @@ class CUCode_CARD : public IUCode
public:
CUCode_CARD(DSPHLE *dsp_hle, u32 crc);
virtual ~CUCode_CARD();
u32 GetUpdateMs();
void HandleMail(u32 _uMail);
void Update(int cycles);

View File

@ -19,6 +19,7 @@
#include "UCode_GBA.h"
#include "../../DSP.h"
#include "ConfigManager.h"
CUCode_GBA::CUCode_GBA(DSPHLE *dsp_hle, u32 crc)
: IUCode(dsp_hle, crc)
@ -40,6 +41,11 @@ void CUCode_GBA::Update(int cycles)
}
}
u32 CUCode_GBA::GetUpdateMs()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
}
void CUCode_GBA::HandleMail(u32 _uMail)
{
static bool nextmail_is_mramaddr = false;

View File

@ -23,6 +23,7 @@ struct CUCode_GBA : public IUCode
{
CUCode_GBA(DSPHLE *dsp_hle, u32 crc);
virtual ~CUCode_GBA();
u32 GetUpdateMs();
void HandleMail(u32 _uMail);
void Update(int cycles);

View File

@ -17,6 +17,7 @@
#include "UCodes.h"
#include "UCode_InitAudioSystem.h"
#include "ConfigManager.h"
CUCode_InitAudioSystem::CUCode_InitAudioSystem(DSPHLE *dsp_hle, u32 crc)
: IUCode(dsp_hle, crc)
@ -42,6 +43,11 @@ void CUCode_InitAudioSystem::Update(int cycles)
}
}
u32 CUCode_InitAudioSystem::GetUpdateMs()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
}
void CUCode_InitAudioSystem::HandleMail(u32 _uMail)
{}

View File

@ -25,6 +25,7 @@ class CUCode_InitAudioSystem : public IUCode
public:
CUCode_InitAudioSystem(DSPHLE *dsp_hle, u32 crc);
virtual ~CUCode_InitAudioSystem();
u32 GetUpdateMs();
void HandleMail(u32 _uMail);
void Update(int cycles);

View File

@ -19,6 +19,7 @@
#include "UCode_ROM.h"
#include "Hash.h"
#include "../../Memmap.h"
#include "ConfigManager.h"
CUCode_Rom::CUCode_Rom(DSPHLE *dsp_hle, u32 crc)
: IUCode(dsp_hle, crc)
@ -117,6 +118,11 @@ void CUCode_Rom::BootUCode()
m_DSPHLE->SetUCode(ector_crc);
}
u32 CUCode_Rom::GetUpdateMs()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
}
void CUCode_Rom::DoState(PointerWrap &p)
{
p.Do(m_CurrentUCode);

View File

@ -25,6 +25,7 @@ class CUCode_Rom : public IUCode
public:
CUCode_Rom(DSPHLE *dsp_hle, u32 _crc);
virtual ~CUCode_Rom();
u32 GetUpdateMs();
void HandleMail(u32 _uMail);
void Update(int cycles);

View File

@ -27,6 +27,7 @@
#include "WaveFile.h"
#include "../../DSP.h"
#include "ConfigManager.h"
CUCode_Zelda::CUCode_Zelda(DSPHLE *dsp_hle, u32 _CRC)
@ -565,6 +566,10 @@ void CUCode_Zelda::ExecuteList()
}
}
u32 CUCode_Zelda::GetUpdateMs()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
}
void CUCode_Zelda::DoState(PointerWrap &p)
{

View File

@ -133,6 +133,7 @@ class CUCode_Zelda : public IUCode
public:
CUCode_Zelda(DSPHLE *dsp_hle, u32 _CRC);
virtual ~CUCode_Zelda();
u32 GetUpdateMs();
void HandleMail(u32 _uMail);
void HandleMail_LightVersion(u32 _uMail);

View File

@ -92,6 +92,7 @@ public:
// Cycles are out of the 81/121mhz the DSP runs at.
virtual void Update(int cycles) = 0;
virtual void MixAdd(short* buffer, int size) {}
virtual u32 GetUpdateMs() = 0;
virtual void DoState(PointerWrap &p) { DoStateShared(p); }

View File

@ -326,6 +326,11 @@ void DSPLLE::DSP_Update(int cycles)
}
}
u32 DSPLLE::DSP_UpdateRate()
{
return 12600; // TO BE TWEAKED
}
void DSPLLE::DSP_SendAIBuffer(unsigned int address, unsigned int num_samples)
{
if (!soundStream)

View File

@ -44,6 +44,7 @@ public:
virtual void DSP_Update(int cycles);
virtual void DSP_StopSoundStream();
virtual void DSP_ClearAudioBuffer(bool mute);
virtual u32 DSP_UpdateRate();
private:
static void dsp_thread(DSPLLE* lpParameter);

View File

@ -119,9 +119,6 @@ int et_PatchEngine; // PatchEngine updates every 1/60th of a second by default
// These are badly educated guesses
// Feel free to experiment. Set these in Init below.
int
// These shouldn't be period controlled either, most likely.
DSP_PERIOD,
// This is a fixed value, don't change it
AUDIO_DMA_PERIOD,
@ -149,8 +146,8 @@ void DSPCallback(u64 userdata, int cyclesLate)
{
//splits up the cycle budget in case lle is used
//for hle, just gives all of the slice to hle
DSP::UpdateDSPSlice(DSP_PERIOD - cyclesLate);
CoreTiming::ScheduleEvent(DSP_PERIOD - cyclesLate, et_DSP);
DSP::UpdateDSPSlice(DSP::GetDSPEmulator()->DSP_UpdateRate() - cyclesLate);
CoreTiming::ScheduleEvent(DSP::GetDSPEmulator()->DSP_UpdateRate() - cyclesLate, et_DSP);
}
void AudioDMACallback(u64 userdata, int cyclesLate)
@ -256,17 +253,6 @@ void Init()
IPC_HLE_PERIOD = GetTicksPerSecond() / (freq * fields);
}
if (DSP::GetDSPEmulator()->IsLLE())
{
DSP_PERIOD = 12600; // TO BE TWEAKED
}
else
{
// AX HLE uses 3ms (Wii) or 5ms (GC) timing period
int ms_to_process = SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
DSP_PERIOD = (int)(GetTicksPerSecond() / 1000) * ms_to_process / fields;
}
// System internal sample rate is fixed at 32KHz * 4 (16bit Stereo) / 32 bytes DMA
AUDIO_DMA_PERIOD = CPU_CORE_CLOCK / (AudioInterface::GetAIDSampleRate() * 4 / 32);
@ -292,7 +278,7 @@ void Init()
et_PatchEngine = CoreTiming::RegisterEvent("PatchEngine", PatchEngineCallback);
CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerLine(), et_VI);
CoreTiming::ScheduleEvent(DSP_PERIOD, et_DSP);
CoreTiming::ScheduleEvent(0, et_DSP);
CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerFrame(), et_SI);
CoreTiming::ScheduleEvent(AUDIO_DMA_PERIOD, et_AudioDMA);
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU)