shinyquagsire23 / OpenJKDF2

A cross-platform reimplementation of JKDF2 in C
Other
513 stars 43 forks source link

(Audio regression) A small but audible brakes when playing sound effects (almost any sound (weapon select, fire, tusken die, alert, elevator up/down, force jump)) if they are playing for the first time #207

Open Alex3474247 opened 1 year ago

Alex3474247 commented 1 year ago

I have found an audio regression on my Windows 10 64bit system: Sound effects delays, for example, when shooting or selecting a weapon, if these sounds are played for the first time after starting the game. Perhaps this is because of the lack of precaching. For example in Quake in QuakeC source all the played sound effects are precached before use. In video I fire a shot from concussion rifle in level 5 of MotS, a delay is small, but it is present, and moreover, the whole game is delayed (In video I pressed a "fire" mouse button at position 01s 133ms, but the projectile flew out only at 01s 399ms, the delay is ~266ms). I think this is part of the non-decompiled std funtions, perhaps it was named stdPrecache in original source code. Maybe this issue is related with https://github.com/shinyquagsire23/OpenJKDF2/issues/57 ? Edit: Just checked original engine JKM.EXE, no issue, no delay.

https://user-images.githubusercontent.com/17110303/215273775-bd02875e-7eba-459d-bcb8-bcdb196a402f.mp4

shinyquagsire23 commented 1 year ago

At least testing on my own, it turns out that all of the sounds are indeed precached (I think the one exception is that some COGs can load sounds which aren't in the world's list of sounds? But weapons are definitely precached). However, there's a chance that OpenAL is doing something weird with format conversions maybe? If it were in OpenJKDF2 code, there would be a 300ms frame lag, there's no multithreading at all (except in some MP code for getting server lists).

Try creating an alsoft.ini next to the EXE with these contents

# alsoft.ini
[general]
periods = 1

Or try checking to see if there's anything in https://raw.githubusercontent.com/kcat/openal-soft/master/alsoftrc.sample that helps, maybe.

The macOS issue is unfortunately unrelated, in that case it loads a dylib the first time you press arrow/function keys. No clue why really.

Alex3474247 commented 1 year ago

Try creating an alsoft.ini next to the EXE with these contents

alsoft.ini

[general] periods = 1

  • this doesn't help, it seems, and

alsoftrc.sample is, I guess, a guide of how to tweak the openal, I found the similar period_size param, set it as 64, but it doesn't affect the regression significantly. Have not find any other useful param that fits the meaning.

It doesn't seem to help in any way, there is still a delay sometimes. This issue was in previous versions, too. Additional example, it's noticeable in MotS level 4, when the "Warning, cooling system malfunction." ... and etc messages appears, there is a delay. Maybe these debug messages can be useful?

avcore\audiocore\client\audioclient\audioclientcore.cpp(1907)\AUDIOSES.DLL!00007FF803A13EF5: (caller: 00007FFFBFB8CF31) ReturnHr(1) tid(259ec) 80070057 The parameter is incorrect. The thread 0x27708 has exited with code 0 (0x0). The thread 0x257d0 has exited with code 0 (0x0). The thread 0x2574c has exited with code 0 (0x0). 'openjkdf2-64.exe' (Win32): Unloaded 'C:\Windows\System32\wrap_oal.dll' The thread 0x270c4 has exited with code 1 (0x1). The thread 0x25e0c has exited with code 1 (0x1). The thread 0x236a0 has exited with code 1 (0x1). The thread 0x1fd50 has exited with code 1 (0x1). The thread 0x2600c has exited with code 1 (0x1). The thread 0x25938 has exited with code 1 (0x1). The thread 0x2000c has exited with code 1 (0x1). The thread 0x2727c has exited with code 1 (0x1). The thread 0x233fc has exited with code 1 (0x1). The thread 0x275f8 has exited with code 1 (0x1). The thread 0x1a408 has exited with code 1 (0x1). The thread 0x26d34 has exited with code 1 (0x1). The program '[145580] openjkdf2-64.exe' has exited with code 1 (0x1). Edit: Possible updating openal may help.

shinyquagsire23 commented 1 year ago

Hmm, maybe try the latest commit, there's some things I had delayed to stdSound_BufferPlay that I moved to stdSound_BufferUnlock

Alex3474247 commented 1 year ago

It may have been fixed, but I didn't notice it right away. Updated an openal from the latest pre-release. First time there were delays at level 4, in the water where the reactor and 4 switches, the elevator went down, and there was a delay when the elevator is lifting back. But when I exited the game (stop debugging), and runned it again (run debug), no delay in that sound effect. I think openjkdf2 sound precache is still weird, so I recommend you to leave this issue open.

Alex3474247 commented 1 year ago

I think you need to have the same operating system as me, (and probably the same laptop Asus ROG 16 GB RAM Core i7 7700 HQ nVidia Geforce GTX 1060 Windows 10 64 bit v1909, Visual Studio 2019), or Windows 10 64bit v1909 virtual machine to simulate the regression. If you can't, postpone this problem for later.

shinyquagsire23 commented 1 year ago

That's ~fairly close to my VR rig that I've been meaning to do some regression work on (SSAO bugs mostly) so I can probably take a look at it, yeah. Might not be super high priority though, it wouldn't surprise me if the lag is just because I happened to pick a bad OpenAL-soft version for MSVC (does it happen in the MinGW builds?)

Alex3474247 commented 1 year ago

This issue is still present as of 0.8.14, these 260ms brakes still occurs and can occur on playing any weapon / environment / enemies sounds.

shinyquagsire23 commented 1 year ago

Admittedly I've had a difficult time debugging this because afaict everything is buffered correctly, if there were disk access/cache lag it would also lag the rest of the game, and Apple's OpenAL implementation hasn't had any noticable audio lag. Maybe try placing OpenAL32.dll with DSOAL? https://www.pcgamingwiki.com/wiki/Glossary:Surround_sound#DirectSound3D

Alex3474247 commented 1 year ago

No, unfortunately that doesn't fix the problem, even the computer restart doesn't help, and the sound lags occurs pretty frequently, no matter debugging from VS or simply running the exe.