Merge pull request #3042 from booto/audio-timing

AI: reduce overhead of sample counter
This commit is contained in:
Scott Mansell 2015-09-27 05:03:55 +13:00
commit a91810ba3b
1 changed files with 16 additions and 11 deletions

View File

@ -133,7 +133,7 @@ void DoState(PointerWrap &p)
static void GenerateAudioInterrupt();
static void UpdateInterrupts();
static void IncreaseSampleCount(const u32 _uAmount);
static u64 GetAIPeriod();
static int GetAIPeriod();
static int et_AI;
void Init()
@ -205,7 +205,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
g_LastCPUTime = CoreTiming::GetTicks();
CoreTiming::RemoveEvent(et_AI);
CoreTiming::ScheduleEvent(((int)GetAIPeriod() / 2), et_AI);
CoreTiming::ScheduleEvent(GetAIPeriod(), et_AI);
}
// AI Interrupt
@ -238,10 +238,14 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
mmio->Register(base | AI_SAMPLE_COUNTER,
MMIO::ComplexRead<u32>([](u32) {
Update(0, 0);
return m_SampleCounter;
return m_SampleCounter + static_cast<u32>((CoreTiming::GetTicks() - g_LastCPUTime) / g_CPUCyclesPerSample);
}),
MMIO::DirectWrite<u32>(&m_SampleCounter)
MMIO::ComplexWrite<u32>([](u32, u32 val) {
m_SampleCounter = val;
g_LastCPUTime = CoreTiming::GetTicks();
CoreTiming::RemoveEvent(et_AI);
CoreTiming::ScheduleEvent(GetAIPeriod(), et_AI);
})
);
mmio->Register(base | AI_INTERRUPT_TIMING,
@ -250,7 +254,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
DEBUG_LOG(AUDIO_INTERFACE, "AI_INTERRUPT_TIMING=%08x@%08x", val, PowerPC::ppcState.pc);
m_InterruptTiming = val;
CoreTiming::RemoveEvent(et_AI);
CoreTiming::ScheduleEvent(((int)GetAIPeriod() / 2), et_AI);
CoreTiming::ScheduleEvent(GetAIPeriod(), et_AI);
})
);
}
@ -308,16 +312,17 @@ void Update(u64 userdata, int cyclesLate)
g_LastCPUTime += Samples * g_CPUCyclesPerSample;
IncreaseSampleCount(Samples);
}
CoreTiming::ScheduleEvent(((int)GetAIPeriod() / 2) - cyclesLate, et_AI);
CoreTiming::ScheduleEvent(GetAIPeriod() - cyclesLate, et_AI);
}
}
u64 GetAIPeriod()
int GetAIPeriod()
{
u64 period = g_CPUCyclesPerSample * m_InterruptTiming;
u64 period = g_CPUCyclesPerSample * (m_InterruptTiming-m_SampleCounter);
u64 s_period = g_CPUCyclesPerSample * g_AISSampleRate;
if (period == 0)
period = 32000 * g_CPUCyclesPerSample;
return period;
return static_cast<int>(s_period);
return static_cast<int>(std::min(period, s_period));
}
} // end of namespace AudioInterface