Calculating Tempo [BPM] to Miliseconds!

Started by Zakhar, 11 Aug '03 - 22:30

Zakhar

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

Quoteit 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


QuoteWhat 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

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!