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
IIRC
PeriodicTimer
should be the most accurateinaccuracies 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
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)Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
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?
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 waitits 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•7mo ago
Message Not Public
Sign In & Join Server To View
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•7mo ago
Message Not Public
Sign In & Join Server To View
Thats my conclusion as well but im not sure what to use instead
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
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 😂
hehe, both topics can get really difficult
game engines at least cover the audio stuff for u ;p
gamedev is just easier to get into because the engine spoonfeeds you^^
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
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•7mo ago
Message Not Public
Sign In & Join Server To View
I suppose it does I'll search around and see what I cant find I appreciate the insight in this discussion🙏
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
its not super fun in other languages either to be fair
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
I'll take a look I think I saw other projects on github using it for their audio player
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
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