Fix audio buffer allocation
Use prediction if do have enough buffer purpose before allow allocate. This fixed Mafia title for loading "running man" mission. Plus add log info for SetEvent failure.
This commit is contained in:
parent
d8246a0074
commit
cc781826c3
|
@ -204,7 +204,7 @@ static XTL::X_CDirectSoundStream* g_pDSoundStreamCache[SOUNDSTREAM_CACHE_SIZE]
|
||||||
static int g_bDSoundCreateCalled = FALSE;
|
static int g_bDSoundCreateCalled = FALSE;
|
||||||
unsigned int g_iDSoundSynchPlaybackCounter = 0;
|
unsigned int g_iDSoundSynchPlaybackCounter = 0;
|
||||||
// Managed memory xbox audio variables
|
// Managed memory xbox audio variables
|
||||||
#define X_DS_SGE_COUNT_MAX 2048
|
#define X_DS_SGE_COUNT_MAX 2047
|
||||||
#define X_DS_SGE_PAGE_MAX (4 * ONE_KB)
|
#define X_DS_SGE_PAGE_MAX (4 * ONE_KB)
|
||||||
#define X_DS_SGE_SIZE_MAX (X_DS_SGE_COUNT_MAX * X_DS_SGE_PAGE_MAX)
|
#define X_DS_SGE_SIZE_MAX (X_DS_SGE_COUNT_MAX * X_DS_SGE_PAGE_MAX)
|
||||||
DWORD g_dwXbMemAllocated = 0;
|
DWORD g_dwXbMemAllocated = 0;
|
||||||
|
@ -964,7 +964,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//If out of space, return out of memory.
|
//If out of space, return out of memory.
|
||||||
if (ppDSoundBufferCache == nullptr || !DSoundSGEMenAllocCheck()) {
|
if (ppDSoundBufferCache == nullptr || !DSoundSGEMenAllocCheck(pdsbd->dwBufferBytes)) {
|
||||||
|
|
||||||
hRet = DSERR_OUTOFMEMORY;
|
hRet = DSERR_OUTOFMEMORY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -998,7 +998,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
GeneratePCMFormat(DSBufferDesc, pdsbd->lpwfxFormat, (*ppBuffer)->EmuFlags, pdsbd->dwBufferBytes, &(*ppBuffer)->X_BufferCache, (*ppBuffer)->X_BufferCacheSize);
|
GeneratePCMFormat(DSBufferDesc, pdsbd->lpwfxFormat, (*ppBuffer)->EmuFlags, pdsbd->dwBufferBytes, &(*ppBuffer)->X_BufferCache, (*ppBuffer)->X_BufferCacheSize);
|
||||||
(*ppBuffer)->EmuBufferDesc = DSBufferDesc;
|
(*ppBuffer)->EmuBufferDesc = DSBufferDesc;
|
||||||
|
|
||||||
DbgPrintf("EmuDSound: DirectSoundCreateBuffer, *ppBuffer := 0x%.08X, bytes := 0x%.08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes);
|
DbgPrintf("EmuDSound: DirectSoundCreateBuffer, *ppBuffer := 0x%08X, bytes := 0x%08X\n", *ppBuffer, (*ppBuffer)->EmuBufferDesc.dwBufferBytes);
|
||||||
|
|
||||||
DSoundBufferCreate(&DSBufferDesc, (*ppBuffer)->EmuDirectSoundBuffer8);
|
DSoundBufferCreate(&DSBufferDesc, (*ppBuffer)->EmuDirectSoundBuffer8);
|
||||||
if (pdsbd->dwFlags & DSBCAPS_CTRL3D) {
|
if (pdsbd->dwFlags & DSBCAPS_CTRL3D) {
|
||||||
|
@ -1007,6 +1007,11 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
|
||||||
*ppDSoundBufferCache = *ppBuffer;
|
*ppDSoundBufferCache = *ppBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("DEBUG: ==DirectSoundCreateBuffer==\n");
|
||||||
|
printf("DEBUG: *ppBuffer = %8X | requestSize = %8X\n", *ppBuffer, pdsbd->dwBufferBytes);
|
||||||
|
printf("DEBUG: g_dwXbMemAllocated = %8X\n", g_dwXbMemAllocated);
|
||||||
|
printf("DEBUG: ===========================\n");
|
||||||
|
|
||||||
leaveCriticalSection;
|
leaveCriticalSection;
|
||||||
|
|
||||||
return hRet;
|
return hRet;
|
||||||
|
@ -1075,7 +1080,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetBufferData)
|
||||||
}
|
}
|
||||||
HRESULT hRet = DSERR_OUTOFMEMORY;
|
HRESULT hRet = DSERR_OUTOFMEMORY;
|
||||||
|
|
||||||
if (DSoundSGEMenAllocCheck()) {
|
if (DSoundSGEMenAllocCheck(dwBufferBytes)) {
|
||||||
|
|
||||||
// Confirmed it perform a reset to default.
|
// Confirmed it perform a reset to default.
|
||||||
DSoundBufferRegionSetDefault(pThis);
|
DSoundBufferRegionSetDefault(pThis);
|
||||||
|
|
|
@ -71,8 +71,8 @@ inline void DSoundSGEMemAlloc(DWORD size) {
|
||||||
inline void DSoundSGEMemDealloc(DWORD size) {
|
inline void DSoundSGEMemDealloc(DWORD size) {
|
||||||
g_dwXbMemAllocated -= size;
|
g_dwXbMemAllocated -= size;
|
||||||
}
|
}
|
||||||
inline bool DSoundSGEMenAllocCheck() {
|
inline bool DSoundSGEMenAllocCheck(DWORD sizeRequest) {
|
||||||
int leftOverSize = X_DS_SGE_SIZE_MAX - g_dwXbMemAllocated;
|
int leftOverSize = X_DS_SGE_SIZE_MAX - (g_dwXbMemAllocated + sizeRequest);
|
||||||
// Don't let xbox title to alloc any more.
|
// Don't let xbox title to alloc any more.
|
||||||
if (leftOverSize < 0) {
|
if (leftOverSize < 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -729,7 +729,11 @@ inline void DSoundStreamClearPacket(
|
||||||
if (Xb_lpfnCallback != xbnullptr) {
|
if (Xb_lpfnCallback != xbnullptr) {
|
||||||
Xb_lpfnCallback(Xb_lpvContext, buffer->xmp_data.pContext, status);
|
Xb_lpfnCallback(Xb_lpvContext, buffer->xmp_data.pContext, status);
|
||||||
} else if (buffer->xmp_data.hCompletionEvent != 0) {
|
} else if (buffer->xmp_data.hCompletionEvent != 0) {
|
||||||
SetEvent(buffer->xmp_data.hCompletionEvent);
|
BOOL checkHandle = SetEvent(buffer->xmp_data.hCompletionEvent);
|
||||||
|
if (checkHandle == 0) {
|
||||||
|
DWORD error = GetLastError();
|
||||||
|
EmuWarning("DSOUND: Unable to set event on packet's hCompletionEvent. %8X | error = %8X", buffer->xmp_data.hCompletionEvent, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue