remove Xb_Volume member from host's structure

This commit is contained in:
RadWolfie 2020-05-10 19:17:00 -05:00
parent ee4856a06d
commit 8b780f2d5c
4 changed files with 41 additions and 36 deletions

View File

@ -103,7 +103,6 @@ struct EmuDirectSoundBuffer
DSoundBuffer_Lock X_lock;
REFERENCE_TIME Xb_rtPauseEx;
REFERENCE_TIME Xb_rtStopEx;
LONG Xb_Volume;
LONG Xb_VolumeMixbin;
X_DSENVOLOPEDESC Xb_EnvolopeDesc;
X_DSVOICEPROPS Xb_VoiceProperties;
@ -271,7 +270,6 @@ class X_CDirectSoundStream
LPVOID Xb_lpvContext;
REFERENCE_TIME Xb_rtFlushEx;
REFERENCE_TIME Xb_rtPauseEx;
LONG Xb_Volume;
LONG Xb_VolumeMixbin;
X_DSENVOLOPEDESC Xb_EnvolopeDesc;
X_DSVOICEPROPS Xb_VoiceProperties;

View File

@ -1001,7 +1001,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetHeadroom)
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom,
pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags,
pThis->Xb_VolumeMixbin, pThis->EmuFlags,
pHybridThis->p_CDSVoice);
return hRet;
@ -1220,8 +1220,7 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetMixBinVolumes_8)
EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties,
pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin,
pHybridThis->p_CDSVoice);
pThis->EmuFlags, pThis->Xb_VolumeMixbin, pHybridThis->p_CDSVoice);
return hRet;
}

View File

