Archived

This topic is now archived and is closed to further replies.

DirectMusic timing

This topic is 5896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Has anyone successfully used the AdvisePeriodic() timing function originating from DirectMusic? I''m having real trouble getting the semaphore to do anything useful. Here''s the code: sound_sem = CreateSemaphore(NULL, 5, 10, NULL); if (sound_sem == NULL) fprintf(stderr, "Error creating semaphore\n"); CoInitialize(NULL); if (CoCreateInstance(CLSID_SystemClock, NULL, CLSCTX_INPROC, IID_IReferenceClock, (LPVOID*)&pRefClock) != S_OK) fprintf(stderr, "Error initialising COM\n"); if (pRefClock->AdvisePeriodic(1, 166667, sound_sem, &sound_timer) != S_OK) fprintf(stderr, "Error creating timer\n"); for (; { WaitForSingleObject(sound_sem); do_whatever(); } Unfortunately the timer appears to do nothing, at least the way this is coded. Can anyone please help? Thanks in advance! Alex.

Share this post


Link to post
Share on other sites
It seems to work OK in DirectX 8.1 I don''t know if there were problems in previous versions.

Your WaitForSingleObject call is invalid - You''re missing the 2nd parameter. I assume you are using INFINITE just to see if it returns at all.

Just to clarify the problem: If you breakpoint the WaitForSingleObject call and then single-step over it does the app just hang there?

Cheers,
John

Share this post


Link to post
Share on other sites
I incorrectly made the assumption that WaitForSingleObject() would only return _after_ the time I specified in AdvisePeriodic(). However it should check for WAIT_OBJECT_0. The code should read:

if (WaitForSingleObject(sound_sem, 0) == WAIT_OBJECT_0)
do_something();
Thanks for responding though.

Alex.

Share this post


Link to post
Share on other sites