forward headroom setter to voice

This commit is contained in:
RadWolfie 2020-05-01 06:26:08 -05:00
parent d7d1d781d8
commit ab142abd69
4 changed files with 23 additions and 33 deletions

View File

@ -105,7 +105,6 @@ struct EmuDirectSoundBuffer
REFERENCE_TIME Xb_rtStopEx; REFERENCE_TIME Xb_rtStopEx;
LONG Xb_Volume; LONG Xb_Volume;
LONG Xb_VolumeMixbin; LONG Xb_VolumeMixbin;
DWORD Xb_dwHeadroom;
X_DSENVOLOPEDESC Xb_EnvolopeDesc; X_DSENVOLOPEDESC Xb_EnvolopeDesc;
X_DSVOICEPROPS Xb_VoiceProperties; X_DSVOICEPROPS Xb_VoiceProperties;
DWORD Xb_Flags; DWORD Xb_Flags;
@ -274,7 +273,6 @@ class X_CDirectSoundStream
REFERENCE_TIME Xb_rtPauseEx; REFERENCE_TIME Xb_rtPauseEx;
LONG Xb_Volume; LONG Xb_Volume;
LONG Xb_VolumeMixbin; LONG Xb_VolumeMixbin;
DWORD Xb_dwHeadroom;
X_DSENVOLOPEDESC Xb_EnvolopeDesc; X_DSENVOLOPEDESC Xb_EnvolopeDesc;
X_DSVOICEPROPS Xb_VoiceProperties; X_DSVOICEPROPS Xb_VoiceProperties;
DWORD Host_dwLastWritePos; DWORD Host_dwLastWritePos;

View File

@ -240,14 +240,13 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateBuffer)
else { else {
if (pdsbd->dwFlags & DSBCAPS_CTRL3D) { if (pdsbd->dwFlags & DSBCAPS_CTRL3D) {
DSound3DBufferCreate(pEmuBuffer->EmuDirectSoundBuffer8, pEmuBuffer->EmuDirectSound3DBuffer8); DSound3DBufferCreate(pEmuBuffer->EmuDirectSoundBuffer8, pEmuBuffer->EmuDirectSound3DBuffer8);
pEmuBuffer->Xb_dwHeadroom = 0; // Default for 3D
} }
DSoundDebugMuteFlag(pEmuBuffer->X_BufferCacheSize, pEmuBuffer->EmuFlags); DSoundDebugMuteFlag(pEmuBuffer->X_BufferCacheSize, pEmuBuffer->EmuFlags);
// Pre-set volume to enforce silence if one of audio codec is disabled. // Pre-set volume to enforce silence if one of audio codec is disabled.
HybridDirectSoundBuffer_SetVolume(pEmuBuffer->EmuDirectSoundBuffer8, 0L, pEmuBuffer->EmuFlags, nullptr, HybridDirectSoundBuffer_SetVolume(pEmuBuffer->EmuDirectSoundBuffer8, 0L, pEmuBuffer->EmuFlags,
pEmuBuffer->Xb_VolumeMixbin, pEmuBuffer->Xb_dwHeadroom, pHybridBuffer->p_CDSVoice); pEmuBuffer->Xb_VolumeMixbin, pHybridBuffer->p_CDSVoice);
g_pDSoundBufferCache.push_back(pHybridBuffer); g_pDSoundBufferCache.push_back(pHybridBuffer);
} }
@ -1001,7 +1000,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetHeadroom)
LOG_FUNC_END; LOG_FUNC_END;
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer; EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom, pThis->Xb_dwHeadroom, HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom,
pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags,
pHybridThis->p_CDSVoice); pHybridThis->p_CDSVoice);
@ -1221,7 +1220,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetMixBinVolumes_8)
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer; EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties, HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties,
pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->Xb_dwHeadroom, pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin,
pHybridThis->p_CDSVoice); pHybridThis->p_CDSVoice);
return hRet; return hRet;
@ -1507,8 +1506,8 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetVolume)
LOG_FUNC_END; LOG_FUNC_END;
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer; EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
HRESULT hRet = HybridDirectSoundBuffer_SetVolume(pThis->EmuDirectSoundBuffer8, lVolume, pThis->EmuFlags, &pThis->Xb_Volume, HRESULT hRet = HybridDirectSoundBuffer_SetVolume(pThis->EmuDirectSoundBuffer8, lVolume, pThis->EmuFlags,
pThis->Xb_VolumeMixbin, pThis->Xb_dwHeadroom, pHybridThis->p_CDSVoice); pThis->Xb_VolumeMixbin, pHybridThis->p_CDSVoice);
return hRet; return hRet;
} }

View File

