mirror of
https://github.com/libretro/RetroArch
synced 2025-02-04 03:40:03 +00:00
(360) Xaudio2 driver compiles now
This commit is contained in:
parent
a287ebe736
commit
8320d0a0e9
@ -21,20 +21,30 @@
|
|||||||
#include <xaudio2.h>
|
#include <xaudio2.h>
|
||||||
#include "../general.h"
|
#include "../general.h"
|
||||||
|
|
||||||
|
#define MAX_BUFFERS 16
|
||||||
|
#define MAX_BUFFERS_MASK 15
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
uint8_t *buf;
|
||||||
IXAudio2 * pXAudio2;
|
IXAudio2 * pXAudio2;
|
||||||
IXAudio2MasteringVoice *pMasteringVoice;
|
IXAudio2MasteringVoice *pMasteringVoice;
|
||||||
IXAudio2SourceVoice *pSourceVoice;
|
IXAudio2SourceVoice *pSourceVoice;
|
||||||
bool nonblock;
|
bool nonblock;
|
||||||
unsigned bufsize;
|
unsigned bufsize;
|
||||||
|
unsigned bufptr;
|
||||||
|
unsigned write_buffer;
|
||||||
volatile long buffers;
|
volatile long buffers;
|
||||||
|
HANDLE hEvent;
|
||||||
} xa_t;
|
} xa_t;
|
||||||
|
|
||||||
static void *xa_init(const char *device, unsigned rate, unsigned latency)
|
static void *xa_init(const char *device, unsigned rate, unsigned latency)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
WAVEFORMATEXTENSIBLE wfx;
|
||||||
|
|
||||||
|
flags = 0;
|
||||||
|
|
||||||
if (latency < 8)
|
if (latency < 8)
|
||||||
latency = 8; // Do not allow shenanigans.
|
latency = 8; // Do not allow shenanigans.
|
||||||
@ -44,26 +54,23 @@ static void *xa_init(const char *device, unsigned rate, unsigned latency)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
size_t bufsize = latency * rate / 1000;
|
size_t bufsize = latency * rate / 1000;
|
||||||
size_t size = busize * 2 * sizeof(float);
|
size_t size = bufsize * 2 * sizeof(float);
|
||||||
|
|
||||||
SSNES_LOG("XAudio2: Requesting %d ms latency, using %d ms latency.\n", latency, (int)bufsize * 1000 / rate);
|
SSNES_LOG("XAudio2: Requesting %d ms latency, using %d ms latency.\n", latency, (int)bufsize * 1000 / rate);
|
||||||
|
|
||||||
if( FAILED( hr = XAudio2Create(&xa->pXAudio2, flags)))
|
if( FAILED( hr = XAudio2Create(&xa->pXAudio2, flags)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (FAILED(IXAudio2_CreateMasteringVoice(xa->pXAudio2,
|
if (FAILED(xa->pXAudio2->CreateMasteringVoice(&xa->pMasteringVoice, 2, rate, 0, 0, NULL)))
|
||||||
&xa->pMasterVoice, 2, rate, 0, 0, 0)))
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
WAVEFORMATEXTENSIBLE wfx = {0};
|
//wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
||||||
|
//wfx.nChannels = 2;
|
||||||
wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
//wfx.nSamplesPerSec = rate;
|
||||||
wfx.nChannels = 2;
|
//wfx.nBlockAlign = channels * sizeof(float);
|
||||||
wfx.nSamplesPerSec = rate;
|
//wfx.wBitsPerSample = sizeof(float) * 8;
|
||||||
wfx.nBlockAlign = channels * sizeof(float);
|
//wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
||||||
wfx.wBitsPerSample = sizeof(float) * 8;
|
//wfx.cbSize = 0;
|
||||||
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
|
||||||
wfx.cbSize = 0;
|
|
||||||
|
|
||||||
if( FAILED( hr = xa->pXAudio2->CreateSourceVoice( &xa->pSourceVoice, ( WAVEFORMATEX*)&wfx ) ) )
|
if( FAILED( hr = xa->pXAudio2->CreateSourceVoice( &xa->pSourceVoice, ( WAVEFORMATEX*)&wfx ) ) )
|
||||||
goto error;
|
goto error;
|
||||||
@ -74,10 +81,10 @@ static void *xa_init(const char *device, unsigned rate, unsigned latency)
|
|||||||
if (!xa->buf)
|
if (!xa->buf)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if( FAILED(IXAUdio2SourceVoice_Start(xa->pSourceVoice, 0, XAUDIO2_COMMIT_NOW)))
|
if( FAILED(xa->pSourceVoice->Start(0)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!xa->xa)
|
if (!xa->pXAudio2)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return xa;
|
return xa;
|
||||||
@ -111,7 +118,7 @@ static size_t xaudio2_write(xa_t *handle, const void *buf, size_t bytes_)
|
|||||||
xa2buffer.AudioBytes = handle->bufsize;
|
xa2buffer.AudioBytes = handle->bufsize;
|
||||||
xa2buffer.pAudioData = handle->buf + handle->write_buffer * handle->bufsize;
|
xa2buffer.pAudioData = handle->buf + handle->write_buffer * handle->bufsize;
|
||||||
|
|
||||||
if (FAILED(IXAudio2SourceVoice_SubmitSourceBuffer(handle->pSourceVoice, &xa2buffer, NULL)))
|
if (FAILED(handle->pSourceVoice->SubmitSourceBuffer(&xa2buffer)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
InterlockedIncrement(&handle->buffers);
|
InterlockedIncrement(&handle->buffers);
|
||||||
@ -125,17 +132,18 @@ static size_t xaudio2_write(xa_t *handle, const void *buf, size_t bytes_)
|
|||||||
|
|
||||||
static ssize_t xa_write(void *data, const void *buf, size_t size)
|
static ssize_t xa_write(void *data, const void *buf, size_t size)
|
||||||
{
|
{
|
||||||
|
size_t avail;
|
||||||
xa_t *xa = (xa_t*)data;
|
xa_t *xa = (xa_t*)data;
|
||||||
if (xa->nonblock)
|
if (xa->nonblock)
|
||||||
{
|
{
|
||||||
size_t avail = (xa->bufsize * (MAX_BUFFERS - xa->buffers - 1);
|
avail = (xa->bufsize * (MAX_BUFFERS - xa->buffers - 1));
|
||||||
if (avail == 0)
|
if (avail == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (avail < size)
|
if (avail < size)
|
||||||
size = avail;
|
size = avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ret = xaudio2_write(xa->pXAudio2, buf, size);
|
size_t ret = xaudio2_write(xa, buf, size);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
return -1;
|
return -1;
|
||||||
return ret;
|
return ret;
|
||||||
@ -171,15 +179,15 @@ static void xaudio2_free(xa_t *handle)
|
|||||||
{
|
{
|
||||||
if (handle->pSourceVoice)
|
if (handle->pSourceVoice)
|
||||||
{
|
{
|
||||||
IXAudio2SourceVoice_Stop(handle->pSourceVoice, 0, XAUDIO2_COMMIT_NOW);
|
handle->pSourceVoice->Stop(0, XAUDIO2_COMMIT_NOW);
|
||||||
IXAudio2SourceVoice_DestroyVoice(handle->pSourceVoice);
|
handle->pSourceVoice->DestroyVoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle->pMasterVoice)
|
if (handle->pMasteringVoice)
|
||||||
IXAudio2MasteringVoice_DestroyVoice(handle->pMasterVoice);
|
handle->pMasteringVoice->DestroyVoice();
|
||||||
|
|
||||||
if (handle->pXAudio2)
|
if (handle->pXAudio2)
|
||||||
IXAudio2_Release(handle->pXAudio2);
|
handle->pXAudio2->Release();
|
||||||
|
|
||||||
if (handle->hEvent)
|
if (handle->hEvent)
|
||||||
CloseHandle(handle->hEvent);
|
CloseHandle(handle->hEvent);
|
||||||
@ -194,9 +202,9 @@ static void xa_free(void *data)
|
|||||||
xa_t *xa = (xa_t*)data;
|
xa_t *xa = (xa_t*)data;
|
||||||
if (xa)
|
if (xa)
|
||||||
{
|
{
|
||||||
if (xa->xa)
|
if (xa->pXAudio2)
|
||||||
xaudio2_free(xa->xa);
|
xaudio2_free(xa);
|
||||||
free(xa);
|
free(xa->pXAudio2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user