metronome

This is a discussion on metronome within the C Programming forums, part of the General Programming Boards category; Is it possible to make a metronome in C? If possible, then how would I do it?...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    metronome

    Is it possible to make a metronome in C? If possible, then how would I do it?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,167
    Code:
    for(;;)
    {
      // make a sound
      // sleep for a certain amount of time based on tempo
    }
    If you understand what you're doing, you're not learning anything.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Yes.... maybe....

    You can time down to one-millisecond using <ctime> (aka time.h).

    There is no sound in standard C++, but assuming you're on a Windows system, PlaySound() is probably the easiest way to make a sound.

    There are a couple of issues with Windows. Although you can read time with millisecond precision, you do not get millisecond accuracy. The time_t structure only gets updated about every 30 ms (I forget the exact number). And the Windows multitasking also adds to the problem... The CPU may be doing something else just when you need it to make a "tick".

    I think these timing errors may be enough to cause problems, but I'm not sure. You can hear a 50ms delay.... For example, if you delay the sound to one speaker it will sound like an echo. But, a 50ms error between beats may not be as noticable.

    If the Windows timing issues are a problem, DirectX (DirectSound) or MIDI may provide the solution. (These techniques might be able to hand-off the timing chores to the soundcard/soundchip.)

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    5
    Thanks for the replies. I'll try to do some work on it.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    903
    Code:
    int ms = (60.0f / (float)bpm) * 1000;
    This is how I would be getting the delay between each ticks.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21