哪个计时器类用于节拍器?(Which timer class to use for a metronome?)

编程入门 行业动态 更新时间:2024-10-25 20:28:33
哪个计时器类用于节拍器?(Which timer class to use for a metronome?)

.net框架有很多种方法可以使用计时器,但对于节拍器我应该使用哪一个?

我尝试了所有这些计时器,但没有一个对我的使用来说足够准确(他们无法在15ms以下获得分辨率)。

System.Windows.Forms.Timer System.Web.UI.Timer System.Diagnostics.Stopwatch System.Timers.Timer System.Threading.Timer

对于我的节拍器课程,我需要Ticks可靠,恒定,无漂移。

我在MSDN上找到了这个实现: https ://msdn.microsoft.com/en-us/library/aa964692( v = vs。85).aspx使用“coredll.dll”

另一种解决方案是实现这些本机方法:

[DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeSetEvent")] internal static extern UInt32 TimeSetEvent(UInt32 msDelay, UInt32 msResolution, MultimediaTimerCallback callback, ref UInt32 userCtx, UInt32 eventType); [DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeKillEvent")] internal static extern void TimeKillEvent(UInt32 uTimerId);

在Windows上拥有分辨率低于5ms的计时器的最佳方法是什么?

编辑

我在.net(法语)中找到了关于计时器的这个非常有趣的链接: http : //www.e-naxos.com/Blog/post/NET-et-ses-timers-Prise-de-tete-ou-reelle- utilite-的.aspx

The .net framework has many ways to use timers, but for a metronome which one should I use ?

I tried all these timers but no one is enough accurate for my use (they can't have a resolution under 15ms).

System.Windows.Forms.Timer System.Web.UI.Timer System.Diagnostics.Stopwatch System.Timers.Timer System.Threading.Timer

For my metronome class I need Ticks reliable , constant, without drift.

I found this implementation on MSDN : https://msdn.microsoft.com/en-us/library/aa964692(v=vs.85).aspx that use "coredll.dll"

Another solution can be to implement these native methods:

[DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeSetEvent")] internal static extern UInt32 TimeSetEvent(UInt32 msDelay, UInt32 msResolution, MultimediaTimerCallback callback, ref UInt32 userCtx, UInt32 eventType); [DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeKillEvent")] internal static extern void TimeKillEvent(UInt32 uTimerId);

What is the best way to have a timer with a resolution under 5ms on windows ?

EDIT

I found this very interesting link about timers in .net (in french) : http://www.e-naxos.com/Blog/post/NET-et-ses-timers-Prise-de-tete-ou-reelle-utilite-.aspx

最满意答案

您应该使用多媒体计时器来实现此目的。

多媒体计时器服务允许应用程序以最高分辨率(或准确度)为硬件平台调度计时器事件。 这些多媒体计时器服务允许您以比其他计时器服务更高的分辨率安排计时器事件。

这些定时器服务对于需要高分辨率定时的应用程序非常有用。 例如,MIDI音序器需要高分辨率计时器,因为它必须在1毫秒的分辨率内保持MIDI事件的速度。

有各种C#库可以帮助使用它们。

例如: http : //www.codeproject.com/Articles/5501/The-Multimedia-Timer-for-the-NET-Framework

You should use a Multimedia Timer for this purpose.

Multimedia timer services allow applications to schedule timer events with the greatest resolution (or accuracy) possible for the hardware platform. These multimedia timer services allow you to schedule timer events at a higher resolution than other timer services.

These timer services are useful for applications that demand high-resolution timing. For example, a MIDI sequencer requires a high-resolution timer because it must maintain the pace of MIDI events within a resolution of 1 millisecond.

There are various C# libraries available to help use these.

For example: http://www.codeproject.com/Articles/5501/The-Multimedia-Timer-for-the-NET-Framework

更多推荐

本文发布于:2023-04-28 00:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节拍器   计时器   timer   class   metronome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!