2012-04-21 23:13:50 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2020-05-11 03:49:16 +02:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-12-11 23:55:31 -08:00
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-01-27 01:46:00 +01:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-01-27 01:46:00 +01:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 23:31:57 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-01-27 01:46:00 +01:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2006-01-17 04:36:32 +01:00
|
|
|
#if !defined(_XBOX) && (_MSC_VER == 1310)
|
|
|
|
#ifndef _WIN32_DCOM
|
|
|
|
#define _WIN32_DCOM
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-09-05 14:01:03 +02:00
|
|
|
#include <stdint.h>
|
2015-04-03 02:29:20 +02:00
|
|
|
#include <stddef.h>
|
2011-01-27 01:46:00 +01:00
|
|
|
#include <stdlib.h>
|
2015-09-05 14:01:03 +02:00
|
|
|
#include <boolean.h>
|
|
|
|
|
|
|
|
#include <compat/msvc.h>
|
2015-11-24 00:38:48 +01:00
|
|
|
#include <retro_miscellaneous.h>
|
2019-07-26 03:39:46 +02:00
|
|
|
#include <string/stdstring.h>
|
|
|
|
#include <encodings/utf.h>
|
|
|
|
#include <lists/string_list.h>
|
2015-09-05 14:01:03 +02:00
|
|
|
|
2017-01-14 04:06:56 -05:00
|
|
|
#if defined(_MSC_VER) && (_WIN32_WINNT <= _WIN32_WINNT_WIN2K)
|
|
|
|
/* needed for CoInitializeEx */
|
|
|
|
#define _WIN32_DCOM
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 02:29:20 +02:00
|
|
|
#include "xaudio.h"
|
2015-09-05 14:01:03 +02:00
|
|
|
|
2019-07-26 03:39:46 +02:00
|
|
|
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
|
|
|
#include "../common/mmdevice_common.h"
|
|
|
|
#endif
|
|
|
|
|
2019-06-17 12:49:21 +02:00
|
|
|
#include "../../retroarch.h"
|
2015-11-23 12:14:53 +01:00
|
|
|
#include "../../verbosity.h"
|
2011-01-27 01:46:00 +01:00
|
|
|
|
2015-04-03 02:29:20 +02:00
|
|
|
typedef struct xaudio2 xaudio2_t;
|
|
|
|
|
|
|
|
#define MAX_BUFFERS 16
|
|
|
|
|
|
|
|
#define MAX_BUFFERS_MASK (MAX_BUFFERS - 1)
|
|
|
|
|
2017-12-25 08:11:10 +01:00
|
|
|
#ifndef COINIT_MULTITHREADED
|
|
|
|
#define COINIT_MULTITHREADED 0x00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define XAUDIO2_WRITE_AVAILABLE(handle) ((handle)->bufsize * (MAX_BUFFERS - (handle)->buffers - 1))
|
|
|
|
|
2011-01-27 01:46:00 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
xaudio2_t *xa;
|
|
|
|
bool nonblock;
|
2014-10-01 21:42:19 +02:00
|
|
|
bool is_paused;
|
2012-02-14 09:15:09 +01:00
|
|
|
size_t bufsize;
|
2011-01-27 01:46:00 +01:00
|
|
|
} xa_t;
|
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
/* Forward declarations */
|
|
|
|
static void *xa_list_new(void *u);
|
|
|
|
|
2018-02-05 00:25:03 +01:00
|
|
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
2015-04-03 02:29:20 +02:00
|
|
|
struct xaudio2 : public IXAudio2VoiceCallback
|
2017-09-28 10:04:48 +02:00
|
|
|
#else
|
|
|
|
struct xaudio2
|
|
|
|
#endif
|
2015-04-03 02:29:20 +02:00
|
|
|
{
|
2018-02-05 00:25:03 +01:00
|
|
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
2015-04-03 02:29:20 +02:00
|
|
|
xaudio2() :
|
|
|
|
buf(0), pXAudio2(0), pMasterVoice(0),
|
|
|
|
pSourceVoice(0), hEvent(0), buffers(0), bufsize(0),
|
|
|
|
bufptr(0), write_buffer(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~xaudio2() {}
|
|
|
|
|
|
|
|
STDMETHOD_(void, OnBufferStart) (void *) {}
|
2017-12-11 23:55:31 -08:00
|
|
|
STDMETHOD_(void, OnBufferEnd) (void *)
|
2015-04-03 02:29:20 +02:00
|
|
|
{
|
2015-11-17 11:17:18 +01:00
|
|
|
InterlockedDecrement((LONG volatile*)&buffers);
|
2015-04-03 02:29:20 +02:00
|
|
|
SetEvent(hEvent);
|
|
|
|
}
|
|
|
|
STDMETHOD_(void, OnLoopEnd) (void *) {}
|
|
|
|
STDMETHOD_(void, OnStreamEnd) () {}
|
|
|
|
STDMETHOD_(void, OnVoiceError) (void *, HRESULT) {}
|
|
|
|
STDMETHOD_(void, OnVoiceProcessingPassEnd) () {}
|
|
|
|
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
|
2017-09-28 10:04:48 +02:00
|
|
|
#else
|
|
|
|
const IXAudio2VoiceCallbackVtbl *lpVtbl;
|
|
|
|
#endif
|
2015-04-03 02:29:20 +02:00
|
|
|
|
|
|
|
uint8_t *buf;
|
|
|
|
IXAudio2 *pXAudio2;
|
|
|
|
IXAudio2MasteringVoice *pMasterVoice;
|
|
|
|
IXAudio2SourceVoice *pSourceVoice;
|
|
|
|
HANDLE hEvent;
|
|
|
|
|
2015-09-05 14:01:03 +02:00
|
|
|
unsigned long volatile buffers;
|
2015-04-03 02:29:20 +02:00
|
|
|
unsigned bufsize;
|
|
|
|
unsigned bufptr;
|
|
|
|
unsigned write_buffer;
|
|
|
|
};
|
|
|
|
|
2018-02-05 00:25:03 +01:00
|
|
|
#if !defined(__cplusplus) || defined(CINTERFACE)
|
|
|
|
static void WINAPI voice_on_buffer_end(IXAudio2VoiceCallback *handle_, void *data)
|
2017-12-11 23:55:31 -08:00
|
|
|
{
|
|
|
|
xaudio2_t *handle = (xaudio2_t*)handle_;
|
|
|
|
(void)data;
|
|
|
|
InterlockedDecrement((LONG volatile*)&handle->buffers);
|
|
|
|
SetEvent(handle->hEvent);
|
|
|
|
}
|
|
|
|
|
2018-02-05 00:25:03 +01:00
|
|
|
static void WINAPI dummy_voidp(IXAudio2VoiceCallback *handle, void *data) { (void)handle; (void)data; }
|
|
|
|
static void WINAPI dummy_nil(IXAudio2VoiceCallback *handle) { (void)handle; }
|
|
|
|
static void WINAPI dummy_uint32(IXAudio2VoiceCallback *handle, UINT32 dummy) { (void)handle; (void)dummy; }
|
|
|
|
static void WINAPI dummy_voidp_hresult(IXAudio2VoiceCallback *handle, void *data, HRESULT dummy) { (void)handle; (void)data; (void)dummy; }
|
2017-12-11 23:55:31 -08:00
|
|
|
|
|
|
|
const struct IXAudio2VoiceCallbackVtbl voice_vtable = {
|
|
|
|
dummy_uint32,
|
|
|
|
dummy_nil,
|
|
|
|
dummy_nil,
|
|
|
|
dummy_voidp,
|
|
|
|
voice_on_buffer_end,
|
|
|
|
dummy_voidp,
|
|
|
|
dummy_voidp_hresult,
|
2017-09-28 10:04:48 +02:00
|
|
|
};
|
2017-09-28 16:50:30 +02:00
|
|
|
#endif
|
2017-09-28 10:04:48 +02:00
|
|
|
|
2015-04-03 02:29:20 +02:00
|
|
|
static void xaudio2_set_wavefmt(WAVEFORMATEX *wfx,
|
|
|
|
unsigned channels, unsigned samplerate)
|
|
|
|
{
|
2015-04-09 06:02:41 +02:00
|
|
|
wfx->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
|
|
|
wfx->nBlockAlign = channels * sizeof(float);
|
|
|
|
wfx->wBitsPerSample = sizeof(float) * 8;
|
2015-04-03 02:29:20 +02:00
|
|
|
|
2015-04-09 06:02:41 +02:00
|
|
|
wfx->nChannels = channels;
|
|
|
|
wfx->nSamplesPerSec = samplerate;
|
2015-04-03 02:29:20 +02:00
|
|
|
wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
|
2015-04-09 06:02:41 +02:00
|
|
|
wfx->cbSize = 0;
|
2015-04-03 02:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xaudio2_free(xaudio2_t *handle)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (handle->pSourceVoice)
|
|
|
|
{
|
2017-09-28 10:04:48 +02:00
|
|
|
IXAudio2SourceVoice_Stop(handle->pSourceVoice,
|
|
|
|
0, XAUDIO2_COMMIT_NOW);
|
|
|
|
IXAudio2SourceVoice_DestroyVoice(handle->pSourceVoice);
|
2015-04-03 02:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->pMasterVoice)
|
2017-09-28 10:04:48 +02:00
|
|
|
{
|
|
|
|
IXAudio2MasteringVoice_DestroyVoice(handle->pMasterVoice);
|
|
|
|
}
|
2015-04-03 02:29:20 +02:00
|
|
|
|
|
|
|
if (handle->pXAudio2)
|
2017-09-28 10:04:48 +02:00
|
|
|
{
|
|
|
|
IXAudio2_Release(handle->pXAudio2);
|
|
|
|
}
|
2015-04-03 02:29:20 +02:00
|
|
|
|
|
|
|
if (handle->hEvent)
|
|
|
|
CloseHandle(handle->hEvent);
|
|
|
|
|
|
|
|
free(handle->buf);
|
2017-09-28 10:04:48 +02:00
|
|
|
|
2018-02-05 00:25:03 +01:00
|
|
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
2015-04-03 02:29:20 +02:00
|
|
|
delete handle;
|
2017-09-28 10:04:48 +02:00
|
|
|
#else
|
|
|
|
free(handle);
|
|
|
|
#endif
|
2015-04-03 02:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
|
2019-07-26 17:16:24 +02:00
|
|
|
size_t size, const char *device)
|
2015-04-03 02:29:20 +02:00
|
|
|
{
|
2019-07-26 17:16:24 +02:00
|
|
|
int32_t idx_found = -1;
|
|
|
|
WAVEFORMATEX wfx = {0};
|
|
|
|
struct string_list *list = NULL;
|
2018-02-05 00:25:03 +01:00
|
|
|
#if defined(__cplusplus) && !defined(CINTERFACE)
|
2019-07-26 17:16:24 +02:00
|
|
|
xaudio2_t *handle = new xaudio2;
|
2017-09-28 10:04:48 +02:00
|
|
|
#else
|
2019-07-26 17:16:24 +02:00
|
|
|
xaudio2_t *handle = (xaudio2_t*)calloc(1, sizeof(*handle));
|
2017-09-28 10:04:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
goto error;
|
2015-04-03 02:29:20 +02:00
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
list = (struct string_list*)xa_list_new(NULL);
|
|
|
|
|
2018-02-05 00:25:03 +01:00
|
|
|
#if !defined(__cplusplus) || defined(CINTERFACE)
|
2017-09-28 16:50:30 +02:00
|
|
|
handle->lpVtbl = &voice_vtable;
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 02:29:20 +02:00
|
|
|
if (FAILED(XAudio2Create(&handle->pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)))
|
|
|
|
goto error;
|
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
/* Search for device name first */
|
|
|
|
if (list && list->elems)
|
|
|
|
{
|
|
|
|
if (list->elems)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < list->size; i++)
|
|
|
|
{
|
|
|
|
if (string_is_equal(device, list->elems[i].data))
|
|
|
|
{
|
|
|
|
idx_found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Index was not found yet based on name string,
|
|
|
|
* just assume id is a one-character number index. */
|
|
|
|
|
|
|
|
if (idx_found == -1)
|
|
|
|
{
|
|
|
|
if (isdigit(device[0]))
|
|
|
|
{
|
|
|
|
RARCH_LOG("[XAudio2]: Fallback, device index is a single number index instead: %d.\n", idx_found);
|
|
|
|
idx_found = strtoul(device, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx_found == -1)
|
|
|
|
idx_found = 0;
|
|
|
|
|
2018-12-28 11:42:24 +01:00
|
|
|
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
2019-07-26 17:16:24 +02:00
|
|
|
{
|
2019-07-26 20:46:11 +02:00
|
|
|
wchar_t *temp = NULL;
|
|
|
|
if (device)
|
|
|
|
temp = utf8_to_utf16_string_alloc((const char*)list->elems[idx_found].userdata);
|
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, (LPCWSTR)(uintptr_t)temp, NULL, AudioCategory_GameEffects)))
|
|
|
|
{
|
|
|
|
free(temp);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (temp)
|
|
|
|
free(temp);
|
|
|
|
}
|
2018-12-28 11:42:24 +01:00
|
|
|
#else
|
2019-07-26 17:16:24 +02:00
|
|
|
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2, &handle->pMasterVoice, channels, samplerate, 0, idx_found, NULL)))
|
2017-09-28 10:04:48 +02:00
|
|
|
goto error;
|
2018-12-28 11:42:24 +01:00
|
|
|
#endif
|
2015-04-03 02:29:20 +02:00
|
|
|
|
|
|
|
xaudio2_set_wavefmt(&wfx, channels, samplerate);
|
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
if (FAILED(IXAudio2_CreateSourceVoice(handle->pXAudio2,
|
|
|
|
&handle->pSourceVoice, &wfx,
|
|
|
|
XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO,
|
2017-09-28 10:04:48 +02:00
|
|
|
(IXAudio2VoiceCallback*)handle, 0, 0)))
|
|
|
|
goto error;
|
2015-04-03 02:29:20 +02:00
|
|
|
|
2015-04-09 06:02:41 +02:00
|
|
|
handle->hEvent = CreateEvent(0, FALSE, FALSE, 0);
|
2015-04-03 02:29:20 +02:00
|
|
|
if (!handle->hEvent)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
handle->bufsize = size / MAX_BUFFERS;
|
2015-04-09 06:02:41 +02:00
|
|
|
handle->buf = (uint8_t*)calloc(1, handle->bufsize * MAX_BUFFERS);
|
2015-04-03 02:29:20 +02:00
|
|
|
if (!handle->buf)
|
|
|
|
goto error;
|
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
if (FAILED(IXAudio2SourceVoice_Start(handle->pSourceVoice, 0,
|
2017-09-28 10:04:48 +02:00
|
|
|
XAUDIO2_COMMIT_NOW)))
|
|
|
|
goto error;
|
2015-04-03 02:29:20 +02:00
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
if (list)
|
|
|
|
string_list_free(list);
|
2015-04-03 02:29:20 +02:00
|
|
|
return handle;
|
|
|
|
|
|
|
|
error:
|
2019-07-26 17:16:24 +02:00
|
|
|
if (list)
|
|
|
|
string_list_free(list);
|
2015-04-03 02:29:20 +02:00
|
|
|
xaudio2_free(handle);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:09:14 +01:00
|
|
|
static void *xa_init(const char *device, unsigned rate, unsigned latency,
|
2017-01-11 07:25:42 +01:00
|
|
|
unsigned block_frames,
|
2017-01-09 13:09:14 +01:00
|
|
|
unsigned *new_rate)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2015-01-12 05:05:56 +01:00
|
|
|
size_t bufsize;
|
2017-01-09 13:09:14 +01:00
|
|
|
xa_t *xa = (xa_t*)calloc(1, sizeof(*xa));
|
2015-05-20 23:01:03 +02:00
|
|
|
if (!xa)
|
|
|
|
return NULL;
|
2015-01-12 05:05:56 +01:00
|
|
|
|
2011-06-09 23:17:10 +02:00
|
|
|
if (latency < 8)
|
2015-01-12 05:05:56 +01:00
|
|
|
latency = 8; /* Do not allow shenanigans. */
|
2011-06-09 23:17:10 +02:00
|
|
|
|
2015-01-12 05:05:56 +01:00
|
|
|
bufsize = latency * rate / 1000;
|
2011-01-27 01:46:00 +01:00
|
|
|
|
2019-04-28 05:48:09 +02:00
|
|
|
RARCH_LOG("[XAudio2]: Requesting %u ms latency, using %d ms latency.\n",
|
2013-01-11 01:13:55 +01:00
|
|
|
latency, (int)bufsize * 1000 / rate);
|
2011-01-28 20:57:13 +01:00
|
|
|
|
2012-02-14 09:15:09 +01:00
|
|
|
xa->bufsize = bufsize * 2 * sizeof(float);
|
|
|
|
|
2019-07-26 17:16:24 +02:00
|
|
|
xa->xa = xaudio2_new(rate, 2, xa->bufsize, device);
|
2011-01-27 01:46:00 +01:00
|
|
|
if (!xa->xa)
|
|
|
|
{
|
2012-04-21 23:25:32 +02:00
|
|
|
RARCH_ERR("Failed to init XAudio2.\n");
|
2011-01-27 01:46:00 +01:00
|
|
|
free(xa);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-25 19:31:05 +01:00
|
|
|
|
2011-01-27 01:46:00 +01:00
|
|
|
return xa;
|
|
|
|
}
|
|
|
|
|
2020-01-03 21:54:09 +01:00
|
|
|
static ssize_t xa_write(void *data, const void *buf, size_t size)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2019-07-21 15:49:59 +02:00
|
|
|
unsigned bytes;
|
|
|
|
xa_t *xa = (xa_t*)data;
|
|
|
|
xaudio2_t *handle = xa->xa;
|
|
|
|
const uint8_t *buffer = (const uint8_t*)buf;
|
|
|
|
|
2020-01-03 21:54:09 +01:00
|
|
|
if (xa->nonblock)
|
2019-07-21 15:49:59 +02:00
|
|
|
{
|
2020-01-03 21:54:09 +01:00
|
|
|
size_t avail = XAUDIO2_WRITE_AVAILABLE(xa->xa);
|
2019-07-21 15:49:59 +02:00
|
|
|
|
2020-01-03 21:54:09 +01:00
|
|
|
if (avail == 0)
|
|
|
|
return 0;
|
|
|
|
if (avail < size)
|
|
|
|
size = avail;
|
2019-07-21 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
2020-01-03 21:54:09 +01:00
|
|
|
bytes = size;
|
2020-01-02 20:33:21 +01:00
|
|
|
|
|
|
|
while (bytes)
|
|
|
|
{
|
|
|
|
unsigned need = MIN(bytes, handle->bufsize - handle->bufptr);
|
|
|
|
|
|
|
|
memcpy(handle->buf + handle->write_buffer *
|
|
|
|
handle->bufsize + handle->bufptr,
|
|
|
|
buffer, need);
|
|
|
|
|
|
|
|
handle->bufptr += need;
|
|
|
|
buffer += need;
|
|
|
|
bytes -= need;
|
|
|
|
|
|
|
|
if (handle->bufptr == handle->bufsize)
|
|
|
|
{
|
|
|
|
XAUDIO2_BUFFER xa2buffer;
|
|
|
|
|
|
|
|
while (handle->buffers == MAX_BUFFERS - 1)
|
|
|
|
WaitForSingleObject(handle->hEvent, INFINITE);
|
|
|
|
|
|
|
|
xa2buffer.Flags = 0;
|
|
|
|
xa2buffer.AudioBytes = handle->bufsize;
|
|
|
|
xa2buffer.pAudioData = handle->buf + handle->write_buffer * handle->bufsize;
|
|
|
|
xa2buffer.PlayBegin = 0;
|
|
|
|
xa2buffer.PlayLength = 0;
|
|
|
|
xa2buffer.LoopBegin = 0;
|
|
|
|
xa2buffer.LoopLength = 0;
|
|
|
|
xa2buffer.LoopCount = 0;
|
|
|
|
xa2buffer.pContext = NULL;
|
|
|
|
|
|
|
|
if (FAILED(IXAudio2SourceVoice_SubmitSourceBuffer(
|
|
|
|
handle->pSourceVoice, &xa2buffer, NULL)))
|
|
|
|
{
|
|
|
|
if (size > 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
InterlockedIncrement((LONG volatile*)&handle->buffers);
|
|
|
|
handle->bufptr = 0;
|
|
|
|
handle->write_buffer = (handle->write_buffer + 1) & MAX_BUFFERS_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-11-02 20:04:31 +01:00
|
|
|
static bool xa_stop(void *data)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2014-10-01 21:42:19 +02:00
|
|
|
xa_t *xa = (xa_t*)data;
|
2014-11-14 22:55:40 -05:00
|
|
|
xa->is_paused = true;
|
2011-01-27 01:46:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:42:19 +02:00
|
|
|
static bool xa_alive(void *data)
|
|
|
|
{
|
|
|
|
xa_t *xa = (xa_t*)data;
|
2015-01-12 05:05:56 +01:00
|
|
|
if (!xa)
|
|
|
|
return false;
|
|
|
|
return !xa->is_paused;
|
2014-10-01 21:42:19 +02:00
|
|
|
}
|
|
|
|
|
2011-11-02 20:04:31 +01:00
|
|
|
static void xa_set_nonblock_state(void *data, bool state)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2011-12-24 13:46:12 +01:00
|
|
|
xa_t *xa = (xa_t*)data;
|
2015-01-12 05:05:56 +01:00
|
|
|
if (xa)
|
2020-01-03 21:54:09 +01:00
|
|
|
xa->nonblock = state;
|
2011-01-27 01:46:00 +01:00
|
|
|
}
|
|
|
|
|
2017-01-22 18:05:07 +01:00
|
|
|
static bool xa_start(void *data, bool is_shutdown)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2014-10-01 21:42:19 +02:00
|
|
|
xa_t *xa = (xa_t*)data;
|
|
|
|
xa->is_paused = false;
|
2011-01-27 01:46:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-02 20:04:31 +01:00
|
|
|
static bool xa_use_float(void *data)
|
2011-08-21 19:27:11 +02:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-02 20:04:31 +01:00
|
|
|
static void xa_free(void *data)
|
2011-01-27 01:46:00 +01:00
|
|
|
{
|
2011-12-24 13:46:12 +01:00
|
|
|
xa_t *xa = (xa_t*)data;
|
2015-01-12 05:05:56 +01:00
|
|
|
|
|
|
|
if (!xa)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xa->xa)
|
|
|
|
xaudio2_free(xa->xa);
|
|
|
|
free(xa);
|
2011-01-27 01:46:00 +01:00
|
|
|
}
|
|
|
|
|
2012-02-14 09:15:09 +01:00
|
|
|
static size_t xa_write_avail(void *data)
|
|
|
|
{
|
|
|
|
xa_t *xa = (xa_t*)data;
|
2017-12-25 08:11:10 +01:00
|
|
|
return XAUDIO2_WRITE_AVAILABLE(xa->xa);
|
2012-02-14 09:15:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t xa_buffer_size(void *data)
|
|
|
|
{
|
|
|
|
xa_t *xa = (xa_t*)data;
|
|
|
|
return xa->bufsize;
|
|
|
|
}
|
|
|
|
|
2019-07-26 03:39:46 +02:00
|
|
|
static void xa_device_list_free(void *u, void *slp)
|
|
|
|
{
|
|
|
|
struct string_list *sl = (struct string_list*)slp;
|
|
|
|
|
|
|
|
if (sl)
|
|
|
|
string_list_free(sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *xa_list_new(void *u)
|
|
|
|
{
|
|
|
|
#if defined(_XBOX) || !(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
|
|
|
unsigned i;
|
|
|
|
union string_list_elem_attr attr;
|
2020-05-11 03:49:16 +02:00
|
|
|
uint32_t dev_count = 0;
|
2019-07-26 03:39:46 +02:00
|
|
|
IXAudio2 *ixa2 = NULL;
|
|
|
|
struct string_list *sl = string_list_new();
|
|
|
|
|
|
|
|
if (!sl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
attr.i = 0;
|
|
|
|
|
|
|
|
if (FAILED(XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR)))
|
2019-07-26 17:22:21 +02:00
|
|
|
return NULL;
|
2019-07-26 03:39:46 +02:00
|
|
|
|
2020-05-11 03:49:16 +02:00
|
|
|
IXAudio2_GetDeviceCount(ixa2, &dev_count);
|
2019-07-26 03:39:46 +02:00
|
|
|
|
2020-05-11 03:49:16 +02:00
|
|
|
for (i = 0; i < dev_count; i++)
|
2019-07-26 03:39:46 +02:00
|
|
|
{
|
|
|
|
XAUDIO2_DEVICE_DETAILS dev_detail;
|
|
|
|
if (IXAudio2_GetDeviceDetails(ixa2, i, &dev_detail) == S_OK)
|
|
|
|
{
|
|
|
|
char *str = utf16_to_utf8_string_alloc(dev_detail.DisplayName);
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
string_list_append(sl, str, attr);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IXAudio2_Release(ixa2);
|
|
|
|
|
|
|
|
return sl;
|
2019-07-26 04:00:49 +02:00
|
|
|
#elif defined(__WINRT__)
|
|
|
|
return NULL;
|
2019-07-26 03:39:46 +02:00
|
|
|
#else
|
|
|
|
return mmdevice_list_new(u);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 07:06:20 +02:00
|
|
|
audio_driver_t audio_xa = {
|
2011-12-24 13:46:12 +01:00
|
|
|
xa_init,
|
|
|
|
xa_write,
|
|
|
|
xa_stop,
|
|
|
|
xa_start,
|
2014-10-01 21:42:19 +02:00
|
|
|
xa_alive,
|
2011-12-24 13:46:12 +01:00
|
|
|
xa_set_nonblock_state,
|
|
|
|
xa_free,
|
|
|
|
xa_use_float,
|
2012-02-14 09:15:09 +01:00
|
|
|
"xaudio",
|
2019-07-26 03:39:46 +02:00
|
|
|
xa_list_new,
|
|
|
|
xa_device_list_free,
|
2012-02-14 09:15:09 +01:00
|
|
|
xa_write_avail,
|
|
|
|
xa_buffer_size,
|
2011-01-27 01:46:00 +01:00
|
|
|
};
|