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
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
#include "XAudio2Backend.h"
|
2016-07-21 15:41:40 +02:00
|
|
|
|
#include <Windows.h>
|
2015-01-11 00:46:10 +01:00
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
XAudio2Backend::XAudio2Backend()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
XAudio2Backend::~XAudio2Backend()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
void XAudio2Backend::Play()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
lib->play();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
void XAudio2Backend::Close()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
lib->stop();
|
|
|
|
|
|
lib->flush();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
void XAudio2Backend::Pause()
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
lib->stop();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-21 02:16:54 +01:00
|
|
|
|
void XAudio2Backend::Open(u32 /* num_buffers */)
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
if (lib.get() == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
void* hmodule;
|
|
|
|
|
|
|
|
|
|
|
|
if (hmodule = LoadLibraryExW(L"XAudio2_9.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
// XAudio 2.9 uses the same code as XAudio 2.8
|
|
|
|
|
|
lib.reset(xa28_init(hmodule));
|
|
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.9 initialized");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (hmodule = LoadLibraryExW(L"XAudio2_8.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
lib.reset(xa28_init(hmodule));
|
|
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.8 initialized");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (hmodule = LoadLibraryExW(L"XAudio2_7.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
|
|
|
|
|
|
{
|
|
|
|
|
|
lib.reset(xa27_init(hmodule));
|
|
|
|
|
|
|
|
|
|
|
|
LOG_SUCCESS(GENERAL, "XAudio 2.7 initialized");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
fmt::throw_exception("No supported XAudio2 library found");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lib->open();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
bool XAudio2Backend::IsPlaying()
|
2018-12-20 23:35:49 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
return lib->is_playing();
|
2018-12-20 23:35:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-21 03:13:22 +01:00
|
|
|
|
bool XAudio2Backend::AddData(const void* src, u32 num_samples)
|
2015-01-11 00:46:10 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
return lib->add(src, num_samples);
|
2018-12-20 23:35:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
void XAudio2Backend::Flush()
|
2018-12-20 23:35:49 +01:00
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
lib->flush();
|
2015-01-11 00:46:10 +01:00
|
|
|
|
}
|
2016-04-25 12:49:12 +02:00
|
|
|
|
|
2018-12-16 18:40:50 +01:00
|
|
|
|
u64 XAudio2Backend::GetNumEnqueuedSamples()
|
|
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
return lib->enqueued_samples();
|
2018-12-16 18:40:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 22:12:58 +01:00
|
|
|
|
f32 XAudio2Backend::SetFrequencyRatio(f32 new_ratio)
|
|
|
|
|
|
{
|
2018-12-21 03:13:22 +01:00
|
|
|
|
return lib->set_freq_ratio(new_ratio);
|
2018-12-16 22:12:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-16 18:09:53 +01:00
|
|
|
|
#endif
|