2018-12-20 23:35:49 +01:00
|
|
|
|
#ifdef _WIN32
|
2016-07-21 15:41:40 +02:00
|
|
|
|
|
2016-04-25 12:49:12 +02:00
|
|
|
|
#include "Utilities/Log.h"
|
2016-04-27 00:27:24 +02:00
|
|
|
|
#include "Utilities/StrFmt.h"
|
2015-10-26 22:09:31 +01:00
|
|
|
|
|
2015-01-11 00:46:10 +01:00
|
|
|
|
#include "XAudio2Thread.h"
|
2016-07-21 15:41:40 +02:00
|
|
|
|
#include <Windows.h>
|
2015-01-11 00:46:10 +01:00
|
|
|
|
|
2016-02-01 22:51:35 +01:00
|
|
|
|
XAudio2Thread::XAudio2Thread()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2016-08-06 14:40:51 +02:00
|
|
|
|
if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_ERROR(GENERAL, "XAudio: failed to increase thread priority");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-30 16:10:01 +02:00
|
|
|
|
if (auto lib2_9 = LoadLibraryExW(L"XAudio2_9.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
// xa28* implementation is fully compatible with library 2.9
|
|
|
|
|
|
xa28_init(lib2_9);
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
m_funcs.destroy = &xa28_destroy;
|
|
|
|
|
|
m_funcs.play = &xa28_play;
|
|
|
|
|
|
m_funcs.flush = &xa28_flush;
|
|
|
|
|
|
m_funcs.stop = &xa28_stop;
|
|
|
|
|
|
m_funcs.open = &xa28_open;
|
|
|
|
|
|
m_funcs.is_playing = &xa28_is_playing;
|
|
|
|
|
|
m_funcs.add = &xa28_add;
|
2016-07-30 16:10:01 +02:00
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.9 initialized");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-09 09:55:11 +02:00
|
|
|
|
if (auto lib2_7 = LoadLibraryExW(L"XAudio2_7.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
xa27_init(lib2_7);
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
m_funcs.destroy = &xa27_destroy;
|
|
|
|
|
|
m_funcs.play = &xa27_play;
|
|
|
|
|
|
m_funcs.flush = &xa27_flush;
|
|
|
|
|
|
m_funcs.stop = &xa27_stop;
|
|
|
|
|
|
m_funcs.open = &xa27_open;
|
|
|
|
|
|
m_funcs.is_playing = &xa27_is_playing;
|
|
|
|
|
|
m_funcs.add = &xa27_add;
|
2016-08-09 09:55:11 +02:00
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.7 initialized");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-30 16:10:01 +02:00
|
|
|
|
if (auto lib2_8 = LoadLibraryExW(L"XAudio2_8.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
xa28_init(lib2_8);
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
m_funcs.destroy = &xa28_destroy;
|
|
|
|
|
|
m_funcs.play = &xa28_play;
|
|
|
|
|
|
m_funcs.flush = &xa28_flush;
|
|
|
|
|
|
m_funcs.stop = &xa28_stop;
|
|
|
|
|
|
m_funcs.open = &xa28_open;
|
|
|
|
|
|
m_funcs.is_playing = &xa28_is_playing;
|
|
|
|
|
|
m_funcs.add = &xa28_add;
|
2016-07-30 16:10:01 +02:00
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.8 initialized");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-08 18:01:06 +02:00
|
|
|
|
fmt::throw_exception("No supported XAudio2 library found");
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-01 22:51:35 +01:00
|
|
|
|
XAudio2Thread::~XAudio2Thread()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2016-07-30 16:10:01 +02:00
|
|
|
|
m_funcs.destroy();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XAudio2Thread::Play()
|
|
|
|
|
|
{
|
2016-07-30 16:10:01 +02:00
|
|
|
|
m_funcs.play();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XAudio2Thread::Close()
|
|
|
|
|
|
{
|
2016-07-30 16:10:01 +02:00
|
|
|
|
m_funcs.stop();
|
|
|
|
|
|
m_funcs.flush();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
void XAudio2Thread::Pause()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2016-07-30 16:10:01 +02:00
|
|
|
|
m_funcs.stop();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
void XAudio2Thread::Open()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2016-07-30 16:10:01 +02:00
|
|
|
|
m_funcs.open();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-20 23:35:49 +01:00
|
|
|
|
bool XAudio2Thread::IsPlaying()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_funcs.is_playing();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool XAudio2Thread::AddData(const void* src, int size)
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-20 23:35:49 +01:00
|
|
|
|
return m_funcs.add(src, size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XAudio2Thread::Flush()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_funcs.flush();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
2016-04-25 12:49:12 +02:00
|
|
|
|
|
2015-01-16 18:09:53 +01:00
|
|
|
|
#endif
|