Author Topic: Calculating Tempo [BPM] to Miliseconds!  (Read 7169 times)

Zakhar

  • Guest
Calculating Tempo [BPM] to Miliseconds!
« on: 11 Aug '03 - 22:30 »
Here's a question from an amature coder.  ::)

I was trying to make a little sequencer to play some wave samples,and i wrote some lines of code to calculate timer interval [in miliseconds] by a given tempo in BPM.

I figured out that 120 beats will be 1 minute [60000 miliseconds] so interval for a given tempo would be:

interval=(60000/tempo]  'in miliseconds

it seemd to work fine and i could get 1/4,1/8 and 1/16 intervals for a timer which was playing a sample.but when i compared my output with some other sequencers playing a click track,i found out that what i'm hearing in my program is a bit slower than standrad tempo.cakewalk was playing a click in 120BPM but mine was playing slower even it seemd to be running at 120bpm.

am i awefully wrong? does anybody knows the formula to calculate timer interval by a given BPM?

thanx.  :)

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Calculating Tempo [BPM] to Miliseconds!
« Reply #1 on: 12 Aug '03 - 13:56 »
Quote
it seemd to work fine and i could get 1/4,1/8 and 1/16 intervals for a timer which was playing a sample.but when i compared my output with some other sequencers playing a click track,i found out that what i'm hearing in my program is a bit slower than standrad tempo.cakewalk was playing a click in 120BPM but mine was playing slower even it seemd to be running at 120bpm.

What sort of timer are you using? For accuracy, you should use a multimedia timer (timeSetEvent), rather than the "SetTimer" function.

biggyspender

  • Posts: 28
Re: Calculating Tempo [BPM] to Miliseconds!
« Reply #2 on: 12 Aug '03 - 15:16 »

Quote


What sort of timer are you using? For accuracy, you should use a multimedia timer (timeSetEvent), rather than the "SetTimer" function.


...or even code your own stream (with streamproc), that will be able to derive the time from the playing audio.

Zakhar

  • Guest
Re: Calculating Tempo [BPM] to Miliseconds!
« Reply #3 on: 12 Aug '03 - 22:37 »
Thanx alot Ian and Biggy! I changed timer as Ian said and now it works just fine. i also set priority to High and it ticks damn accurate.

Mercy!