From 40178cb22d2e2ef7b4e8a6f34d5acf7d8ad3e62f Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 18 Jan 2014 06:06:34 -0800 Subject: [PATCH] Minor changes to APU. --- src/xenia/apu/nop/nop_audio_system.cc | 2 +- src/xenia/apu/nop/nop_audio_system.h | 2 +- src/xenia/apu/xaudio2/xaudio2_audio_system.cc | 39 +++++++++---------- src/xenia/apu/xaudio2/xaudio2_audio_system.h | 5 ++- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/xenia/apu/nop/nop_audio_system.cc b/src/xenia/apu/nop/nop_audio_system.cc index c4f38851a..446d2078f 100644 --- a/src/xenia/apu/nop/nop_audio_system.cc +++ b/src/xenia/apu/nop/nop_audio_system.cc @@ -32,7 +32,7 @@ void NopAudioSystem::Pump() { // } -void NopAudioSystem::SubmitFrame(uint32_t samples_ptr) { +void NopAudioSystem::SubmitFrame(uint32_t frame_ptr) { // Process samples! They are big-endian floats. } diff --git a/src/xenia/apu/nop/nop_audio_system.h b/src/xenia/apu/nop/nop_audio_system.h index 5a71aaf7d..f64b0d1d0 100644 --- a/src/xenia/apu/nop/nop_audio_system.h +++ b/src/xenia/apu/nop/nop_audio_system.h @@ -28,7 +28,7 @@ public: virtual void Shutdown(); - virtual void SubmitFrame(uint32_t samples_ptr); + virtual void SubmitFrame(uint32_t frame_ptr); protected: virtual void Initialize(); diff --git a/src/xenia/apu/xaudio2/xaudio2_audio_system.cc b/src/xenia/apu/xaudio2/xaudio2_audio_system.cc index ca874e7ea..a564d7868 100644 --- a/src/xenia/apu/xaudio2/xaudio2_audio_system.cc +++ b/src/xenia/apu/xaudio2/xaudio2_audio_system.cc @@ -80,7 +80,7 @@ void XAudio2AudioSystem::Initialize() { active_channels_ = 6; XAUDIO2_DEBUG_CONFIGURATION config; - config.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS | XAUDIO2_LOG_INFO | XAUDIO2_LOG_DETAIL | XAUDIO2_LOG_STREAMING; + config.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS; config.BreakMask = 0; config.LogThreadID = FALSE; config.LogTiming = TRUE; @@ -97,7 +97,8 @@ void XAudio2AudioSystem::Initialize() { WAVEFORMATIEEEFLOATEX waveformat; - waveformat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + //waveformat.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + waveformat.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; waveformat.Format.nChannels = active_channels_; waveformat.Format.nSamplesPerSec = 48000; waveformat.Format.wBitsPerSample = 32; @@ -110,7 +111,7 @@ void XAudio2AudioSystem::Initialize() { waveformat.dwChannelMask = ChannelMasks[waveformat.Format.nChannels]; hr = audio_->CreateSourceVoice(&pcm_voice_, &waveformat.Format, - XAUDIO2_VOICE_NOPITCH | XAUDIO2_VOICE_NOSRC, + 0, XAUDIO2_DEFAULT_FREQ_RATIO, voice_callback_); if (FAILED(hr)) { XELOGE("CreateSourceVoice failed with %.8X", hr); @@ -129,33 +130,37 @@ void XAudio2AudioSystem::Pump() { // Only allow one buffer to be queued at once. We only have one static // store of data, and if we called back the game audio driver it would // overwrite it. - ResetEvent(wait_handle_); + //ResetEvent(wait_handle_); } WaitForSingleObject(wait_handle_, INFINITE); } -void XAudio2AudioSystem::SubmitFrame(uint32_t samples_ptr) { +void XAudio2AudioSystem::SubmitFrame(uint32_t frame_ptr) { + ResetEvent(wait_handle_); + // Process samples! They are big-endian floats. HRESULT hr; - auto samples = reinterpret_cast( - emulator_->memory()->membase() + samples_ptr); + auto input_frame = reinterpret_cast(emulator_->memory()->membase() + frame_ptr); + auto output_frame = reinterpret_cast(frame_); // interleave the data - for (int i = 0, o = 0; i < 256; ++i) { - for (int j = 0; j < 6 && j < active_channels_; ++j) { - samples_[o++] = XESWAPF32BE(*(samples + (j * 256) + i)); + for (int index = 0, o = 0; index < 256; ++index) { + for (int channel = 0, table = 0; + channel < 6 && channel < active_channels_; + ++channel, table += 256) { + output_frame[o++] = XESWAPF32BE(input_frame[table + index]); } } XAUDIO2_BUFFER buffer; - buffer.Flags = XAUDIO2_END_OF_STREAM; - buffer.pAudioData = reinterpret_cast(samples_); - buffer.AudioBytes = sizeof(samples_); + buffer.Flags = 0; + buffer.pAudioData = reinterpret_cast(frame_); + buffer.AudioBytes = sizeof(frame_); buffer.PlayBegin = 0; buffer.PlayLength = 256; - buffer.LoopBegin = 0; + buffer.LoopBegin = XAUDIO2_NO_LOOP_REGION; buffer.LoopLength = 0; buffer.LoopCount = 0; buffer.pContext = 0; @@ -165,12 +170,6 @@ void XAudio2AudioSystem::SubmitFrame(uint32_t samples_ptr) { XEASSERTALWAYS(); return; } - hr = pcm_voice_->Start(0); - if (FAILED(hr)) { - XELOGE("Start failed with %.8X", hr); - XEASSERTALWAYS(); - return; - } } void XAudio2AudioSystem::Shutdown() { diff --git a/src/xenia/apu/xaudio2/xaudio2_audio_system.h b/src/xenia/apu/xaudio2/xaudio2_audio_system.h index 1a3fcf423..0befa2a5d 100644 --- a/src/xenia/apu/xaudio2/xaudio2_audio_system.h +++ b/src/xenia/apu/xaudio2/xaudio2_audio_system.h @@ -30,7 +30,7 @@ public: virtual void Shutdown(); - virtual void SubmitFrame(uint32_t samples_ptr); + virtual void SubmitFrame(uint32_t frame_ptr); protected: virtual void Initialize(); @@ -41,7 +41,8 @@ private: IXAudio2MasteringVoice* mastering_voice_; IXAudio2SourceVoice* pcm_voice_; int active_channels_; - float samples_[1536]; + static const int frame_channels_ = 6; + float frame_[frame_channels_ * 256]; HANDLE wait_handle_; class VoiceCallback;