armory3d / armory

3D Engine with Blender Integration
https://armory3d.org
zlib License
3.05k stars 317 forks source link

Krom and Windows (C) builds playing at a higher speed with 120hz monitor. #3014

Open moisesjpelaez opened 4 months ago

moisesjpelaez commented 4 months ago

Description Krom and Windows (C) builds are played at a higher speed. The Krom build also plays the audio at a higher pitch.

To Reproduce Open the project's .wav files Run the project with Krom Runtime. Run the project with Browser Runtime. Compare the differences.

Expected behavior To run the game at a normal speed on Windows Builds (same speed as browser builds).

System Blender: 3.6.10 LTS Armory: 2024.02 OS: Windows 11 Home (x64) Graphics card: NVIDIA GeForce RTX 3050 Ti Laptop

Test File Can be tested with the sound example. The handle spins faster on Windows builds (both C and Krom) and the audio pitch is higher with Krom.

Note: I haven't tested Mac or Linux builds.

moisesjpelaez commented 1 month ago

image image

It seems the problem is in kha.System.refreshRate in Krom builds, as is giving me 60 instead of 120 as shown in the images.

moisesjpelaez commented 2 weeks ago

After digging into Kha's code I realized the Display.frequency is hardcoded to 60 for all platforms except html5.

I found a temporary solution for my case, which is modifying Kha's Scheduler as shown in the images. Forcing the oneifhz variable to be 1.0 / 120.0 solves this speed issue.

image image

I tested it with my:

and the frequency keeps consistent across all those devices.

The audio issue with Krom is another thing that I'll open in a different issue.