bio4ema

hey.

i want to code a program that includes a metronome using c++ and directSound and/or directMusic.

this metronome should raise an event periodically, it should be as precise as possible and i need to change the tempo at runtime.

now what i need is something like the
StartTimer (UINT TimerDuration)
onTimer(UINT nIDEvent)
killTimer()
functions in VC++ but with a higher resolution than milli-seconds and with a way to affect the duration between the timer events at runtime, as mentioned above, thus without having to stop and restart the timer...

is there a way to use directSound / directMusic in order to achieve this

perhaps sth with
IReferenceClock::AdvisePeriodic

or does this problem not really have anything to do with directX and i should post on the VC++ board

thanks in advance, b


Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

Wessam Bahnassi

DSound is a high-performance sound output API only. You can use DSound or any other API for the matter of playing the sound. However, timing is out of the scope of DSound. Just to point a couple of things, I doubt a metronome would need more than 1ms of precision. Second, there's nothing wrong with killing and recreating the timer when your tempo changes. It doesn't take 5 seconds to do this operation (it's almost instant).




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

bio4ema

thanks for your reply !

the reason I connected my question about timing with directSound / directMusic is because of the directMusic functions concerning timing issues such as e.g. IDirectMusic8::GetMasterClock or IDirectMusicPerformance8::AdjustTime, which left me wondering if there were functions provided by directX that I could use for solving my problem stated above.

i do need more than 1ms of precision (at least 1/10.000 sec) due to the fact that when converting beats per minute (BPM) to time length, millisconds are not sufficient and result in incorrect tempo values.
for example a 120 bpm track has a one-quarter length of 125 ms, so a milli-second resolution would be fine. a 129 bpm track, however, has a one-quarter length of 116,279... ms.

killing and restarting the timer is not an option since it would quite severly interrupt the flow of the track currently being played.

thanks for any suggestions,
best wishes,
b.




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

Wessam Bahnassi

bio4ema wrote:
i do need more than 1ms of precision (at least 1/10.000 sec) due to the fact that when converting beats per minute (BPM) to time length, millisconds are not sufficient and result in incorrect tempo values.
(I assume you mean 1/10000 sec, right )
bio4ema wrote:
for example a 120 bpm track has a one-quarter length of 125 ms, so a milli-second resolution would be fine. a 129 bpm track, however, has a one-quarter length of 116,279... ms.
Sooner or later you're going to run into this problem, you cannot represent all numbers exactly in a computer (e.g 1/3). But I really doubt these small imprecisions would be noticeable.
bio4ema wrote:
killing and restarting the timer is not an option since it would quite severly interrupt the flow of the track currently being played.
Have you tried it




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

bio4ema

(I assume you mean 1/10000 sec, right )

well, yes, by 10.000  I meant 10000.

Sooner or later you're going to run into this problem, you cannot represent all numbers exactly in a computer (e.g 1/3). But I really doubt these small imprecisions would be noticeable.

Yeah, but for example i'd rather use 0,3333 for 1/3 than 0,333.


killing and restarting the timer is not an option since it would quite severly interrupt the flow of the track currently being played.
Have you tried it

Yes.

So, to come back to my initial question
Does directX, in particular DirectMusic, provide functions I could use or not As pointed out in the first reply, directSound is for playing (setting fx, etc).

thanks, b.




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

bio4ema

also, concerning the timing issue: i've tried StartTimer (), onTimer() and killTimer() , but wasn't satisfied with the results, which is the reason why i came to this forum hoping to find a better way.

best wishes, b.




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

Wessam Bahnassi

Yes, you can use DMusic to achieve this result, but I wouldn't do it with DMusic since it's dropped now and not supported anymore. Instead, you can generate a DSound secondary buffer with the length of a bar, and fill it up with beats at proper timing then just play the buffer with DSound in a looping fashion (thinking of it, it can be even perfectly done with the normal Win32 PlaySound() function).




Re: Game Technologies: DirectX 101 metronome using directSound or directMusic

bio4ema

thank you very much. that really helped.

best wishes b.