mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-05 15:37:51 +00:00
Merge pull request #6482 from unknownbrackets/timing
Reduce timing inaccuracy from 44.1kHz
This commit is contained in:
commit
ac2279ce78
@ -87,6 +87,7 @@ static std::recursive_mutex externalEventSection;
|
||||
|
||||
// Warning: not included in save state.
|
||||
void (*advanceCallback)(int cyclesExecuted) = NULL;
|
||||
std::vector<MHzChangeCallback> mhzChangeCallbacks;
|
||||
|
||||
void SetClockFrequencyMHz(int cpuMhz)
|
||||
{
|
||||
@ -97,6 +98,11 @@ void SetClockFrequencyMHz(int cpuMhz)
|
||||
|
||||
CPU_HZ = cpuMhz * 1000000;
|
||||
// TODO: Rescale times of scheduled events?
|
||||
|
||||
for (auto it = mhzChangeCallbacks.begin(), end = mhzChangeCallbacks.end(); it != end; ++it) {
|
||||
MHzChangeCallback cb = *it;
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
int GetClockFrequencyMHz()
|
||||
@ -198,6 +204,7 @@ void Init()
|
||||
lastGlobalTimeTicks = 0;
|
||||
lastGlobalTimeUs = 0;
|
||||
hasTsEvents = 0;
|
||||
mhzChangeCallbacks.clear();
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
@ -407,6 +414,10 @@ void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted))
|
||||
advanceCallback = callback;
|
||||
}
|
||||
|
||||
void RegisterMHzChangeCallback(MHzChangeCallback callback) {
|
||||
mhzChangeCallbacks.push_back(callback);
|
||||
}
|
||||
|
||||
bool IsScheduled(int event_type)
|
||||
{
|
||||
if (!first)
|
||||
|
@ -76,6 +76,7 @@ namespace CoreTiming
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
typedef void (*MHzChangeCallback)();
|
||||
typedef void (*TimedCallback)(u64 userdata, int cyclesLate);
|
||||
|
||||
u64 GetTicks();
|
||||
@ -116,6 +117,7 @@ namespace CoreTiming
|
||||
|
||||
// Warning: not included in save states.
|
||||
void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted));
|
||||
void RegisterMHzChangeCallback(MHzChangeCallback callback);
|
||||
|
||||
std::string GetScheduledEventsSummary();
|
||||
|
||||
|
@ -52,8 +52,8 @@ const int hwSampleRate = 44100;
|
||||
int hwBlockSize = 64;
|
||||
int hostAttemptBlockSize = 512;
|
||||
|
||||
static int audioIntervalUs;
|
||||
static int audioHostIntervalUs;
|
||||
static int audioIntervalCycles;
|
||||
static int audioHostIntervalCycles;
|
||||
|
||||
static s32 *mixBuffer;
|
||||
|
||||
@ -84,19 +84,25 @@ static inline s16 adjustvolume(s16 sample, int vol) {
|
||||
|
||||
void hleAudioUpdate(u64 userdata, int cyclesLate) {
|
||||
// Schedule the next cycle first. __AudioUpdate() may consume cycles.
|
||||
CoreTiming::ScheduleEvent(usToCycles(audioIntervalUs) - cyclesLate, eventAudioUpdate, 0);
|
||||
CoreTiming::ScheduleEvent(audioIntervalCycles - cyclesLate, eventAudioUpdate, 0);
|
||||
|
||||
__AudioUpdate();
|
||||
}
|
||||
|
||||
void hleHostAudioUpdate(u64 userdata, int cyclesLate) {
|
||||
CoreTiming::ScheduleEvent(usToCycles(audioHostIntervalUs) - cyclesLate, eventHostAudioUpdate, 0);
|
||||
CoreTiming::ScheduleEvent(audioHostIntervalCycles - cyclesLate, eventHostAudioUpdate, 0);
|
||||
|
||||
// Not all hosts need this call to poke their audio system once in a while, but those that don't
|
||||
// can just ignore it.
|
||||
host->UpdateSound();
|
||||
}
|
||||
|
||||
void __AudioCPUMHzChange() {
|
||||
audioIntervalCycles = (int)(usToCycles(1000000ULL) * hwBlockSize / hwSampleRate);
|
||||
audioHostIntervalCycles = (int)(usToCycles(1000000ULL) * hostAttemptBlockSize / hwSampleRate);
|
||||
}
|
||||
|
||||
|
||||
void __AudioInit() {
|
||||
mixFrequency = 44100;
|
||||
|
||||
@ -122,14 +128,13 @@ void __AudioInit() {
|
||||
|
||||
}
|
||||
|
||||
audioIntervalUs = (int)(1000000ULL * hwBlockSize / hwSampleRate);
|
||||
audioHostIntervalUs = (int)(1000000ULL * hostAttemptBlockSize / hwSampleRate);
|
||||
__AudioCPUMHzChange();
|
||||
|
||||
eventAudioUpdate = CoreTiming::RegisterEvent("AudioUpdate", &hleAudioUpdate);
|
||||
eventHostAudioUpdate = CoreTiming::RegisterEvent("AudioUpdateHost", &hleHostAudioUpdate);
|
||||
|
||||
CoreTiming::ScheduleEvent(usToCycles(audioIntervalUs), eventAudioUpdate, 0);
|
||||
CoreTiming::ScheduleEvent(usToCycles(audioHostIntervalUs), eventHostAudioUpdate, 0);
|
||||
CoreTiming::ScheduleEvent(audioIntervalCycles, eventAudioUpdate, 0);
|
||||
CoreTiming::ScheduleEvent(audioHostIntervalCycles, eventHostAudioUpdate, 0);
|
||||
for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++)
|
||||
chans[i].clear();
|
||||
|
||||
@ -139,8 +144,8 @@ void __AudioInit() {
|
||||
__blockForAudioQueueLock();
|
||||
outAudioQueue.clear();
|
||||
__releaseAcquiredLock();
|
||||
CoreTiming::RegisterMHzChangeCallback(&__AudioCPUMHzChange);
|
||||
}
|
||||
|
||||
void __AudioDoState(PointerWrap &p) {
|
||||
auto s = p.Section("sceAudio", 1);
|
||||
if (!s)
|
||||
|
Loading…
Reference in New Issue
Block a user