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

Input Lag in Hatsune Miku Project Diva 2nd #4020

Closed
GamerzHell9137 opened this issue Oct 1, 2013 · 52 comments
Closed

Input Lag in Hatsune Miku Project Diva 2nd #4020

GamerzHell9137 opened this issue Oct 1, 2013 · 52 comments

Comments

@GamerzHell9137
Copy link

It seems that the most important part of a Rhythm games, the inputs, are delaying in Project Diva 2nd.
It works normal on JPCSP but on PPSSPP it doesn't.
And just want to say that Project Diva Extend doesn't suffer of that problem.

@unknownbrackets
Copy link
Collaborator

I thought there might've already been an issue for this? I think someone said toggling some settings improved it. Maybe I'm wrong.

How far off is it? Like very noticeable, or just enough to screw up timing? Are you using a controller, Android, Windows...?

-[Unknown]

@solarmystic
Copy link
Contributor

I have this game, and on the latest revision (0.9.1-1463, tested hours ago) using my Core 2, ATI 4670 and Windows 7 x64 SP1 system, it's still pretty much perfect in terms of the timing, when using either my Keyboard or my wired x360 for Windows controller.

I'll wait for @thedax to chime in too, since he has this game and regularly boots it up for testing purposes. (jukebox etc) Basically, this game has been one of the crown jewels in terms of compatibility in PPSSPP for a long time, and it is possible to finish (0 - 100%) the game on Hard (tested) without too much trouble (on a controller) if you're a proficient enough player on PPSSPP.

Now there are other games that significant input timing issues like Patapon 1 for example (inability to maintain Fever status easily), but not this one, at least from my end. There was also a Low Latency Audio option that was merged into master quite a long time ago that was supposed to help as well for those other games.

The user has got to be using Windows (or some desktop OS), since he/she mentions that JPCSP does not have the same issue.

EDIT:- Using FXAA introduces some input lag on my end it seems (even with consistent 100% speed), I've been testing this game all this while without FXAA, since default settings don't involve using it.

@hrydgard
Copy link
Owner

hrydgard commented Oct 2, 2013

I'm surprised FXAA would cause a noticable difference to lag, it shouldn't unless your GPU is really, really slow. Placebo effect?

Some graphics drivers will automatically triple buffer, which can cause an extra frame of lag if implemented badly. There are hacks around that, which might help too.

@GamerzHell9137
Copy link
Author

@unknownbrackets Its noticeable on the highest difficult where you need to press more buttons

@solarmystic I finished the game and i'm only aiming at Perfect on Extreme difficulty

@hrydgard FXAA enabled and its still the same, no differences.

And i'll upload a video showing the same song on Project Divan 2nd and Extend,maybe that can help to see where the issue is.

@unknownbrackets
Copy link
Collaborator

Note that some keyboards may have lag or errors when you press multiple buttons at the same time in quick sequence. Probably a usb controller would work better here, but unfortunately on Windows currently they are all polled 60 times a second (so they may not be sampled frequently enough.)

This situation may be better or worse on Android, I'm not sure (probably better, assuming things can keep up...?)

So changing your input method may affect it. Theoretically, mouse might actually be the most accurate... unless you have an expensive keyboard, in which case it's probably fine.

-[Unknown]

@GamerzHell9137
Copy link
Author

I'm using a gamepad, to be exact a Sony PSOne gamepad.
And i tried keyboard too, nothing changed.
Here's the video btw http://www.youtube.com/watch?v=MdZBJrwDlAs&feature=youtu.be

@GamerzHell9137
Copy link
Author

Here u can clearly see that there's something wrong.

http://www.youtube.com/watch?v=n6ycPGS5JqM&feature=youtu.be

@sanitysama
Copy link

sometimes presses are registered twice, most of the time they are just unreasonably desynched. for example, you may try to hit whole notes like this PA-PA-PA-PA, but it ends up coming out like PA-PAPA--PA.

tried a wireless keyboard, wired keyboard, wired ps3 controller. all have the same input lag. not going to try any more input methods as all the users here have reported the problem with a variety of different hardware, it's clearly the emulator's issue.

putting it bluntly the lag issue makes the game pretty unplayable on all difficulties. project diva games have always been really stingy about timing. the only way to play is to compensate for lag by hitting notes before they match up.

@GamerzHell9137
Copy link
Author

@unknownbrackets
Hey i have checked the game a little and tried many things on the emulator.
Enabling Multithreading and Non Buffered Rendering, fixes the input lag in game but there are lots of graphical issues that make the game unplayable, like the GUI of the game disappearing the the notes too, flickering screen and sound getting unstable, the animation too cause the frames drop to 6-7 FPS and get back to 30 FPS.

