CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Accurate timer needed for drum sequencer

    Hi. I am developing a drum sequencer using VB.net but having trouble with the accuracy of the timing. I've tried the Forms timer, the System timer and I'm now using the Threading version, which I'm timing against a Stopwatch. The only other option I've found is the QueryPerformanceCounter, but that would require polling, which would be a nightmare. At 120 beats per minute, there are 125 milliseconds between beats. This seems to work out most of the time, then there are a couple at 140, which I don't understand. I'm completely new to multithreading, although I've learnt a lot from my mistakes over the last month or so. If anyone knows of a way of getting super-accurate timing, but in a Timer-type environment, using events, please let met know. Or some way of conditionally increasing the priority of the Threading.Timer.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Accurate timer needed for drum sequencer

    Use a multimedia timer.

  3. #3
    Join Date
    Feb 2014
    Posts
    6

    Re: Accurate timer needed for drum sequencer

    Many thanks. I've found one and got it working.

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Accurate timer needed for drum sequencer

    Quote Originally Posted by Firebeard View Post
    At 120 beats per minute, there are 125 milliseconds between beats. This seems to work out most of the time, then there are a couple at 140, which I don't understand.
    according to my maths... 120 BPM = 500ms between beats...at 125ms - 140ms your getting between 428 and 480BPM ....

    Just remember that most timers are accurate only to ~16 ms and some are as bad as 55ms....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Feb 2014
    Posts
    6

    Re: Accurate timer needed for drum sequencer

    Sorry, I didn't explain it very well. My system is based around a 2 bar rhythm / arpeggiator pattern made up of 16th notes. It does work out OK at 125ms. I found a Media Timer - I went through the three standard ones (form, system and threading) and they were awful. The one I'm using now I'm testing against a StopWatch and it seems dead on. It even allows for ad hoc changes of tempo, rather than pausing for ages like the form and system timers did. I think I'm at a stage now where I can confirm that any lags in are my code rather than a fundamental infrastructure issue. Unless the stopwatch and timer are consistently inaccurate, but I'm not even going to go there...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured