Refactor audio buffering API, this should mainly prevent SDL audio driver from allocating memory in the mixer callback.

This commit is contained in:
elasota
2021-04-25 00:34:02 -04:00
parent f9d3b91f72
commit 5d9dde6589
17 changed files with 374 additions and 180 deletions

View File

@@ -1,3 +1,4 @@
#include "GpAudioBufferXAudio2.h"
#include "GpAudioChannelXAudio2.h"
#include "GpAudioDriverXAudio2.h"
#include "IGpAudioChannelCallbacks.h"
@@ -77,25 +78,25 @@ void GpAudioChannelXAudio2::SetAudioChannelContext(IGpAudioChannelCallbacks *cal
m_contextCallbacks = callbacks;
}
void GpAudioChannelXAudio2::PostBuffer(const void *buffer, size_t bufferSize)
bool GpAudioChannelXAudio2::PostBuffer(IGpAudioBuffer *buffer)
{
XAUDIO2_BUFFER xa2Buffer;
xa2Buffer.Flags = 0;
xa2Buffer.AudioBytes = static_cast<UINT32>(bufferSize);
xa2Buffer.pAudioData = static_cast<const BYTE*>(buffer);
xa2Buffer.PlayBegin = 0;
xa2Buffer.PlayLength = 0;
xa2Buffer.LoopBegin = 0;
xa2Buffer.LoopLength = 0;
xa2Buffer.LoopCount = 0;
xa2Buffer.pContext = nullptr;
GpAudioBufferXAudio2 *xa2Buffer = static_cast<GpAudioBufferXAudio2*>(buffer);
xa2Buffer->AddRef();
HRESULT result = m_sourceVoice->SubmitSourceBuffer(xa2Buffer->GetXA2Buffer(), nullptr);
if (result != S_OK)
{
xa2Buffer->Release();
return false;
}
m_sourceVoice->SubmitSourceBuffer(&xa2Buffer, nullptr);
if (m_voiceState == VoiceState_Idle)
{
m_voiceState = VoiceState_Active;
m_sourceVoice->Start(0, 0);
}
return true;
}
void GpAudioChannelXAudio2::Stop()