Can you investigate more around multihtreading with non buffered rendering?

Setting the game to Buffered/CPU/GPU Rendering with multithreading fixes the graphical issues but input lags come back.

EDIT:The Non Buffered Rendering + Multithreading Method might not be 100% sure that could fix it, its almost unplayable on it so i can't give you a 100% answer to that. If things wouldn't jump in and out and there wasn't the flickering i could give you a straight answer.

@unknownbrackets
Copy link
Collaborator

If that helps it just means your device is too slow, I think. Both of those impact performance and not input at all.

Multithreading ONLY impacts the GPU right now. It doesn't make input or audio multithreaded. So, if that helps, it helps because of better timing.

Same with buffered rendering. If turning that off helps, it just means it's spending less time drawing.

-[Unknown]

@unknownbrackets
Copy link
Collaborator

So, I did some tests. With my PS1 controller and adapter (which is DirectInput), I seem to only get analog changes with a resolution of 0.072052 seconds between changes. That's like 14 fps at best. About the same for buttons and HAT: 0.071762.

The sample resolution is definitely better than that. I wonder if it's just my controller, though.

-[Unknown]

@hrydgard
Copy link
Owner

Could be your adapter, too.

@unknownbrackets
Copy link
Collaborator

Right, sorry I meant either one. I kinda doubt DirectInput is that bad. And I assume XInput must be better. But I wonder what resolution we can get.

It's fairly easy to test. Just log the real_time_now() change whenever the joystick state is altered, and then unthrottle PPSSPP while you mash buttons. Since it's unthrottled, it'll sample more times per second.

Actually, I think we may only sample 30 times per second if the game is 30 fps, now that I just say the above...

-[Unknown]

@GamerzHell9137
Copy link
Author

Idk what u guys are talking about but i'm happy that there is still some progress here.

@unknownbrackets
Copy link
Collaborator

@hrydgard so, aside from my poor DirectInput support, it's pretty clear from #3318 that sampling the controllers is currently done at the game's framerate.

On Windows, splitting it off to a thread would be an easy way to solve this, where they could poll the controllers 120 times per second, for example.

However, on Android, that won't ultimately help. I think controllers are actually processed on a separate thread there, but the on-screen buttons aren't. Ideally, we should check those 60 times per second even when the game runs at 30 fps. And SDL/Blackberry/etc. have the same issue even with controllers.

So... we could still exit the loop and not flip I guess? Or add a NativeSomething to process input only? May still thread up the inputs on Windows to be sure.

-[Unknown]

@hrydgard
Copy link
Owner

Hm. On Android, touch events are immediately sent through to the app through NativeTouch and there is no buffering apart from any that the Android OS does for us. The old touch buttons were updated once per frame but the current ones update instantly, I think. So display framerate should be irrelevant.

There are two other issues causing latency on Android though:

  • Audio latency: To get on the "fast path" that many modern devices support we have to output at the system native sample rate, many devices have 48khz while we output 44.1. We should support 48khz and resample ourselves.
  • Triple buffering - there are ways to force double buffering instead but it does have performance impact. Been meaning to look into this for a while, just like many other things....

@unknownbrackets
Copy link
Collaborator

Here's something to try:
https://github.com/unknownbrackets/ppsspp/compare/lagsync

You'll need to build this branch, and then edit your ini (maybe run and close PPSSPP first just to get the setting in there):

ForceLagSync = True

This will keep the game clock and real world clock in sync approx every 1ms.

Things to understand about this:

  • This will make games slower unless your system is fast enough to emulate the game realtime.
  • Multithreading may improve performance -if- when you lose FPS (although it still has a few bugs.)
  • This may not work well on Android.
  • The faster your computer and graphics, the more this may help lag issues.
  • This should give you better accuracy for input, audio, and network communication. Anything that interacts with the outside-emulation world.

Anyway, I don't really have a test case for the latency and I'm not a twitch game person, so this isn't well tested. But in theory it ought to work.

-[Unknown]

@solarmystic
Copy link
Contributor

@unknownbrackets
I'm not one of those facing the input lag issue in both Project Diva games (2nd and Extend) personally, but I'd still be interested in seeing how the gameplay would be altered/improved by your branch. Will report back once built and tested.

@solarmystic
Copy link
Contributor

@unknownbrackets
Okay, so apparently the gameplay experience is rather mixed for me when enabling the ForceLagSync option in the ini file.

