Skip to content

Commit 1cba6d3

Browse files
authored
Merge pull request #53 from SnuffSocket/timer-branch
Feat: Set timer resolution (1ms)
2 parents c61c316 + 9c5da70 commit 1cba6d3

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

BabbleApp/Locale/English/locale.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
"error.frame": "Problem while getting frame",
3636
"error.size": "Size of frames to display are of unequal sizes",
3737
"error.capture": "Frame capture issue detected",
38+
"error.winmm": "Failed to load winmm",
3839
"warn.frameDrop": "Frame drop. Corrupted JPEG",
3940
"warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect",
4041
"warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect",
4142
"warn.backpressure1": "CAPTURE QUEUE BACKPRESSURE OF",
4243
"warn.backpressure2": "CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM",
4344
"warn.oneEuroValues": "OneEuroFilter values must be a legal number",
45+
"warn.timerRes": "Failed to set timer resolution:",
4446
"info.moveToTrackingMode": "Moving to tracking mode",
4547
"info.moveToROIMode": "Moving to ROI mode",
4648
"info.setROI": "Set ROI",

BabbleApp/Locale/OwO/locale.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
"error.frame": "Problem while getting frame",
3636
"error.size": "Size of frames to display are of unequal sizes",
3737
"error.capture": "Frame capture issue detected",
38+
"error.winmmDll": "Failed to load winmm",
3839
"warn.frameDrop": "Frame drop. Corrupted JPEG",
3940
"warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect",
4041
"warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect",
4142
"warn.backpressure1": "CAPTURE QUEUE BACKPRESSURE OF",
4243
"warn.backpressure2": "CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM",
4344
"warn.oneEuroValues": "OneEuroFilter values must be a legal number",
45+
"warn.timerRes": "Faiwed to set timew wesowution:",
4446
"info.moveToTrackingMode": "Moving to tracking mode",
4547
"info.moveToROIMode": "Moving to ROI mode",
4648
"info.setROI": "Set ROI",

BabbleApp/Locale/Pirate Speak/locale.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
"error.frame": "Problem while getting frame",
3636
"error.size": "Size of frames to display are of unequal sizes",
3737
"error.capture": "Frame capture issue detected",
38+
"error.winmmDll": "Failed to load winmm",
3839
"warn.frameDrop": "Frame drop. Corrupted JPEG",
3940
"warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect",
4041
"warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect",
4142
"warn.backpressure1": "CAPTURE QUEUE BACKPRESSURE OF",
4243
"warn.backpressure2": "CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM",
4344
"warn.oneEuroValues": "OneEuroFilter values must be a legal number",
45+
"warn.timerRes": "We be failin' to set th' timer resolution:",
4446
"info.moveToTrackingMode": "Moving to tracking mode",
4547
"info.moveToROIMode": "Moving to ROI mode",
4648
"info.setROI": "Set ROI",

BabbleApp/babbleapp.py

Lines changed: 18 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
@@ -32,8 +33,14 @@
3233
from utils.misc_utils import EnsurePath, is_nt, bg_color_highlight, bg_color_clear
3334
from lang_manager import LocaleStringManager as lang
3435

36+
winmm = None
37+
3538
if is_nt:
3639
from winotify import Notification
40+
try:
41+
winmm = windll.winmm
42+
except OSError:
43+
print(f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.winmm")}.\033[0m')
3744
os.system("color") # init ANSI color
3845

3946
# Random environment variable to speed up webcam opening on the MSMF backend.
@@ -53,6 +60,15 @@
5360
page_url = "https://github.com/SummerSigh/ProjectBabble/releases/latest"
5461
appversion = "Babble v2.0.6 Alpha"
5562

63+
def timerResolution(toggle):
64+
if winmm != None:
65+
if toggle:
66+
rc = c_int(winmm.timeBeginPeriod(1))
67+
if rc.value != 0:
68+
# TIMEERR_NOCANDO = 97
69+
print(f'\033[93m[{lang._instance.get_string("log.warn")}] {lang._instance.get_string("warn.timerRes")} {rc.value}\033[0m')
70+
else:
71+
winmm.timeEndPeriod(1)
5672

5773
def main():
5874
EnsurePath()
@@ -109,6 +125,7 @@ def main():
109125
print(
110126
f'[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.noInternet")}.'
111127
)
128+
timerResolution(True)
112129
# Check to see if we have an ROI. If not, bring up ROI finder GUI.
113130

114131
# Spawn worker threads
@@ -235,6 +252,7 @@ def main():
235252
if ROSC:
236253
osc_receiver.shutdown()
237254
osc_receiver_thread.join()
255+
timerResolution(False)
238256
print(
239257
f'\033[94m[{lang._instance.get_string("log.info")}] {lang._instance.get_string("babble.exit")}\033[0m'
240258
)

0 commit comments

Comments
 (0)