elishacloud / Silent-Hill-2-Enhancements

A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC. It also includes scripts to build or modify SH2 audio files (SFX, BGM and Dialog).
http://www.enhanced.townofsilenthill.com/SH2/
zlib License
597 stars 42 forks source link

Remove stutter when in-game cutscenes call voice.asf file #506

Closed Polymega closed 2 years ago

Polymega commented 2 years ago

This has been casually brought up for a couple years now, so I figure I ought to make it "official" with its own ticket.

For in-game cutscenes, when the game calls the voice.asf file to retrieve the appropriate dialogue audio, it will momentarily stutter the game. I've recorded a handful of cutscenes in the video below to illustrate. When you hear the beep is when the stutter happens:

https://youtu.be/GIXchmWy5mQ

If the associated dialogue audio starts at the same the time the cutscene starts you don't notice it. But if the audio is called midway through, that's when it's noticeable. Some cutscenes this issue appears more obvious than others.

The immediate/noticeable concern here is that the voice.afs file, which is a container file for all the individual dialogue audio files, is ~1.5 GB in size. So the game has to call a 1.5 GB file to retrieve a single audio file within it each time. I don't know if anything can be done for this due to that reason, but we've worked miracles before. 🤞

Polymega commented 2 years ago

Some potential good news here. I replaced all 159 dialogue audio with a 111 KB wav file of a man saying "This is a test." Collectively, this makes the voice.asf file 17 MB, which is tiny.

Even with this tiny file the game stutters exactly the same. This tells me maybe it doesn't have to do with the size of this file, so maybe it's something that can be fixed.

Here is this test voice.asf file for anyone else to use. Just make sure you make a backup of your real voice.asf first: voice.zip

Note: I haven't done a full playthrough with this test file, so it may break the game on parts that loop. There are loop points set in certain audio tracks and these test tracks are like two seconds long which may break looping points. I'm not sure.

elishacloud commented 2 years ago

When I looked into this before I noticed that during the stutter the game was calling tons of Direct3D functions. In some cases, 10 times more calls than a "normal" frame. I believe these "extra" function calls could be what is causing the stutter or the momentary game pause.

TheMachineAmbassador commented 2 years ago

Hello, today i did a research on this issue. Unfortunately it seems this is a another adx issue, The proof is 0x055c5c7 (prepares memory control buffer for adx) when you nop this you'll notice there is no issue anymore but of course it never plays adx audio :).

Polymega commented 2 years ago

Unfortunately it seems this is a another adx issue

Blah. So Gemini is doing something crazy and rewriting the ADX handling for this game. Maybe we should pause this issue for now until we see where Gemini's work takes us. Perhaps it may address/fix this issue?

TheMachineAmbassador commented 2 years ago

Well... Yeah i was thinking a bit different but at the end thing is we doesen't even have any adx documentation for a reference. I mean i searched whole internet but didn't find resource for our work. Url I was looking at this site, maybe someone reverse engineered one of the games in this list and found this https://github.com/Sewer56/CriFsHook.ReloadedII i don't know can we use this on our project but maybe i can find further more that might help to us.

Polymega commented 2 years ago

I don't want to count our chickens before they hatch but Gemini's rewrite of ADX audio handling for the game very well might fix this. ☺️ There's still work to be done, but his current test builds fix this problem!

TheMachineAmbassador commented 2 years ago

Yeah, i saw it 😀 it's great how this game's audio issues fixed after whole years. So we can tell this game's pc version is now much more better than ps2 version 😊. It was already perfect with whole graphics improvement, soft shadows, upscaled images and more but now this multiple core support, it completes the puzzle.

umbrellacorp53 commented 2 years ago

but his current test builds fix this problem!

Hmm... Test build you say? Is it ready enough to drop some files onto the Steam Deck for a preliminary test or is it still too raw/not integrated into EE?

Polymega commented 2 years ago

Still too raw. The build I was testing was only working with vanilla SH2 PC. Gemini is still in the process of fully implementing it to this module. There are also some optimization tasks needed for it, so if you were to test it now you'd experience stutters that you might mistake for Steam Deck issues.

Edit: Holy typos, I must be tired.

umbrellacorp53 commented 2 years ago

I just got caught up on the other thread. Amazing work. As I said over there, when it gets to the testing phase I'll be right on it.

Polymega commented 2 years ago

I'm closing this ticket as this issue is officially resolved thanks to Gemini's new Criware audio reimplementation. 🥳 You can use a test build with this feature until the next official update: https://github.com/elishacloud/Silent-Hill-2-Enhancements/files/8568012/d3d8.zip