Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X3DAUDIO_CALCULATE_ZEROCENTER should be set for proper volume levels returned by X3DAudioCalculate #521

Open
HSNB opened this issue Dec 20, 2024 · 4 comments
Labels
audio Related to DirectX Tool Kit for Audio enhancement question

Comments

@HSNB
Copy link

HSNB commented Dec 20, 2024

It seems that even when there's no Front Center speaker according to the Mastering Voice Channel Mask (SPEAKER_FRONT_CENTER), X3DAudioCalculate will still calculate the matrix volume levels as if there is.

This causes the volume of the sound to play at a lower volume.

For example if you have a 2 channel output (headset), meaning Channel Mask is SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT. It is still needed to set X3DAUDIO_CALCULATE_ZEROCENTER even though the comment of X3DAUDIO_CALCULATE_ZEROCENTER says "valid only for matrix calculations with final mix formats that have a front center channel".

I could be wrong in understanding 3D audio, but if I'm not setting this ZEROCENTER flag what happens is that even a 3D sound playing at a distance of 0 away from the listener, makes the sound play at a lower volume than the actual sound file, which seems like a wrong thing to me?

@HSNB
Copy link
Author

HSNB commented Dec 20, 2024

Note that DirectSound also has this "bug", but in DirectSound there's no way to set a "Zero Center" flag to fix it.

@walbourn walbourn added the audio Related to DirectX Tool Kit for Audio label Dec 20, 2024
@walbourn
Copy link
Member

walbourn commented Dec 20, 2024

Interesting. Thanks for the feedback.

Looking at the source to XAudio3DCalculate, they clearly have validation that enforces the flag as documented:

if (u32Flags & X3DAUDIO_CALCULATE_ZEROCENTER) {
    if (!(u32Flags & X3DAUDIO_CALCULATE_MATRIX) || !(pHandle->u32SpeakerChannelMask & SPEAKER_FRONT_CENTER)) {
        X3DDEBUG_MESSAGE(X3DDEBUG_ERROR, "X3DAUDIO_CALCULATE_ZEROCENTER valid only for matrix calculations with final mix formats that have a front center channel");
        fValid = FALSE;
    }
}

So if there is no FRONT_CENTER in the provided channel mask or you don't have the flag to calculate a matrix set, the debugging logic would say it's not valid.

Furthermore, the actual implementation for X3DAUDIO_CALCULATE_ZEROCENTER uses this flag specifically for the following speaker configs to remove one speaker channel:

SPEAKER_SURROUND
SPEAKER_5POINT1
SPEAKER_7POINT1
SPEAKER_5POINT1_SURROUND
SPEAKER_7POINT1_SURROUND

The other logic for that flag only applies if there are more than 2 speaker channels (since the first two are always left/right and the third is the center).

In other words, I don't see where in the code that flag would impact a 2 channel speaker configuration.

@walbourn
Copy link
Member

walbourn commented Dec 20, 2024

Note that with that said, perhaps I should offer a way to set that flag through DirectX Tool Kit for Audio for scenarios where it is desirable.

@HSNB
Copy link
Author

HSNB commented Dec 20, 2024

In other words, I don't see where in the code that flag would impact a 2 channel speaker configuration.

If you have any project that you can test it with please do, it for sure matters.

mDSPSettings.SrcChannelCount = 1
mDSPSettings.DstChannelCount = 2

Without ZEROCENTER the matrix contains: 0.5 0.5
With ZEROCENTER the matrix contains: 1.0 1.0

XAudio 2.9 Redist on Windows 10.
Also happens in normal XAudio 2.9 (No Redist).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Related to DirectX Tool Kit for Audio enhancement question
Projects
None yet
Development

No branches or pull requests

2 participants