summaryrefslogtreecommitdiff
path: root/drivers/xaudio2
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2016-10-17 14:42:05 -0200
committerGeorge Marques <george@gmarqu.es>2016-10-17 20:42:37 -0200
commit05bf24b9a5208dbfcde8006cfc0625e57125107e (patch)
treea22ee8162311ef0a03a4a2f24c031d4e19212769 /drivers/xaudio2
parentf3102160a1c0280ddd3e1873a50a2efddfe8c35b (diff)
Fix memory management of XAudio2 driver
Diffstat (limited to 'drivers/xaudio2')
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.cpp11
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.h2
2 files changed, 5 insertions, 8 deletions
diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp
index 033e840ab1..c7a8962102 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.cpp
+++ b/drivers/xaudio2/audio_driver_xaudio2.cpp
@@ -80,9 +80,7 @@ Error AudioDriverXAudio2::init() {
wave_format.nBlockAlign = channels * wave_format.wBitsPerSample >> 3;
wave_format.nAvgBytesPerSec = mix_rate * wave_format.nBlockAlign;
- voice_callback = memnew(XAudio2DriverVoiceCallback);
-
- hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, voice_callback);
+ hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback);
if (hr != S_OK) {
ERR_EXPLAIN("Error creating XAudio2 source voice. " + itos(hr));
ERR_FAIL_V(ERR_UNAVAILABLE);
@@ -133,7 +131,7 @@ void AudioDriverXAudio2::thread_func(void* p_udata) {
XAUDIO2_VOICE_STATE state;
while (ad->source_voice->GetState(&state), state.BuffersQueued > AUDIO_BUFFERS - 1)
{
- WaitForSingleObject(ad->voice_callback->buffer_end_event, INFINITE);
+ WaitForSingleObject(ad->voice_callback.buffer_end_event, INFINITE);
}
}
@@ -197,7 +195,7 @@ void AudioDriverXAudio2::finish() {
if (source_voice) {
source_voice->Stop(0);
- memdelete(source_voice);
+ source_voice->DestroyVoice();
}
if (samples_in) {
@@ -209,8 +207,7 @@ void AudioDriverXAudio2::finish() {
}
};
- memdelete(voice_callback);
- memdelete(mastering_voice);
+ mastering_voice->DestroyVoice();
memdelete(thread);
if (mutex)
diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h
index 787a476b93..1c6a90500d 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.h
+++ b/drivers/xaudio2/audio_driver_xaudio2.h
@@ -87,7 +87,7 @@ class AudioDriverXAudio2 : public AudioDriverSW {
IXAudio2MasteringVoice* mastering_voice;
XAUDIO2_BUFFER xaudio_buffer[AUDIO_BUFFERS];
IXAudio2SourceVoice* source_voice;
- XAudio2DriverVoiceCallback* voice_callback;
+ XAudio2DriverVoiceCallback voice_callback;
public: