diff --git a/audio/drivers/xaudio.cpp b/audio/drivers/xaudio.c
similarity index 94%
rename from audio/drivers/xaudio.cpp
rename to audio/drivers/xaudio.c
index 37a9abcd74..ef730aeab1 100644
--- a/audio/drivers/xaudio.cpp
+++ b/audio/drivers/xaudio.c
@@ -100,7 +100,7 @@ static void WINAPI voice_on_buffer_end(void *handle_, void *data)
{
(void)data;
xaudio2_t *handle = (xaudio2_t*)handle_;
- InterlockedDecrement(&handle->buffers);
+ InterlockedDecrement((__LONG32 volatile*)&handle->buffers);
SetEvent(handle->hEvent);
}
@@ -118,7 +118,9 @@ const struct IXAudio2VoiceCallbackVtbl voice_vtable = {
dummy_voidp,
dummy_voidp_hresult,
};
+#endif
+#if 0
static void xaudio2_enumerate_devices(xaudio2_t *xa)
{
uint32_t dev_count = 0;
@@ -128,13 +130,21 @@ static void xaudio2_enumerate_devices(xaudio2_t *xa)
(void)i;
(void)dev_count;
#ifndef _XBOX
+#ifdef __cplusplus
xa->pXAudio2->GetDeviceCount(&dev_count);
+#else
+ IXAudio2_GetDeviceCount(xa->pXAudio2, &dev_count);
+#endif
fprintf(stderr, "XAudio2 devices:\n");
for (i = 0; i < dev_count; i++)
{
XAUDIO2_DEVICE_DETAILS dev_detail;
+#ifdef __cplusplus
xa->pXAudio2->GetDeviceDetails(i, &dev_detail);
+#else
+ IXAudio2_GetDeviceDetails(xa->pXAudio2, i, &dev_detail);
+#endif
fwprintf(stderr, L"\t%u: %s\n", i, dev_detail.DisplayName);
}
#endif
@@ -224,6 +234,10 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
if (!handle)
goto error;
+#ifndef __cplusplus
+ handle->lpVtbl = &voice_vtable;
+#endif
+
if (FAILED(XAudio2Create(&handle->pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)))
goto error;
@@ -244,8 +258,9 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
handle)))
goto error;
#else
- if (FAILED(IXAudio2_CreateSourceVoice(handle->pXAudio2->CreateSourceVoice, &wfx,
- XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO,
+ if (FAILED(IXAudio2_CreateSourceVoice(handle->pXAudio2,
+ &handle->pSourceVoice, &wfx,
+ XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO,
(IXAudio2VoiceCallback*)handle, 0, 0)))
goto error;
#endif
@@ -289,7 +304,8 @@ static size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes_)
{
unsigned need = MIN(bytes, handle->bufsize - handle->bufptr);
- memcpy(handle->buf + handle->write_buffer * handle->bufsize + handle->bufptr,
+ memcpy(handle->buf + handle->write_buffer *
+ handle->bufsize + handle->bufptr,
buffer, need);
handle->bufptr += need;
diff --git a/audio/drivers/xaudio.h b/audio/drivers/xaudio.h
index 2378665da7..dbb46c5db6 100644
--- a/audio/drivers/xaudio.h
+++ b/audio/drivers/xaudio.h
@@ -15,16 +15,21 @@
* If not, see .
*/
-// Kinda stripped down. Only contains the bare essentials used in RetroArch.
+/* Kinda stripped down. Only contains the bare essentials used in RetroArch. */
#ifndef XAUDIO2_STRIPPED_H
#define XAUDIO2_STRIPPED_H
#include
-// All structures defined in this file use tight field packing
+/* All structures defined in this file use tight field packing */
#pragma pack(push, 1)
+
+#ifdef __cplusplus
#define X2DEFAULT(x) = (x)
+#else
+#define X2DEFAULT(x)
+#endif
#ifdef _XBOX
#include
@@ -41,7 +46,7 @@ DEFINE_CLSID(XAudio2, 3eda9b49, 2085, 498b, 9b, b2, 39, a6, 77, 84, 93, de);
DEFINE_CLSID(XAudio2_Debug, 47199894, 7cc2, 444d, 98, 73, ce, d2, 56, 2c, c6, 0e);
DEFINE_IID(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
-#include // Basic audio data types and constants
+#include /* Basic audio data types and constants */
#else
@@ -51,6 +56,11 @@ DEFINE_IID(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
#include
#include
+#ifndef __cplusplus
+#undef OPAQUE
+#define OPAQUE struct
+#endif
+
#define DEFINE_GUID_X(n, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
static const GUID n = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#define DEFINE_CLSID_X(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
@@ -58,7 +68,13 @@ DEFINE_IID(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
#define DEFINE_IID_X(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
DEFINE_GUID_X(IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
-DEFINE_CLSID_X(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af); // 2.7
+#ifndef __cplusplus
+#ifndef INTERFACE
+#define INTERFACE void
+#endif
+#endif
+
+DEFINE_CLSID_X(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af); /* 2.7 */
DEFINE_IID_X(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
#endif
@@ -121,7 +137,8 @@ typedef struct XAUDIO2_DEVICE_DETAILS
WAVEFORMATEXTENSIBLE OutputFormat;
} XAUDIO2_DEVICE_DETAILS;
-// Forward declarations.
+/* Forward declarations. */
+#ifdef __cplusplus
struct XAUDIO2_VOICE_DETAILS;
struct XAUDIO2_VOICE_SENDS;
struct XAUDIO2_EFFECT_DESCRIPTOR;
@@ -133,6 +150,20 @@ struct XAUDIO2_PERFORMANCE_DATA;
struct XAUDIO2_DEBUG_CONFIGURATION;
struct IXAudio2EngineCallback;
struct IXAudio2SubmixVoice;
+#else
+typedef OPAQUE XAUDIO2_VOICE_DETAILS XAUDIO2_VOICE_DETAILS;
+typedef OPAQUE XAUDIO2_VOICE_SENDS XAUDIO2_VOICE_SENDS;
+typedef OPAQUE XAUDIO2_EFFECT_DESCRIPTOR XAUDIO2_EFFECT_DESCRIPTOR;
+typedef OPAQUE XAUDIO2_EFFECT_CHAIN XAUDIO2_EFFECT_CHAIN;
+typedef OPAQUE XAUDIO2_FILTER_PARAMETERS XAUDIO2_FILTER_PARAMETERS;
+typedef OPAQUE XAUDIO2_BUFFER_WMA XAUDIO2_BUFFER_WMA;
+typedef OPAQUE XAUDIO2_VOICE_STATE XAUDIO2_VOICE_STATE;
+typedef OPAQUE XAUDIO2_PERFORMANCE_DATA XAUDIO2_PERFORMANCE_DATA;
+typedef OPAQUE XAUDIO2_DEBUG_CONFIGURATION XAUDIO2_DEBUG_CONFIGURATION;
+typedef OPAQUE IXAudio2EngineCallback IXAudio2EngineCallback;
+typedef OPAQUE IXAudio2SubmixVoice IXAudio2SubmixVoice;
+#endif
+
typedef struct XAUDIO2_BUFFER
{
@@ -256,31 +287,60 @@ DECLARE_INTERFACE_(IXAudio2, IUnknown)
void *pReserved X2DEFAULT(NULL)) PURE;
};
+#ifndef __cplusplus
+/* C hooks */
+#define IXAudio2_Initialize(THIS, ...) (THIS)->lpVtbl->Initialize(THIS, __VA_ARGS__)
+#define IXAudio2_Release(THIS) (THIS)->lpVtbl->Release(THIS)
+#define IXAudio2_CreateSourceVoice(THIS, ...) (THIS)->lpVtbl->CreateSourceVoice(THIS, __VA_ARGS__)
+#define IXAudio2_CreateMasteringVoice(THIS, ...) (THIS)->lpVtbl->CreateMasteringVoice(THIS, __VA_ARGS__)
+#define IXAudio2_GetDeviceCount(THIS, ...) (THIS)->lpVtbl->GetDeviceCount(THIS, __VA_ARGS__)
+#define IXAudio2_GetDeviceDetails(THIS, ...) (THIS)->lpVtbl->GetDeviceDetails(THIS, __VA_ARGS__)
+#define IXAudio2SourceVoice_Start(THIS, ...) (THIS)->lpVtbl->Start(THIS, __VA_ARGS__)
+#define IXAudio2SourceVoice_Stop(THIS, ...) (THIS)->lpVtbl->Stop(THIS, __VA_ARGS__)
+#define IXAudio2SourceVoice_SubmitSourceBuffer(THIS, ...) (THIS)->lpVtbl->SubmitSourceBuffer(THIS, __VA_ARGS__)
+#define IXAudio2SourceVoice_DestroyVoice(THIS) (THIS)->lpVtbl->DestroyVoice(THIS)
+#define IXAudio2MasteringVoice_DestroyVoice(THIS) (THIS)->lpVtbl->DestroyVoice(THIS)
+#endif
+
#ifdef _XBOX
STDAPI XAudio2Create(__deref_out IXAudio2** ppXAudio2, UINT32 Flags X2DEFAULT(0),
XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR));
#else
-static INLINE HRESULT XAudio2Create(IXAudio2 **ppXAudio2, UINT32, XAUDIO2_PROCESSOR)
+static INLINE HRESULT XAudio2Create(IXAudio2 **ppXAudio2, UINT32 flags, XAUDIO2_PROCESSOR proc)
{
IXAudio2 *pXAudio2;
+ (void)flags;
+ (void)proc;
+#ifdef __cplusplus
HRESULT hr = CoCreateInstance(CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, IID_IXAudio2, (void**)&pXAudio2);
+#else
+ HRESULT hr = CoCreateInstance(&CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, &IID_IXAudio2, (void**)&pXAudio2);
+#endif
if (SUCCEEDED(hr))
{
- //hr = IXAudio2_Initialize(pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR);
+#ifdef __cplusplus
hr = pXAudio2->Initialize(0, XAUDIO2_DEFAULT_PROCESSOR);
+#else
+ hr = IXAudio2_Initialize(pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR);
+#endif
if (SUCCEEDED(hr))
*ppXAudio2 = pXAudio2;
else
- //IXAudio2_Release(pXAudio2);
+ {
+#ifdef __cplusplus
pXAudio2->Release();
+#else
+ IXAudio2_Release(pXAudio2);
+#endif
+ }
}
return hr;
}
#endif
-// Undo the #pragma pack(push, 1) directive at the top of this file
+/* Undo the #pragma pack(push, 1) directive at the top of this file */
#pragma pack(pop)
#endif
diff --git a/griffin/griffin.c b/griffin/griffin.c
index f6bf342a6f..35d69df7c1 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -662,6 +662,10 @@ AUDIO
#include "../audio/drivers/ctr_dsp_audio.c"
#endif
+#ifdef HAVE_XAUDIO
+#include "../audio/drivers/xaudio.c"
+#endif
+
#if defined(HAVE_SDL2)
#include "../audio/drivers/sdl_audio.c"
#endif
diff --git a/griffin/griffin_cpp.cpp b/griffin/griffin_cpp.cpp
index eb2c7358f6..a39ac7428d 100644
--- a/griffin/griffin_cpp.cpp
+++ b/griffin/griffin_cpp.cpp
@@ -90,13 +90,6 @@
#endif
#endif
-/*============================================================
-AUDIO
-============================================================ */
-#ifdef HAVE_XAUDIO
-#include "../audio/drivers/xaudio.cpp"
-#endif
-
/*============================================================
MENU
============================================================ */