relocate enter/leave critical section into dsound's patch functions

This commit is contained in:
RadWolfie 2019-07-08 22:54:55 -05:00
parent c5b374e110
commit a06341e0d2
2 changed files with 369 additions and 475 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,12 +26,13 @@
// ******************************************************************
#ifndef EMUDSOUNDINLINE_H
#define EMUDSOUNDINLINE_H
#include <mutex>
#include "XADPCM.h"
CRITICAL_SECTION g_DSoundCriticalSection;
#define enterCriticalSection EnterCriticalSection(&g_DSoundCriticalSection)
#define leaveCriticalSection LeaveCriticalSection(&g_DSoundCriticalSection)
static std::recursive_mutex g_DSoundMutex;
#define DSoundMutexGuardLock std::lock_guard<std::recursive_mutex> guard(g_DSoundMutex)
#define DSoundBufferGetPCMBufferSize(EmuFlags, size) (EmuFlags & DSE_FLAG_XADPCM) > 0 ? DWORD((size / float(XBOX_ADPCM_SRCSIZE)) * XBOX_ADPCM_DSTSIZE) : size
#define DSoundBufferGetXboxBufferSize(EmuFlags, size) (EmuFlags & DSE_FLAG_XADPCM) > 0 ? DWORD((size / float(XBOX_ADPCM_DSTSIZE)) * XBOX_ADPCM_SRCSIZE) : size
@ -1037,26 +1038,16 @@ inline bool DSoundStreamProcess(XTL::X_CDirectSoundStream* pThis) {
inline ULONG HybridDirectSoundBuffer_AddRef(
LPDIRECTSOUNDBUFFER8 pDSBuffer)
{
enterCriticalSection;
ULONG uRet = pDSBuffer->AddRef();
leaveCriticalSection;
return uRet;
}
inline ULONG HybridDirectSoundBuffer_Release(
LPDIRECTSOUNDBUFFER8 pDSBuffer)
{
enterCriticalSection;
ULONG uRet = pDSBuffer->Release();
leaveCriticalSection;
return uRet;
}
@ -1097,9 +1088,6 @@ inline HRESULT HybridDirectSoundBuffer_GetCurrentPosition(
PDWORD pdwCurrentWriteCursor,
DWORD EmuFlags)
{
enterCriticalSection;
DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
HRESULT hRet = pDSBuffer->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
@ -1114,8 +1102,6 @@ inline HRESULT HybridDirectSoundBuffer_GetCurrentPosition(
*pdwCurrentWriteCursor = DSoundBufferGetXboxBufferSize(EmuFlags, dwCurrentWriteCursor);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1127,13 +1113,8 @@ inline HRESULT HybridDirectSoundBuffer_GetStatus(
LPDIRECTSOUNDBUFFER8 pDSBuffer,
PDWORD pdwStatus)
{
enterCriticalSection;
HRESULT hRet = pDSBuffer->GetStatus(pdwStatus);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}*/
@ -1164,9 +1145,6 @@ inline HRESULT HybridDirectSoundBuffer_Pause(
REFERENCE_TIME rtTimeStamp,
REFERENCE_TIME &Xb_rtTimeStamp)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
switch (dwPause) {
case X_DSSPAUSE_RESUME:
@ -1197,8 +1175,6 @@ inline HRESULT HybridDirectSoundBuffer_Pause(
break;
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1279,8 +1255,6 @@ inline HRESULT HybridDirectSound3DBuffer_SetAllParameters(
XTL::X_DS3DBUFFER* pDS3DBufferParams,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
@ -1298,27 +1272,22 @@ inline HRESULT HybridDirectSound3DBuffer_SetAllParameters(
hRet = pDS3DBuffer->SetAllParameters(&pDS3DBufferParamsTemp, dwApply);
if (hRet != DS_OK) {
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
hRet = g_pDSoundPrimary3DListener8->SetDistanceFactor(pDS3DBufferParams->flDistanceFactor, dwApply);
if (hRet != DS_OK) {
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
hRet = g_pDSoundPrimary3DListener8->SetRolloffFactor(pDS3DBufferParams->flRolloffFactor, dwApply);
if (hRet != DS_OK) {
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
hRet = g_pDSoundPrimary3DListener8->SetDopplerFactor(pDS3DBufferParams->flDopplerFactor, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1339,16 +1308,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetConeAngles(
DWORD dwOutsideConeAngle,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetConeAngles(dwInsideConeAngle, dwOutsideConeAngle, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1361,9 +1325,6 @@ inline HRESULT HybridDirectSound3DBuffer_SetConeOrientation(
D3DVALUE z,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
// TODO: (DSound) Should we do restrictive or passive to return actual result back to titles?
@ -1375,8 +1336,6 @@ inline HRESULT HybridDirectSound3DBuffer_SetConeOrientation(
}
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1387,16 +1346,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetConeOutsideVolume(
LONG lConeOutsideVolume,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetConeOutsideVolume(lConeOutsideVolume, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1418,13 +1372,8 @@ inline HRESULT HybridDirectSound3DListener_SetDistanceFactor(
FLOAT flDistanceFactor,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = pDS3DListener->SetDistanceFactor(flDistanceFactor, dwApply);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1436,13 +1385,8 @@ inline HRESULT HybridDirectSound3DListener_SetDopplerFactor(
FLOAT flDopplerFactor,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = pDS3DListener->SetDopplerFactor(flDopplerFactor, dwApply);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1483,9 +1427,6 @@ inline HRESULT HybridDirectSoundBuffer_SetFormat(
XTL::X_DSVOICEPROPS &Xb_VoiceProperties,
XTL::X_LPDSMIXBINS mixbins_output)
{
enterCriticalSection;
pDSBuffer->Stop();
if (X_BufferAllocate) {
@ -1506,8 +1447,6 @@ inline HRESULT HybridDirectSoundBuffer_SetFormat(
DSoundBufferReplace(pDSBuffer, BufferDesc, dwPlayFlags, pDS3DBuffer);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1517,15 +1456,10 @@ inline HRESULT HybridDirectSoundBuffer_SetFrequency(
LPDIRECTSOUNDBUFFER8 pDSBuffer,
DWORD dwFrequency)
{
enterCriticalSection;
HRESULT hRet = S_OK;
hRet = pDSBuffer->SetFrequency(dwFrequency);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1542,9 +1476,6 @@ inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
LONG Xb_volumeMixbin,
DWORD dwEmuFlags)
{
enterCriticalSection;
HRESULT hRet;
if (dwHeadroom > 10000) {
hRet = DSERR_INVALIDPARAM;
@ -1554,8 +1485,6 @@ inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, dwEmuFlags, xbnullptr, Xb_volumeMixbin, dwHeadroom);
}
leaveCriticalSection;
return DS_OK;
}
@ -1602,16 +1531,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetMaxDistance(
D3DVALUE flMaxDistance,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetMaxDistance(flMaxDistance, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1622,16 +1546,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetMinDistance(
D3DVALUE flMinDistance,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetMinDistance(flMinDistance, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1657,8 +1576,6 @@ inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
LONG &Xb_volumeMixBin,
DWORD Xb_dwHeadroom)
{
enterCriticalSection;
HRESULT hRet = DSERR_INVALIDPARAM;
if (pMixBins != xbnullptr) {
@ -1705,8 +1622,6 @@ inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
}
}
leaveCriticalSection;
return hRet;
}
@ -1717,16 +1632,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetMode(
DWORD dwMode,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetMode(dwMode, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1802,16 +1712,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetPosition(
D3DVALUE z,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetPosition(x, y, z, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*
@ -1836,13 +1741,8 @@ inline HRESULT HybridDirectSound3DListener_SetRolloffFactor(
FLOAT fRolloffFactor,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = pDSBuffer->SetRolloffFactor(fRolloffFactor, dwApply);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1856,16 +1756,11 @@ inline HRESULT HybridDirectSound3DBuffer_SetVelocity(
FLOAT z,
DWORD dwApply)
{
enterCriticalSection;
HRESULT hRet = DS_OK;
if (pDS3DBuffer != nullptr) {
hRet = pDS3DBuffer->SetVelocity(x, y, z, dwApply);
}
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
@ -1881,9 +1776,6 @@ inline HRESULT HybridDirectSoundBuffer_SetVolume(
LONG Xb_volumeMixbin,
DWORD Xb_dwHeadroom)
{
enterCriticalSection;
// Preserve original volume
if (Xb_lpVolume != xbnullptr) {
*Xb_lpVolume = lVolume;
@ -1921,8 +1813,6 @@ inline HRESULT HybridDirectSoundBuffer_SetVolume(
HRESULT hRet = pDSBuffer->SetVolume(lVolume);
leaveCriticalSection;
RETURN_RESULT_CHECK(hRet);
}
/*/
@ -1959,8 +1849,6 @@ inline HRESULT HybridDirectSoundBuffer_GetVoiceProperties(
XTL::X_DSVOICEPROPS* out_VoiceProperties
)
{
enterCriticalSection;
HRESULT ret = DS_OK;
if (out_VoiceProperties != xbnullptr) {
@ -1971,8 +1859,6 @@ inline HRESULT HybridDirectSoundBuffer_GetVoiceProperties(
ret = DSERR_INVALIDPARAM;
}
leaveCriticalSection;
return ret;
}