FNA-XNA / FAudio

FAudio - Accuracy-focused XAudio reimplementation for open platforms
https://fna-xna.github.io/
Other
548 stars 73 forks source link

Volume meter on Mixer with empty send list #243

Closed W4RH4WK closed 3 years ago

W4RH4WK commented 3 years ago

We are using FAudio for porting an video game that uses XAudio. We discovered a discrepancy between FAudio and XAudio, although I am not sure whether the game is actually following the XAudio specification.

The game uses a dedicated mixer with the VolumeMeter effect attached to measure volume levels. This mixer is completely separate from the main mixer(s) used for playing sound effects. Certain sounds (mainly voice lines) are passed to one of the main mixers as well as this dedicated mixer for volume measurement.

Naturally, this results in the sound to be played twice as loud, since you are feeding it to two mixers in parallel. Setting the volume to 0 for the VolumeMeter mixer does not work as volume levels are calculated after the volume setting of the mixer is applied.

The workaround of the original developers was to initialize this dedicated mixer with an empty send list. Adapted, the code looks like this:

FAudioVoiceSends sendList;
sendList.pSends = NULL;
sendList.SendCount = 0;
FAudio_CreateSubmixVoice(m_pXAudio2, ppDestMixerVoice, m_uiOutputDeviceAudioChannels, m_uiOutputDeviceSampleRate, 0, 0, &sendList, &chain);

Apparently this works in XAudio, having the desired effect of being able to measure volume levels without having the mixer actually outputting sound. In FAudio, due to the empty send list, the process function of the VolumeMeter effect is never executed.

flibitijibibo commented 3 years ago

Interesting, this probably means you just have to move the SendCount check to below XAPO processing. The only other place I can think of where this might matter is SetEffectChain which might use SendCount for the final output format, but I'd have to double check. Try moving the SendCount checks in MixSource/MixSubmix and see if that's enough to fix it.

W4RH4WK commented 3 years ago

I just moved the SendCount checks down, and it resolves my issue. So far sound is still working. However, I can't say whether this breaks anything else. The PR is up.