mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Fix audio driver starting in debug mode, add -diagnostics mode
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "GpAudioDriverXAudio2.h"
|
||||
|
||||
#include "IGpLogDriver.h"
|
||||
#include "GpAudioChannelXAudio2.h"
|
||||
|
||||
#include <xaudio2.h>
|
||||
@@ -31,34 +32,62 @@ unsigned int GpAudioDriverXAudio2::GetRealSampleRate() const
|
||||
|
||||
GpAudioDriverXAudio2 *GpAudioDriverXAudio2::Create(const GpAudioDriverProperties &properties)
|
||||
{
|
||||
IGpLogDriver *logger = properties.m_logger;
|
||||
|
||||
IXAudio2 *xa = nullptr;
|
||||
IXAudio2MasteringVoice *mv = nullptr;
|
||||
|
||||
const unsigned int realSampleRate = (properties.m_sampleRate + 50) / XAUDIO2_QUANTUM_DENOMINATOR * XAUDIO2_QUANTUM_DENOMINATOR;
|
||||
|
||||
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) != S_OK)
|
||||
if (logger)
|
||||
{
|
||||
logger->Printf(IGpLogDriver::Category_Information, "XAudio2 Driver starting");
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Real sample rate: %u", realSampleRate);
|
||||
}
|
||||
|
||||
HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Error, "CoInitializeEx failed with code %lx", result);
|
||||
|
||||
CoUninitialize();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UINT flags = 0;
|
||||
if (properties.m_debug)
|
||||
flags |= XAUDIO2_DEBUG_ENGINE;
|
||||
|
||||
if (FAILED(XAudio2Create(&xa, flags, XAUDIO2_DEFAULT_PROCESSOR)))
|
||||
{
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Starting XAudio in debug mode");
|
||||
|
||||
flags |= XAUDIO2_DEBUG_ENGINE;
|
||||
}
|
||||
|
||||
result = XAudio2Create(&xa, flags, XAUDIO2_DEFAULT_PROCESSOR);
|
||||
if (FAILED(result))
|
||||
{
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Error, "XAudio2Create failed with code %lx", result);
|
||||
|
||||
CoUninitialize();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (FAILED(xa->CreateMasteringVoice(&mv, 2, realSampleRate, 0, nullptr, nullptr, AudioCategory_GameEffects)))
|
||||
result = xa->CreateMasteringVoice(&mv, 2, realSampleRate, 0, nullptr, nullptr, AudioCategory_GameEffects);
|
||||
if (FAILED(result))
|
||||
{
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Error, "CreateMasteringVoice failed with code %lx", result);
|
||||
|
||||
CoUninitialize();
|
||||
xa->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "XAudio2 started OK", result);
|
||||
|
||||
return new GpAudioDriverXAudio2(properties, realSampleRate, xa, mv);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user