Skip to content

Commit 1bdbca3

Browse files
committed
Feat: Set timer resolution (1ms)
1 parent fc56aba commit 1bdbca3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

BabbleApp/babbleapp.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import queue
2222
import requests
2323
import threading
24+
from ctypes import windll, c_int
2425
from babble_model_loader import *
2526
from camera_widget import CameraWidget
2627
from config import BabbleConfig
@@ -34,6 +35,13 @@
3435
from winotify import Notification
3536
os.system('color') # init ANSI color
3637

38+
winmm = None
39+
try:
40+
winmm = windll.winmm
41+
except OSError:
42+
#print("[DEBUG] Failed to load winmm.dll")
43+
pass
44+
3745
# Random environment variable to speed up webcam opening on the MSMF backend.
3846
# https://github.com/opencv/opencv/issues/17687
3947
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
@@ -51,6 +59,15 @@
5159
page_url = "https://github.com/SummerSigh/ProjectBabble/releases/latest"
5260
appversion = "Babble v2.0.6 Alpha"
5361

62+
def timerResolution(toggle):
63+
if winmm != None:
64+
if toggle:
65+
rc = c_int(winmm.timeBeginPeriod(1))
66+
if rc.value != 0:
67+
# TIMEERR_NOCANDO = 97
68+
print(f"[WARN] Failed to set timer resolution: {rc.value}")
69+
else:
70+
winmm.timeEndPeriod(1)
5471

5572
def main():
5673
# Get Configuration
@@ -95,6 +112,8 @@ def main():
95112
print("[INFO] Toast notifications not supported")
96113
except:
97114
print("[INFO] Internet connection failed, no update check occured.")
115+
116+
timerResolution(True)
98117
# Check to see if we have an ROI. If not, bring up ROI finder GUI.
99118

100119
# Spawn worker threads
@@ -219,6 +238,7 @@ def main():
219238
if ROSC:
220239
osc_receiver.shutdown()
221240
osc_receiver_thread.join()
241+
timerResolution(False)
222242
print("\033[94m[INFO] Exiting BabbleApp\033[0m")
223243
return
224244

0 commit comments

Comments
 (0)