From c57640dfbd53b80b71d62b53c1f87a7f5fade12b Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 1 Jul 2012 17:07:58 +1000 Subject: [PATCH] Implemented proper timing in the "No audio output" back-end. --- Source/Core/AudioCommon/Src/NullSoundStream.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Core/AudioCommon/Src/NullSoundStream.cpp b/Source/Core/AudioCommon/Src/NullSoundStream.cpp index f42df9cc1f..db67b08a15 100644 --- a/Source/Core/AudioCommon/Src/NullSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/NullSoundStream.cpp @@ -17,6 +17,8 @@ #include "AudioCommon.h" #include "NullSoundStream.h" +#include "../../Core/Src/HW/SystemTimers.h" +#include "../../Core/Src/HW/AudioInterface.h" void NullSound::SoundLoop() { @@ -33,9 +35,14 @@ void NullSound::SetVolume(int volume) void NullSound::Update() { - // This should equal AUDIO_DMA_PERIOD. TODO: Fix after DSP merge - int numBytesToRender = 32000 * 4 / 32; - m_mixer->Mix(realtimeBuffer, numBytesToRender / 4); + // num_samples_to_render in this update - depends on SystemTimers::AUDIO_DMA_PERIOD. + const u32 stereo_16_bit_size = 4; + const u32 dma_length = 32; + const u64 audio_dma_period = SystemTimers::GetTicksPerSecond() / (AudioInterface::GetAIDSampleRate() * stereo_16_bit_size / dma_length); + const u64 ais_samples_per_second = 48000 * stereo_16_bit_size; + const u64 num_samples_to_render = (audio_dma_period * ais_samples_per_second) / SystemTimers::GetTicksPerSecond(); + + m_mixer->Mix(realtimeBuffer, (unsigned int)num_samples_to_render); } void NullSound::Clear(bool mute)