C
C#4mo ago
tncargil

Metronome Click Inconsistent

I am writing a metronome in .net maui and when I run the app on my physical andriod device the click is inconsistent. I am using system.timers.timer is there a more consistent way to play the click.wav? Stopwatch is also too inconsistent.
27 Replies
Angius
Angius4mo ago
IIRC PeriodicTimer should be the most accurate
ACiDCA7
ACiDCA74mo ago
inaccuracies can also happen because iirc System.Timers.Timer dispatches the callback and since you are calling this from a UI thread the callback has to wait until the UIthread processes the dispatch
cap5lut
cap5lut4mo ago
System.Timers.Timer is probably the most accurate thing besides a thread with a busy loop but for time critical stuff u will need a combination of "normal sleeps" and a busy loop, because u cant trust the system clock (on windows thats usually 15ms ticks)
No description
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
System.Timers.Timer is definitealy too inacurate to be precise for time keeping for a metronome can you elaborate more on these normal sleeps and busy loop?
cap5lut
cap5lut4mo ago
thats extreme CPU load but basically, for u Thread.Sleep(x); for the amount of time u have to wait minus 15ms and then u do a while loop measuring the rest of the time and calling Thread.Yield() to wait
tncargil
tncargil4mo ago
its possible it could be a quirk of the android environment too as running the app as a windows application it seems fairly accurate
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
is there betterway I could go about trying to get a precise timing on the click without system.Timers and isn't as power intensive?
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
Thats my conclusion as well but im not sure what to use instead
ACiDCA7
ACiDCA74mo ago
well if you reaaaaaaally want to stick to events and have higher accuracy, you gonna have to make your hands dirty and write OS-specific code.. windows has multimediatimers iirc 100ns accuracy android has similar stuff
cap5lut
cap5lut4mo ago
why do i always forget about that type T_T imo audio is a lot harder than game dev, so u chose a quite difficult topic 😂
ACiDCA7
ACiDCA74mo ago
hehe, both topics can get really difficult
cap5lut
cap5lut4mo ago
game engines at least cover the audio stuff for u ;p
ACiDCA7
ACiDCA74mo ago
gamedev is just easier to get into because the engine spoonfeeds you^^
cap5lut
cap5lut4mo ago
writing that from scratch is another story tho its been almost 20 years, but back then i tried myself at synthesizing, i failed horribly and i tried for ~0.5 years
ACiDCA7
ACiDCA74mo ago
i didnt dabble in soundprocessing but when i was young and naive i tried writing a tilebased gameengine on top of sfml (c++) it already provides the fundamental parts like loading sound and displaying stuff but even then it was quite the task... even today i dont think i would be able to write something good completly from scratch. the only thing regarding audio id did was reading metadata from different fileformats. id3tags, vorbiscomments and so on
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
I suppose it does I'll search around and see what I cant find I appreciate the insight in this discussion🙏
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
its not super fun in other languages either to be fair
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
I'll take a look I think I saw other projects on github using it for their audio player
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
tncargil
tncargil4mo ago
So NAudio is not compatitble with .net Mauhi as it requires a window dll that does not exist in the android environment also tried using a dispatcher in microsecond intervals but that was still very inconsistent
Want results from more Discord servers?
Add your server