[APU] Handle XAudio2 initialization failures
This commit is contained in:
parent
da62e0e044
commit
25206be1aa
|
@ -64,7 +64,7 @@ const DWORD ChannelMasks[] = {
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
void XAudio2AudioDriver::Initialize() {
|
bool XAudio2AudioDriver::Initialize() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
voice_callback_ = new VoiceCallback(semaphore_);
|
voice_callback_ = new VoiceCallback(semaphore_);
|
||||||
|
@ -73,7 +73,7 @@ void XAudio2AudioDriver::Initialize() {
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
XELOGE("XAudio2Create failed with %.8X", hr);
|
XELOGE("XAudio2Create failed with %.8X", hr);
|
||||||
assert_always();
|
assert_always();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
XAUDIO2_DEBUG_CONFIGURATION config;
|
XAUDIO2_DEBUG_CONFIGURATION config;
|
||||||
|
@ -89,7 +89,7 @@ void XAudio2AudioDriver::Initialize() {
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
XELOGE("CreateMasteringVoice failed with %.8X", hr);
|
XELOGE("CreateMasteringVoice failed with %.8X", hr);
|
||||||
assert_always();
|
assert_always();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WAVEFORMATIEEEFLOATEX waveformat;
|
WAVEFORMATIEEEFLOATEX waveformat;
|
||||||
|
@ -116,19 +116,21 @@ void XAudio2AudioDriver::Initialize() {
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
XELOGE("CreateSourceVoice failed with %.8X", hr);
|
XELOGE("CreateSourceVoice failed with %.8X", hr);
|
||||||
assert_always();
|
assert_always();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = pcm_voice_->Start();
|
hr = pcm_voice_->Start();
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
XELOGE("Start failed with %.8X", hr);
|
XELOGE("Start failed with %.8X", hr);
|
||||||
assert_always();
|
assert_always();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FLAGS_mute) {
|
if (FLAGS_mute) {
|
||||||
pcm_voice_->SetVolume(0.0f);
|
pcm_voice_->SetVolume(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XAudio2AudioDriver::SubmitFrame(uint32_t frame_ptr) {
|
void XAudio2AudioDriver::SubmitFrame(uint32_t frame_ptr) {
|
||||||
|
@ -177,17 +179,27 @@ void XAudio2AudioDriver::SubmitFrame(uint32_t frame_ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void XAudio2AudioDriver::Shutdown() {
|
void XAudio2AudioDriver::Shutdown() {
|
||||||
|
if (pcm_voice_) {
|
||||||
pcm_voice_->Stop();
|
pcm_voice_->Stop();
|
||||||
pcm_voice_->DestroyVoice();
|
pcm_voice_->DestroyVoice();
|
||||||
pcm_voice_ = NULL;
|
pcm_voice_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mastering_voice_) {
|
||||||
mastering_voice_->DestroyVoice();
|
mastering_voice_->DestroyVoice();
|
||||||
mastering_voice_ = NULL;
|
mastering_voice_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audio_) {
|
||||||
audio_->StopEngine();
|
audio_->StopEngine();
|
||||||
audio_->Release();
|
audio_->Release();
|
||||||
|
audio_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (voice_callback_) {
|
||||||
delete voice_callback_;
|
delete voice_callback_;
|
||||||
|
voice_callback_ = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xaudio2
|
} // namespace xaudio2
|
||||||
|
|
|
@ -26,7 +26,7 @@ class XAudio2AudioDriver : public AudioDriver {
|
||||||
XAudio2AudioDriver(Memory* memory, xe::threading::Semaphore* semaphore);
|
XAudio2AudioDriver(Memory* memory, xe::threading::Semaphore* semaphore);
|
||||||
~XAudio2AudioDriver() override;
|
~XAudio2AudioDriver() override;
|
||||||
|
|
||||||
void Initialize();
|
bool Initialize();
|
||||||
void SubmitFrame(uint32_t frame_ptr) override;
|
void SubmitFrame(uint32_t frame_ptr) override;
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,11 @@ X_STATUS XAudio2AudioSystem::CreateDriver(size_t index,
|
||||||
AudioDriver** out_driver) {
|
AudioDriver** out_driver) {
|
||||||
assert_not_null(out_driver);
|
assert_not_null(out_driver);
|
||||||
auto driver = new XAudio2AudioDriver(memory_, semaphore);
|
auto driver = new XAudio2AudioDriver(memory_, semaphore);
|
||||||
driver->Initialize();
|
if (!driver->Initialize()) {
|
||||||
|
driver->Shutdown();
|
||||||
|
return X_STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
*out_driver = driver;
|
*out_driver = driver;
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue