From 4f552da6c40d87ac3aa63dda1ef115bb1af30450 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 12 Jan 2014 23:52:55 -0800 Subject: [PATCH] Inefficient, but pumping audio. --- src/xenia/apu/audio_system.cc | 6 ++++-- src/xenia/apu/audio_system.h | 1 + src/xenia/apu/xaudio2/xaudio2_audio_system.cc | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 0f34c4dd0..c1b21421c 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -23,7 +23,7 @@ using namespace xe::cpu; AudioSystem::AudioSystem(Emulator* emulator) : emulator_(emulator), memory_(emulator->memory()), thread_(0), running_(false), driver_(0), - client_({ 0 }) { + client_({ 0 }), can_submit_(false) { // Create the run loop used for any windows/etc. // This must be done on the thread we create the driver. run_loop_ = xe_run_loop_create(); @@ -87,11 +87,13 @@ void AudioSystem::ThreadStart() { } // Pump worker. + Pump(); + xe_mutex_lock(lock_); uint32_t client_callback = client_.callback; uint32_t client_callback_arg = client_.wrapped_callback_arg; xe_mutex_unlock(lock_); - if (client_callback) { + if (client_callback && can_submit_) { processor->Execute( thread_state_, client_callback, client_callback_arg, 0); } else { diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h index e8d3907b1..5e81dbb65 100644 --- a/src/xenia/apu/audio_system.h +++ b/src/xenia/apu/audio_system.h @@ -84,6 +84,7 @@ protected: uint32_t callback_arg; uint32_t wrapped_callback_arg; } client_; + bool can_submit_; AudioDriver* driver_; }; diff --git a/src/xenia/apu/xaudio2/xaudio2_audio_system.cc b/src/xenia/apu/xaudio2/xaudio2_audio_system.cc index ba7cda211..1bed2d63b 100644 --- a/src/xenia/apu/xaudio2/xaudio2_audio_system.cc +++ b/src/xenia/apu/xaudio2/xaudio2_audio_system.cc @@ -67,7 +67,14 @@ void XAudio2AudioSystem::Initialize() { } void XAudio2AudioSystem::Pump() { - // + XAUDIO2_VOICE_STATE state; + pcm_voice_->GetState(&state); + auto n = state.BuffersQueued; + if (n > 30) { + can_submit_ = false; + } else { + can_submit_ = true; + } } void XAudio2AudioSystem::SubmitFrame(uint32_t samples_ptr) {