@ -392,7 +392,6 @@ static inline void DSound3DBufferCreate(LPDIRECTSOUNDBUFFER8 pDSBuffer, LPDIRECT
pThis->EmuPlayFlags = dwEmuPlayFlags; \
pThis->X_BufferCacheSize = 0; \
pThis->Xb_rtPauseEx = 0LL; \
pThis->Xb_Volume = 0L; \
pThis->Xb_VolumeMixbin = 0L; \
pThis->Xb_EnvolopeDesc = { 0 }; \
InitVoiceProperties(pThis->Xb_VoiceProperties); /* The rest will initialize in GeneratePCMFormat to GenerateMixBinDefault. */ \
@ -685,6 +684,40 @@ static inline HRESULT DSoundBufferSynchPlaybackFlagAdd(
return DS_OK;
}
static inline HRESULT DSoundBufferUpdateHostVolume(
LPDIRECTSOUNDBUFFER8 pDSBuffer,
uint32_t dwEmuFlags,
uint32_t volume
)
{
if ((dwEmuFlags & DSE_FLAG_PCM) > 0) {
if (!g_XBAudio.codec_pcm) {
volume = DSBVOLUME_MIN;
}
} else if ((dwEmuFlags & DSE_FLAG_XADPCM) > 0) {
if (!g_XBAudio.codec_xadpcm) {
volume = DSBVOLUME_MIN;
}
} else if ((dwEmuFlags & DSE_FLAG_PCM_UNKNOWN) > 0) {
if (!g_XBAudio.codec_unknown) {
volume = DSBVOLUME_MIN;
}
}
if (volume <= -6400 && volume != DSBVOLUME_MIN) {
volume = DSBVOLUME_MIN;
} else if (volume > 0) {
EmuLog(LOG_LEVEL::WARNING, "volume has received greater than 0: %ld", volume);
volume = 0;
}
if ((dwEmuFlags & DSE_FLAG_DEBUG_MUTE) > 0) {
volume = DSBVOLUME_MIN;
}
return pDSBuffer->SetVolume(volume);
}
//TODO: RadWolfie - Need to implement DirectSoundBuffer create support. Or not able to do so due to all three classes function differently.
//IDirectSound
//IDirectSoundStream
@ -1140,7 +1173,6 @@ static HRESULT HybridDirectSoundBuffer_SetVolume(LPDIRECTSOUNDBUFFER8, LONG, DWO
static inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
LPDIRECTSOUNDBUFFER8 pDSBuffer,
DWORD dwHeadroom,
LONG Xb_volume,
LONG Xb_volumeMixbin,
DWORD dwEmuFlags,
XTL::CDirectSoundVoice* Xb_Voice)
@ -1152,7 +1184,7 @@ static inline HRESULT HybridDirectSoundBuffer_SetHeadroom(
hRet = DS_OK;
Xb_Voice->SetHeadroom(dwHeadroom);
uint32_t volume = Xb_Voice->GetVolume();
pDSBuffer->SetVolume(volume);
hRet = DSoundBufferUpdateHostVolume(pDSBuffer, dwEmuFlags, volume);
}
return DS_OK;
@ -1242,7 +1274,6 @@ static inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
XTL::X_LPDSMIXBINS pMixBins,
XTL::X_DSVOICEPROPS& Xb_VoiceProperties,
DWORD EmuFlags,
LONG Xb_volume,
LONG &Xb_volumeMixBin,
XTL::CDirectSoundVoice* Xb_Voice)
{
@ -1284,6 +1315,7 @@ static inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
}
if (counter > 0) {
Xb_volumeMixBin = volume / (LONG)counter;
uint32_t Xb_volume = Xb_Voice->GetVolume();
hRet = HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, EmuFlags,
Xb_volumeMixBin, Xb_Voice);
} else {
@ -1440,30 +1472,7 @@ static inline HRESULT HybridDirectSoundBuffer_SetVolume(
lVolume = Xb_Voice->GetVolume();
lVolume += Xb_volumeMixbin;
if ((dwEmuFlags & DSE_FLAG_PCM) > 0) {
if (!g_XBAudio.codec_pcm) {
lVolume = DSBVOLUME_MIN;
}
} else if ((dwEmuFlags & DSE_FLAG_XADPCM) > 0) {
if (!g_XBAudio.codec_xadpcm) {
lVolume = DSBVOLUME_MIN;
}
} else if ((dwEmuFlags & DSE_FLAG_PCM_UNKNOWN) > 0) {
if (!g_XBAudio.codec_unknown) {
lVolume = DSBVOLUME_MIN;
}
}
if (lVolume <= -6400 && lVolume != DSBVOLUME_MIN) {
lVolume = DSBVOLUME_MIN;
} else if (lVolume > 0) {
EmuLog(LOG_LEVEL::WARNING, "HybridDirectSoundBuffer_SetVolume has received greater than 0: %ld", lVolume);
lVolume = 0;
}
if ((dwEmuFlags & DSE_FLAG_DEBUG_MUTE) > 0) {
lVolume = DSBVOLUME_MIN;
}
HRESULT hRet = pDSBuffer->SetVolume(lVolume);
HRESULT hRet = DSoundBufferUpdateHostVolume(pDSBuffer, dwEmuFlags, lVolume);
RETURN_RESULT_CHECK(hRet);
}

View File

@ -969,7 +969,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetHeadroom)
LOG_FUNC_END;
HRESULT hRet = HybridDirectSoundBuffer_SetHeadroom(pThis->EmuDirectSoundBuffer8, dwHeadroom,
pThis->Xb_Volume, pThis->Xb_VolumeMixbin, pThis->EmuFlags, &pThis->Xb_Voice);
pThis->Xb_VolumeMixbin, pThis->EmuFlags, &pThis->Xb_Voice);
return hRet;
}
@ -1209,8 +1209,7 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetMixBinVolumes_8)
LOG_FUNC_END;
HRESULT hRet = HybridDirectSoundBuffer_SetMixBinVolumes_8(pThis->EmuDirectSoundBuffer8, pMixBins, pThis->Xb_VoiceProperties,
pThis->EmuFlags, pThis->Xb_Volume, pThis->Xb_VolumeMixbin,
&pThis->Xb_Voice);
pThis->EmuFlags, pThis->Xb_VolumeMixbin, &pThis->Xb_Voice);
return hRet;
}