mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Reduce audio drift from 44.1kHz.
Although, not sure what the PSP's actual exact timing is...
This commit is contained in:
parent
f5440c2357
commit
b73c1ba29b
1 changed files with 14 additions and 9 deletions
|
@ -52,8 +52,8 @@ const int hwSampleRate = 44100;
|
||||||
int hwBlockSize = 64;
|
int hwBlockSize = 64;
|
||||||
int hostAttemptBlockSize = 512;
|
int hostAttemptBlockSize = 512;
|
||||||
|
|
||||||
static int audioIntervalUs;
|
static int audioIntervalCycles;
|
||||||
static int audioHostIntervalUs;
|
static int audioHostIntervalCycles;
|
||||||
|
|
||||||
static s32 *mixBuffer;
|
static s32 *mixBuffer;
|
||||||
|
|
||||||
|
@ -84,19 +84,25 @@ static inline s16 adjustvolume(s16 sample, int vol) {
|
||||||
|
|
||||||
void hleAudioUpdate(u64 userdata, int cyclesLate) {
|
void hleAudioUpdate(u64 userdata, int cyclesLate) {
|
||||||
// Schedule the next cycle first. __AudioUpdate() may consume cycles.
|
// Schedule the next cycle first. __AudioUpdate() may consume cycles.
|
||||||
CoreTiming::ScheduleEvent(usToCycles(audioIntervalUs) - cyclesLate, eventAudioUpdate, 0);
|
CoreTiming::ScheduleEvent(audioIntervalCycles - cyclesLate, eventAudioUpdate, 0);
|
||||||
|
|
||||||
__AudioUpdate();
|
__AudioUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hleHostAudioUpdate(u64 userdata, int cyclesLate) {
|
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
|
// Not all hosts need this call to poke their audio system once in a while, but those that don't
|
||||||
// can just ignore it.
|
// can just ignore it.
|
||||||
host->UpdateSound();
|
host->UpdateSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __AudioCPUMHzChange() {
|
||||||
|
audioIntervalCycles = (int)(usToCycles(1000000ULL) * hwBlockSize / hwSampleRate);
|
||||||
|
audioHostIntervalCycles = (int)(usToCycles(1000000ULL) * hostAttemptBlockSize / hwSampleRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void __AudioInit() {
|
void __AudioInit() {
|
||||||
mixFrequency = 44100;
|
mixFrequency = 44100;
|
||||||
|
|
||||||
|
@ -122,14 +128,13 @@ void __AudioInit() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
audioIntervalUs = (int)(1000000ULL * hwBlockSize / hwSampleRate);
|
__AudioCPUMHzChange();
|
||||||
audioHostIntervalUs = (int)(1000000ULL * hostAttemptBlockSize / hwSampleRate);
|
|
||||||
|
|
||||||
eventAudioUpdate = CoreTiming::RegisterEvent("AudioUpdate", &hleAudioUpdate);
|
eventAudioUpdate = CoreTiming::RegisterEvent("AudioUpdate", &hleAudioUpdate);
|
||||||
eventHostAudioUpdate = CoreTiming::RegisterEvent("AudioUpdateHost", &hleHostAudioUpdate);
|
eventHostAudioUpdate = CoreTiming::RegisterEvent("AudioUpdateHost", &hleHostAudioUpdate);
|
||||||
|
|
||||||
CoreTiming::ScheduleEvent(usToCycles(audioIntervalUs), eventAudioUpdate, 0);
|
CoreTiming::ScheduleEvent(audioIntervalCycles, eventAudioUpdate, 0);
|
||||||
CoreTiming::ScheduleEvent(usToCycles(audioHostIntervalUs), eventHostAudioUpdate, 0);
|
CoreTiming::ScheduleEvent(audioHostIntervalCycles, eventHostAudioUpdate, 0);
|
||||||
for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++)
|
for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++)
|
||||||
chans[i].clear();
|
chans[i].clear();
|
||||||
|
|
||||||
|
@ -139,8 +144,8 @@ void __AudioInit() {
|
||||||
__blockForAudioQueueLock();
|
__blockForAudioQueueLock();
|
||||||
outAudioQueue.clear();
|
outAudioQueue.clear();
|
||||||
__releaseAcquiredLock();
|
__releaseAcquiredLock();
|
||||||
|
CoreTiming::RegisterMHzChangeCallback(&__AudioCPUMHzChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __AudioDoState(PointerWrap &p) {
|
void __AudioDoState(PointerWrap &p) {
|
||||||
auto s = p.Section("sceAudio", 1);
|
auto s = p.Section("sceAudio", 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
|
Loading…
Add table
Reference in a new issue