Merge pull request #1993 from CookiePLMonster/dsound-improvements-alt
DSound improvements (alternative volume heuristics)
This commit is contained in:
commit
f8593e692d
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "common/XADPCM.h"
|
#include "common/XADPCM.h"
|
||||||
#include "core/hle/DSOUND/XbDSoundTypes.h"
|
#include "core/hle/DSOUND/XbDSoundTypes.h"
|
||||||
|
@ -1289,49 +1290,35 @@ static inline HRESULT HybridDirectSoundBuffer_SetMixBinVolumes_8(
|
||||||
{
|
{
|
||||||
HRESULT hRet = DSERR_INVALIDPARAM;
|
HRESULT hRet = DSERR_INVALIDPARAM;
|
||||||
|
|
||||||
if (pMixBins != xbox::zeroptr) {
|
if (pMixBins != xbox::zeroptr && pMixBins->lpMixBinVolumePairs != xbox::zeroptr) {
|
||||||
DWORD counter = pMixBins->dwCount, count = pMixBins->dwCount;
|
LONG maxVolume = DSBVOLUME_MIN;
|
||||||
LONG volume = 0;
|
|
||||||
if (pMixBins->lpMixBinVolumePairs != xbox::zeroptr) {
|
|
||||||
// Let's normalize audio level except for low frequency (subwoofer)
|
// Let's normalize audio level except for low frequency (subwoofer)
|
||||||
for (DWORD i = 0; i < count; i++) {
|
for (DWORD i = 0; i < pMixBins->dwCount; i++) {
|
||||||
// Update the mixbin volume only, do not reassign volume pair array.
|
// Update the mixbin volume only, do not reassign volume pair array.
|
||||||
for (DWORD i = 0; i < count; i++) {
|
|
||||||
const auto& it_in = pMixBins->lpMixBinVolumePairs[i];
|
const auto& it_in = pMixBins->lpMixBinVolumePairs[i];
|
||||||
for (DWORD ii = 0; ii < Xb_VoiceProperties.dwMixBinCount; ii++) {
|
auto it_out = std::find_if(Xb_VoiceProperties.MixBinVolumePairs, Xb_VoiceProperties.MixBinVolumePairs+Xb_VoiceProperties.dwMixBinCount,
|
||||||
auto& it_internal = Xb_VoiceProperties.MixBinVolumePairs[ii];
|
[&it_in](const auto& e) {
|
||||||
|
return e.dwMixBin == it_in.dwMixBin;
|
||||||
|
});
|
||||||
// Once found a match, set the volume.
|
// Once found a match, set the volume.
|
||||||
// NOTE If titles input duplicate with different volume,
|
// NOTE If titles input duplicate with different volume,
|
||||||
// it will override previous value.
|
// it will override previous value.
|
||||||
if (it_in.dwMixBin == it_internal.dwMixBin) {
|
if (it_out != Xb_VoiceProperties.MixBinVolumePairs+Xb_VoiceProperties.dwMixBinCount) {
|
||||||
it_internal.lVolume = it_in.lVolume;
|
it_out->lVolume = it_in.lVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since we cannot set per-channel volumes, we want to pick "dominant" volume
|
||||||
|
if (it_in.dwMixBin != XDSMIXBIN_LOW_FREQUENCY && it_in.dwMixBin < XDSMIXBIN_SPEAKERS_MAX) {
|
||||||
|
if (it_in.lVolume > maxVolume) {
|
||||||
|
maxVolume = it_in.lVolume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // This code isn't ideal for DirectSound, since it's not possible to set volume for each speakers.
|
Xb_volumeMixBin = maxVolume;
|
||||||
if (pMixBins->lpMixBinVolumePairs[i].dwMixBin != XDSMIXBIN_LOW_FREQUENCY
|
|
||||||
// We only want to focus on speaker volumes, nothing else.
|
|
||||||
&& pMixBins->lpMixBinVolumePairs[i].dwMixBin < XDSMIXBIN_SPEAKERS_MAX) {
|
|
||||||
#endif
|
|
||||||
if (pMixBins->lpMixBinVolumePairs[i].dwMixBin == XDSMIXBIN_FRONT_LEFT
|
|
||||||
// We only want to focus on front speaker volumes, nothing else.
|
|
||||||
|| pMixBins->lpMixBinVolumePairs[i].dwMixBin == XDSMIXBIN_FRONT_RIGHT) {
|
|
||||||
volume += pMixBins->lpMixBinVolumePairs[i].lVolume;
|
|
||||||
} else {
|
|
||||||
counter--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (counter > 0) {
|
|
||||||
Xb_volumeMixBin = volume / (LONG)counter;
|
|
||||||
int32_t Xb_volume = Xb_Voice->GetVolume() + Xb_Voice->GetHeadroom();
|
int32_t Xb_volume = Xb_Voice->GetVolume() + Xb_Voice->GetHeadroom();
|
||||||
hRet = HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, EmuFlags,
|
hRet = HybridDirectSoundBuffer_SetVolume(pDSBuffer, Xb_volume, EmuFlags,
|
||||||
Xb_volumeMixBin, Xb_Voice);
|
Xb_volumeMixBin, Xb_Voice);
|
||||||
} else {
|
|
||||||
hRet = DS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hRet;
|
return hRet;
|
||||||
|
|
Loading…
Reference in New Issue