@ -394,7 +394,6 @@ static inline void DSound3DBufferCreate(LPDIRECTSOUNDBUFFER8 pDSBuffer, LPDIRECT
pThis->Xb_rtPauseEx = 0LL; \ pThis->Xb_rtPauseEx = 0LL; \
pThis->Xb_Volume = 0L; \ pThis->Xb_Volume = 0L; \
pThis->Xb_VolumeMixbin = 0L; \ pThis->Xb_VolumeMixbin = 0L; \
pThis->Xb_dwHeadroom = 600; /* default for 2D voice */ \
pThis->Xb_EnvolopeDesc = { 0 }; \ pThis->Xb_EnvolopeDesc = { 0 }; \
InitVoiceProperties(pThis->Xb_VoiceProperties); /* The rest will initialize in GeneratePCMFormat to GenerateMixBinDefault. */ \ InitVoiceProperties(pThis->Xb_VoiceProperties); /* The rest will initialize in GeneratePCMFormat to GenerateMixBinDefault. */ \
pThis->Xb_Flags = Xb_dwFlags; pThis->Xb_Flags = Xb_dwFlags;
@ -1133,7 +1132,7 @@ static inline HRESULT HybridDirectSoundBuffer_SetFrequency(
RETURN_RESULT_CHECK(hRet); RETURN_RESULT_CHECK(hRet);
} }
static HRESULT HybridDirectSoundBuffer_SetVolume(LPDIRECTSOUNDBUFFER8, LONG, DWORD, LPLONG, LONG, DWORD, XTL::CDirectSoundVoice*); static HRESULT HybridDirectSoundBuffer_SetVolume(LPDIRECTSOUNDBUFFER8, LONG, DWORD, LONG, XTL::CDirectSoundVoice*);
//IDirectSoundStream //IDirectSoundStream
//IDirectSoundBuffer //IDirectSoundBuffer
@ -1141,7 +1140,6 @@ static HRESULT HybridDirectSoundBuffer_SetVolume(LPDIRECTSOUNDBUFFER8, LONG, DWO
static inline HRESULT HybridDirectSoundBuffer_SetHeadroom( static inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
LPDIRECTSOUNDBUFFER8 pDSBuffer, LPDIRECTSOUNDBUFFER8 pDSBuffer,
DWORD dwHeadroom, DWORD dwHeadroom,
DWORD &Xb_dwHeadroom,
LONG Xb_volume, LONG Xb_volume,
LONG Xb_volumeMixbin, LONG Xb_volumeMixbin,
DWORD dwEmuFlags, DWORD dwEmuFlags,
@ -1151,9 +1149,10 @@ static inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
if (dwHeadroom > 10000) { if (dwHeadroom > 10000) {
hRet = DSERR_INVALIDPARAM; hRet = DSERR_INVALIDPARAM;
} else { } else {
Xb_dwHeadroom = dwHeadroom;
hRet = DS_OK; hRet = DS_OK;
HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, dwEmuFlags, xbnullptr, Xb_volumeMixbin, dwHeadroom, Xb_Voice); Xb_Voice->SetHeadroom(Xb_Voice, dwHeadroom);
uint32_t volume = Xb_Voice->GetVolume(Xb_Voice);
pDSBuffer->SetVolume(volume);
} }
return DS_OK; return DS_OK;
@ -1245,7 +1244,6 @@ static inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
DWORD EmuFlags, DWORD EmuFlags,
LONG Xb_volume, LONG Xb_volume,
LONG &Xb_volumeMixBin, LONG &Xb_volumeMixBin,
DWORD Xb_dwHeadroom,
XTL::CDirectSoundVoice* Xb_Voice) XTL::CDirectSoundVoice* Xb_Voice)
{ {
HRESULT hRet = DSERR_INVALIDPARAM; HRESULT hRet = DSERR_INVALIDPARAM;
@ -1286,8 +1284,8 @@ static inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
} }
if (counter > 0) { if (counter > 0) {
Xb_volumeMixBin = volume / (LONG)counter; Xb_volumeMixBin = volume / (LONG)counter;
hRet = HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, EmuFlags, nullptr, hRet = HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, EmuFlags,
Xb_volumeMixBin, Xb_dwHeadroom, Xb_Voice); Xb_volumeMixBin, Xb_Voice);
} else { } else {
hRet = DS_OK; hRet = DS_OK;
} }
@ -1429,22 +1427,18 @@ static inline HRESULT HybridDirectSoundBuffer_SetVolume(
LPDIRECTSOUNDBUFFER8 pDSBuffer, LPDIRECTSOUNDBUFFER8 pDSBuffer,
LONG lVolume, LONG lVolume,
DWORD dwEmuFlags, DWORD dwEmuFlags,
LPLONG Xb_lpVolume,
LONG Xb_volumeMixbin, LONG Xb_volumeMixbin,
DWORD Xb_dwHeadroom,
XTL::CDirectSoundVoice* Xb_Voice) XTL::CDirectSoundVoice* Xb_Voice)
{ {
// Preserve original volume
if (Xb_lpVolume != xbnullptr) {
*Xb_lpVolume = lVolume;
}
#if 0 // TODO: Restore it once DSound work update comes up #if 0 // TODO: Restore it once DSound work update comes up
// For time being, this log is kept in case of something changed somewhere making a wrong input into the API. // For time being, this log is kept in case of something changed somewhere making a wrong input into the API.
printf("DEBUG: SetVolume | lVolume = %ld | volumeMixbin = %ld | dwHeadroom = %8u\n", lVolume, Xb_volumeMixbin, Xb_dwHeadroom); printf("DEBUG: SetVolume | lVolume = %ld | volumeMixbin = %ld | dwHeadroom = %8u\n", lVolume, Xb_volumeMixbin, Xb_dwHeadroom);
#endif #endif
lVolume += Xb_volumeMixbin - Xb_dwHeadroom; Xb_Voice->SetVolume(Xb_Voice, lVolume);
lVolume = Xb_Voice->GetVolume(Xb_Voice);
lVolume += Xb_volumeMixbin;
if ((dwEmuFlags & DSE_FLAG_PCM) > 0) { if ((dwEmuFlags & DSE_FLAG_PCM) > 0) {
if (!g_XBAudio.codec_pcm) { if (!g_XBAudio.codec_pcm) {

View File

@ -271,14 +271,13 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreateStream)
else { else {
if (DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) { if (DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) {
DSound3DBufferCreate((*ppStream)->EmuDirectSoundBuffer8, (*ppStream)->EmuDirectSound3DBuffer8); DSound3DBufferCreate((*ppStream)->EmuDirectSoundBuffer8, (*ppStream)->EmuDirectSound3DBuffer8);
(*ppStream)->Xb_dwHeadroom = 0; // Default for 3D
} }
DSoundDebugMuteFlag((*ppStream)->EmuBufferDesc.dwBufferBytes, (*ppStream)->EmuFlags); DSoundDebugMuteFlag((*ppStream)->EmuBufferDesc.dwBufferBytes, (*ppStream)->EmuFlags);
// Pre-set volume to enforce silence if one of audio codec is disabled. // Pre-set volume to enforce silence if one of audio codec is disabled.
HybridDirectSoundBuffer_SetVolume((*ppStream)->EmuDirectSoundBuffer8, 0L, (*ppStream)->EmuFlags, nullptr, HybridDirectSoundBuffer_SetVolume((*ppStream)->EmuDirectSoundBuffer8, 0L, (*ppStream)->EmuFlags,
(*ppStream)->Xb_VolumeMixbin, (*ppStream)->Xb_dwHeadroom, &(*ppStream)->Xb_Voice); (*ppStream)->Xb_VolumeMixbin, &(*ppStream)->Xb_Voice);
g_pDSoundStreamCache.push_back(*ppStream); g_pDSoundStreamCache.push_back(*ppStream);
} }
@ -969,7 +968,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetHeadroom)
LOG_FUNC_ARG(dwHeadroom) LOG_FUNC_ARG(dwHeadroom)
LOG_FUNC_END; LOG_FUNC_END;
HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom, pThis->Xb_dwHeadroom, HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom,
pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags, &pThis->Xb_Voice); pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags, &pThis->Xb_Voice);
return hRet; return hRet;
@ -1210,7 +1209,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetMixBinVolumes_8)
LOG_FUNC_END; LOG_FUNC_END;
HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties, HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties,
pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->Xb_dwHeadroom, pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin,
&pThis->Xb_Voice); &pThis->Xb_Voice);
return hRet; return hRet;
@ -1390,8 +1389,8 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetVolume)
LOG_FUNC_ARG(lVolume) LOG_FUNC_ARG(lVolume)
LOG_FUNC_END; LOG_FUNC_END;
HRESULT hRet = HybridDirectSoundBuffer_SetVolume(pThis->EmuDirectSoundBuffer8, lVolume, pThis->EmuFlags, &pThis->Xb_Volume, HRESULT hRet = HybridDirectSoundBuffer_SetVolume(pThis->EmuDirectSoundBuffer8, lVolume, pThis->EmuFlags,
pThis->Xb_VolumeMixbin, pThis->Xb_dwHeadroom, &pThis->Xb_Voice); pThis->Xb_VolumeMixbin, &pThis->Xb_Voice);
return hRet; return hRet;
} }