First up, the good:-

Instananeous inputs during gameplay. Somehow the game registers them even better than before, even though it was okay for me before this.

The bad:-

The games don't ever hit full Speed now, they go close to it but not quite there, almost as if the emulators framelimiter is borked. This is not a hardware performance issue since if I unthrottle the framerate, it shoots up to the hundreds. Seems like it's only hitting 95-97% which makes the audio very stuttery.

Here's a screenshot of what I mean:-

capture

I guess my ancient Core 2 laptop isn't quite powerful enough to enable this option and still get 100% Speed ingame. I did notice that 1 core of the CPU is being completely maxed out by the program with this option enabled with MT disabled of course.

@daniel229
Copy link
Collaborator

Yes,I tried patapon 3,also hitting30/30(96-97%).

@unknownbrackets
Copy link
Collaborator

Again, it's syncing to the cpu every 1ms. If emulating any 1ms chunk of game takes longer than 1ms, this means it will be slower overall. That's why we don't do this normally. Please re-read the bold part of my comment.

It could be potentially made more adaptive, at least with some room for error, but this was just an experiment to see the effect on lag. But either way, if your system can't keep up realtime, then it's going to make you lose fps.

How we normally do it:

|-----1-----2-----3-----4-----5-----6------| <-- time showing on your watch
|123--------------------456----------------| <-- when the game actually executes

This makes it:

|-----1-----2-----3-----4-----5-----6------| <-- time showing on your watch
|-----1-----2-----3-----4-----5-----6------| <-- when the game actually executes

This incurs a speed penalty, because if anything takes too long in the normal method, it looks like this:

|-----1-----2-----3-----4-----5-----6------| <-- time showing on your watch
|1222222223-------------45555555556--------| <-- when the game actually executes

See how it's still okay? That's not happening anymore:

|-----1-----2-----3-----4-----5-----6------| <-- time showing on your watch
|-----1-----222222223-----4-----5555555556-| <-- when the game actually executes

Now you're lagging behind.

But, the upside is your watch on your wrist matches the watch on the game, every millisecond, instead of just 30 or 60 times per second as before.

-[Unknown]

@GamerzHell9137
Copy link
Author

@solarmystic Mind if you share the build?

@daniel229
Copy link
Collaborator

Turn on multithreaded,It's stable on 100%,I think it's not that demanding.

@solarmystic
Copy link
Contributor

