rpcsx/rpcs3/Emu/Audio/XAudio2/XAudio2Backend.cpp

113 lines
2.3 KiB
C++
Raw Normal View History

2018-12-20 23:35:49 +01:00
#ifdef _WIN32
2016-07-21 15:41:40 +02:00
#include "Utilities/Log.h"
#include "Utilities/StrFmt.h"
#include "XAudio2Backend.h"
2016-07-21 15:41:40 +02:00
#include <Windows.h>
XAudio2Backend::XAudio2Backend()
{
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;
m_funcs.enqueued_samples = &xa28_enqueued_samples;
2016-07-30 16:10:01 +02:00
LOG_SUCCESS(GENERAL, "XAudio 2.9 initialized");
return;
}
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;
m_funcs.enqueued_samples = &xa28_enqueued_samples;
2016-07-30 16:10:01 +02:00
LOG_SUCCESS(GENERAL, "XAudio 2.8 initialized");
return;
}
if (auto lib2_7 = LoadLibraryExW(L"XAudio2_7.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))
{
xa27_init(lib2_7);
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;
m_funcs.enqueued_samples = &xa27_enqueued_samples;
LOG_SUCCESS(GENERAL, "XAudio 2.7 initialized");
return;
}
fmt::throw_exception("No supported XAudio2 library found");
}
XAudio2Backend::~XAudio2Backend()
{
2016-07-30 16:10:01 +02:00
m_funcs.destroy();
}
void XAudio2Backend::Play()
{
2016-07-30 16:10:01 +02:00
m_funcs.play();
}
void XAudio2Backend::Close()
{
2016-07-30 16:10:01 +02:00
m_funcs.stop();
m_funcs.flush();
}
void XAudio2Backend::Pause()
{
2016-07-30 16:10:01 +02:00
m_funcs.stop();
}
void XAudio2Backend::Open()
{
2016-07-30 16:10:01 +02:00
m_funcs.open();
}
bool XAudio2Backend::IsPlaying()
2018-12-20 23:35:49 +01:00
{
return m_funcs.is_playing();
}
bool XAudio2Backend::AddData(const void* src, int size)
{
2018-12-20 23:35:49 +01:00
return m_funcs.add(src, size);
}
void XAudio2Backend::Flush()
2018-12-20 23:35:49 +01:00
{
m_funcs.flush();
}
u64 XAudio2Backend::GetNumEnqueuedSamples()
{
return m_funcs.enqueued_samples();
}
2015-01-16 18:09:53 +01:00
#endif