RobertBeckebans / RBDOOM-3-BFG

Doom 3 BFG Edition source port with updated DX12 / Vulkan renderer and modern game engine features
https://www.moddb.com/mods/rbdoom-3-bfg
GNU General Public License v3.0
1.38k stars 247 forks source link

Sound cuts before the end of the startup video #821

Closed Rathmox closed 2 months ago

Rathmox commented 6 months ago

When you enable the intro video and start the game, you can hear the sound cutting before the video ends, when the ID Software logo is displayed.

The original video file doesn't cut at this moment

Steps to reproduce: 1: enable intro video 2: start the game 3: sound cuts before the ed of the intro video

Expected behaviour: Sound keeps playing until the end.

Additionnal info: This doesn't happen on the official game.

Rathmox commented 6 months ago

This has been fixed on DOOM BFA: https://github.com/MadDeCoDeR/Classic-RBDOOM-3-BFG/commit/615ab1b4a025bbccdcd74b175cd3b07d8197ab49

SRSaunders commented 6 months ago

Thanks for catching this. The use case is fairly narrow since it only occurs when playing .bik cinematic files via the ffmpeg decoder, and the missing audio is only about 0.5 seconds at the end. Note the native bundled Bink decoder does not cut off any cinematic audio, and is the default for release builds of the game. The ffmpeg decoder is typically used in debug builds but the issue is observable and valid as you say above.

The reason this happened is that ffmpeg's bik decoder module has a startup delay on the video side, and the audio has to be delayed to match up for proper a/v sync. I used a classic ring buffer to generate the required audio lag which yields a fixed delay period (0.5 sec). However, ring buffers are a bit more complicated to drain (need to keep multiple pointers) so I just didn't bother, figuring that dropping 0.5 seconds at the end would not be very noticeable. But you noticed it, and as you say in the comments, using queues does make solving this easier. I will generate a pull request for RBDoom3BFG - it may be a bit different than the code above, but should be fairly simple on this codebase.

Looking at the changes for DOOM BFA, I am not certain, but it appears that cinematic audio will always continue where it left off from the previous call to ImageForTimeFFMPEG(), and the thisTime parameter is no longer taken into account for the audio steam (video is ok). If you are only playing the intro cinematic from the beginning, this is likely not a concern. But it could be an issue for other use cases if there are pauses, and then a/v sync will be lost.

Rathmox commented 6 months ago

Ok thanks.

I noticed it because I used the DOOM Enhanced versions which have the same intro but working, so I really felt the sound cutting. I compared to the file, and it did not cut. I ended up starting a Windows machine to see if this was originally in the game, and it was not.