@GamerzHell9137
Here:- https://www.mediafire.com/?aap6dcs26u12553
(unzip the exe using 7z and place it in any working PPSSPP folder that you can get from the buildbot. Then, follow [Unknown]'s instructions with the ppsspp.ini file.)

@solarmystic
Copy link
Contributor

@daniel229
Hmm.. you're right, Multthreaded makes it better when Lagsync is enabled. Getting 100% Speed all the time now.

Interestingly enough, the FPS issue that usually happens with the Project Diva games when Multithreaded is enabled does not exist when Lag Sync is also enabled.

@GamerzHell9137
Copy link
Author

Tried, the input difference is huge in Extend but in 2nd its almost the same.
With multithreaded and without it i get same 60 speed and 30 FPS but with multithreaded it looks like its faster but find the input a bit slow.
CPU max usage is 70% with and without multithread.

@yanthey
Copy link

yanthey commented Jun 1, 2014

How about android?

GamerzHell9137 [email protected] wrote:

Tried, the input difference is huge in Extend but in 2nd its almost the same.
With multithreaded and without it i get same 60 speed and 30 FPS but with multithreaded it looks like its faster but find the input a bit slow.
CPU max usage is 70% with and without multithread.


Reply to this email directly or view it on GitHub.

@GamerzHell9137
Copy link
Author

@yanthey Quoted from Unknown

[ This may not work well on Android. ]

@daniel229
Copy link
Collaborator

ForceLagSync = True,make the game #6196 staying on 100%
01

ForceLagSync = False
02

@unknownbrackets
Copy link
Collaborator

Yes, it will also correct timing in games that flip in weird ways that we don't handle well.

You can try it on Android but on some devices I can definitely see it making audio lag worse.

-[Unknown]

@yanthey
Copy link

yanthey commented Jun 1, 2014

Bad, this game can't load save data on my android.

"Unknown W. Brackets" [email protected] wrote:

Yes, it will also correct timing in games that flip in weird ways that we don't handle well.

You can try it on Android but on some devices I can definitely see it making audio lag worse.

-[Unknown]


Reply to this email directly or view it on GitHub.

@yanthey
Copy link

yanthey commented Jun 1, 2014

Sorry, save data work fine,, but final fantasy crisis core force close on new build of ppsspp.

"Unknown W. Brackets" [email protected] wrote:

Yes, it will also correct timing in games that flip in weird ways that we don't handle well.

You can try it on Android but on some devices I can definitely see it making audio lag worse.

-[Unknown]


Reply to this email directly or view it on GitHub.

@unknownbrackets
Copy link
Collaborator

If #6220 / the lagsync branch doesn't help 2nd, I don't know what could be wrong with its input timing. This was the only thing left that I knew about.

-[Unknown]

@GamerzHell9137
Copy link
Author

@unknownbrackets Nope, Lagsync doesn't fix 2nd but it helps a bit.
But there's one thing that's been in my head, the sound that it makes when you press a button its a tad bit late than it needs to be and the notes are slow moving in songs (notes not in sync with the song).

Maybe the 2D elements(HUD) are making some kind of issue with the game?

The other thing is that in each song the sync may be better or worse, dunno why.
Notes move faster in 1 song than in other and stuff like that.

Ohh and one more thing, Multithread makes the input worse in both Extend and 2nd.

@unknownbrackets
Copy link
Collaborator

So, ignoring multithreading which has its own issue, is this still an issue with recent changes?

-[Unknown]

@GamerzHell9137
Copy link
Author

@unknownbrackets I still find the Solarmystic's 2nd build better.
Right now in the latest master build, i don't feel free while playing it.
The input is more forced for me than in his build.
When i play it on master build i feel that i'm forced to press it on the right time PPSSPP tells me and not the songs themself.
While on Solarmystic's 2nd build i feel free from pressing it with the song itself and not when PPSSPP dictates me.

@GamerzHell9137
Copy link
Author

@unknownbrackets And one more thing, the master build eats the input too.
There's a part in a song where i need to press 11 times 1 button but on the master build i gotta press the button 12-15 times to get the 11 buttons in game.

I've recorded myself and slowed down the footage so see if i'm 100% sure about it cause during gameplay i felt that i did press the button more than i should.

In Solarmystic's 2nd build 11 button presses is 11.

@GamerzHell9137
Copy link
Author

No new reports about the game, it plays the same on 0.9.9.1 too.
IUnput lag btw the controller and game and sound doesn't sync the right way.
The controller is not the issue cause i cna play with the same controller on my PS3.
Have tested the game on PS3 too, works fine there.
And i don't judge my skills in the game cause i'm pretty sure that i hit the right timing in the Diva games.

-project diva- f 2nd_2

https://www.youtube.com/watch?v=7f8IRWZNuug&feature=youtu.be

@PierBover
Copy link

I'm playing the three Patapon games and I get a lag of about 300-400 ms, which makes it impossible to play. I've tried both Android and Windows, bluetooth controllers, wired controllers, and keyboards, with the same result. I have tried changing all options related to sound, input, graphics, etc, with no success.

I don't have noticed the lag on other games, but it may be because timing is not so critical...

Im on 1.0.1

@Wowfunhappy
Copy link

Some good news, as of 1.4.2-198, this game no longer appears to have any sync/timing issues.

I'm using Mac build, on a machine that previously had lag issues when I last tried (around ppsspp v1 if I remember correctly). Audio latency is set to low in settings.

If you've had issues running the Project Diva games in the past, you may want to try again!

@GamerzHell9137
Copy link
Author

@Wowfunhappy its same, there's been no changes.

@Wowfunhappy
Copy link

Well, that's odd, because it definitely improved for me on the same machine—the game was unplayable before. I suppose something else in my system could theoretically have changed though.

@GamerzHell9137
Copy link
Author

Improved? Yes. Like it should be? No.

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Feb 24, 2019

Just a note, as seen in #11813, the real clock sync setting was buggy before but should work correctly now. Note that as per #10195, if you're using OpenGL of Vulkan, you're likely to have some lag in the screen updating versus what's happening in the game.

It might be worth trying this now with the force sync setting enabled and using D3D9 or D3D11. Note that forcing clock sync is slower, and works best on Linux/Mac (Windows will have an additional ~2ms input lag because of how its timing functions work, but they work accurately on Linux/Mac/Android - of course Android doesn't have D3D.)

-[Unknown]

@GamerzHell9137
Copy link
Author

@unknownbrackets Other than Force Real Sync and DX9/11, any other option that can improve the input lag on Windows?

@unknownbrackets
Copy link
Collaborator

Well, the lower quality settings are presumably better. Make sure you're not using locked CPU speed or any audio hacks. In theory, non-buffered rendering might have slightly less lag (I'm not sure.)

Just to mention, it's entirely possible that the physical PSP has some input lag (the LCD was slow) and that these games account for it by applying a negative offset to controller input. In some ways, this could explain the earlier comments about multithreading improving the situation.

If the game does that (once #10195 is fixed, which most likely? is slower than the PSP would be), the problem could be that we're BETTER than the PSP, and so the offset the game uses goes in the wrong direction and makes it think your presses are too early.

That means there might be a "goldilocks zone" for input lag. "My score was lower than expected" is a binary measurement, so it will be difficult to zero in on the +/- of that zone if there's no way to say "I average too late" or "I average too early" compared to playing on a PSP.

-[Unknown]

@GamerzHell9137
Copy link
Author

GamerzHell9137 commented Feb 24, 2019

@unknownbrackets Yeah, non buffered makes the input better but in general it feels almost the same. A bit better but yeah, still feels "weird". Don't have a PSP but its funny how Vita and PPSSPP on PC feel different with the input.

About input offsets, is it possible to implement something like that in PPSSPP? The newer Diva games have the option on PS3 and PS Vita which compensates for LCD lag. Still idk if that would fix it, PPSSPP always had this feeling of "you press the button but the game reacts later to it".

And I remember before Megpoid the Music # had less input lag with higher refresh rate monitors (played on 75 Hz), i guess the game reacts different than Diva because it didn't help Diva with input.

I think i talked before about Exclusive Fullscreen mode, that might lessen the input lag because in borderless Windows is forcing its vsync and adds a lot of input lag.

@unknownbrackets
Copy link
Collaborator

The trouble is that it's game logic applying the offset.

Retroarch implemented something for NES games that basically uses savestates every single frame. But NES games had about 4KB of RAM, the PSP has 8000 times as much. For a PSP, saving state every frame is too slow and would CAUSE input lag, not solve it. RAM has only gotten about ~30 times faster maybe since the NES; size gains have outpaced speed gains.

It might be possible for someone to create a cwcheat or hack to adjust the input lag offset the game logic uses - assuming it even exists.

Basically it would have to change the logic so that the "right time" to press a button and get a score is +input lag ms after it's actually displayed. PPSSPP has to run the game logic to generate graphics, so it only has the ability to move everything together (without the save state thing I mentioned above, which really is a smart idea, but as I said not practical for a PSP game.)

-[Unknown]

@GamerzHell9137
Copy link
Author

That sucks, welp i guess we gotta wait for that #10195 fix

@LunaMoo
Copy link
Collaborator

LunaMoo commented Feb 24, 2019

Imo input lag offset wouldn't cause people with this issue to get better at the game, I would rather say that the "Input lag" imo should be even less of a problem in rhytm games than any other genre as even without game offsetting it, such games are awfully predictable and any player could offset it himself or starting playing on an emulator even not feel anything wrong with it.

I do believe based on ways DrawSyncEatCycles hack noticably affecting some of those games(even fixes #9842) and older issue about patapon 1 fever being hard to keep (#2498 ~ which I believe might still be an issue), that the actual problem is that some key presses are expected to happen at different timing than the rest, I recall we had some thread on forum about Patapon 1(long after the issue about it was closed hence I believe it's still a thing) where I helped someone to track some code in disassembly and from that I recall that fourth beat had different timing than the previous 3 when the fever was up, making it much harder to keep, but since it was weird in same way each time, eventually I couldn't tell if it was really broken or not since I got used to it after a few failures..

PS Vita also has imperfect PSP emulator, definitely not cycle accurate, despite being an "official emulator" it's likely even less compatible than PPSSPP at this point in time and should never be used as an example of how games should work on the real hardware.

@Leopard20
Copy link
Contributor

Leopard20 commented Feb 25, 2019

Just wanted to let you know that enabling real clock sync on Android as well significantly improves the input lag (Vulkan and OGL). There's still a tiny bit of lag as mentioned, but it's negligible compared to before. Finally the game is playable! Thanks.
PD Extend still plays best (almost completely lag-free) in all diva games.

@unknownbrackets
Copy link
Collaborator

I feel like there haven't been many people saying this isn't good for a while, and #10195 already covers "all" Proejct Diva games, which presumably includes Project Diva 2nd. So I'm going to just close this as a duplicate (even though that was opened more recently.)

-[Unknown]

@unknownbrackets unknownbrackets closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests