From 8dc20eb5cdc467c2d25b6bf68013533dbd571646 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Tue, 9 Jun 2015 20:14:06 -0700 Subject: [PATCH] Scaling audio playback frequency with clock time scaling. --- src/xenia/apu/xaudio2/xaudio2_audio_driver.cc | 22 ++++++++++++------- .../cpu/frontend/test/xe-cpu-ppc-test.vcxproj | 1 + .../test/xe-cpu-ppc-test.vcxproj.filters | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc b/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc index 91c6aba59..608b201fa 100644 --- a/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc +++ b/src/xenia/apu/xaudio2/xaudio2_audio_driver.cc @@ -10,6 +10,7 @@ #include "xenia/apu/xaudio2/xaudio2_audio_driver.h" #include "xenia/apu/apu-private.h" +#include "xenia/base/clock.h" #include "xenia/base/logging.h" #include "xenia/emulator.h" @@ -35,15 +36,15 @@ class XAudio2AudioDriver::VoiceCallback : public IXAudio2VoiceCallback { }; XAudio2AudioDriver::XAudio2AudioDriver(Emulator* emulator, HANDLE wait) - : audio_(0), - mastering_voice_(0), - pcm_voice_(0), + : audio_(nullptr), + mastering_voice_(nullptr), + pcm_voice_(nullptr), wait_handle_(wait), - voice_callback_(0), + voice_callback_(nullptr), current_frame_(0), AudioDriver(emulator) {} -XAudio2AudioDriver::~XAudio2AudioDriver() {} +XAudio2AudioDriver::~XAudio2AudioDriver() = default; const DWORD ChannelMasks[] = { 0, // TODO: fixme @@ -102,9 +103,10 @@ void XAudio2AudioDriver::Initialize() { waveformat.Samples.wValidBitsPerSample = waveformat.Format.wBitsPerSample; waveformat.dwChannelMask = ChannelMasks[waveformat.Format.nChannels]; - hr = audio_->CreateSourceVoice(&pcm_voice_, &waveformat.Format, - 0, // XAUDIO2_VOICE_NOSRC | XAUDIO2_VOICE_NOPITCH, - XAUDIO2_DEFAULT_FREQ_RATIO, voice_callback_); + hr = audio_->CreateSourceVoice( + &pcm_voice_, &waveformat.Format, + 0, // XAUDIO2_VOICE_NOSRC | XAUDIO2_VOICE_NOPITCH, + XAUDIO2_MAX_FREQ_RATIO, voice_callback_); if (FAILED(hr)) { XELOGE("CreateSourceVoice failed with %.8X", hr); assert_always(); @@ -164,6 +166,10 @@ void XAudio2AudioDriver::SubmitFrame(uint32_t frame_ptr) { current_frame_ = (current_frame_ + 1) % frame_count_; + // Update playback ratio to our time scalar. + // This will keep audio in sync with the game clock. + pcm_voice_->SetFrequencyRatio(float(xe::Clock::guest_time_scalar())); + XAUDIO2_VOICE_STATE state2; pcm_voice_->GetState(&state2, XAUDIO2_VOICE_NOSAMPLESPLAYED); diff --git a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj index 5a4592dd9..4a51bd167 100644 --- a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj +++ b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj @@ -217,6 +217,7 @@ + diff --git a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj.filters b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj.filters index efb4c8f88..8572a8506 100644 --- a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj.filters +++ b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.vcxproj.filters @@ -121,6 +121,7 @@ +