timers and the like
Hey all,
I have recently began construction of a program that will allow you to play drum rythms on the pc. Obviously this is going to require the ability to play sounds with the beat, at very specific and exact intervals. I decided to use a timer to figure out how much time is left before it should play the next note. However, that has been very inconsistent. Sometimes it plays very smoothly, mostly it plays offbeat. Here is a snippet of my code that plays the sounds:
for (int i=0;i<=(11*loops+loops-1);i++)
{
k=0;
while (!GetMessage(&msg, hdlg, 0, 0))
{ //empty loop that waits for the WM_TIMER message.
} //not perfect, but it works for now..
SetTimer(hdlg,IDC_COUNTTIMER, tempo, NULL);
while (play[frame][k]==1)
{
prebuffed[frame][k]->Play(0,0,0);
k++;
}
NextNote();
}
anyway, it seems like it should work to me, but of course there is a reason im still in the beginners forum. I was just wondering if anyone had any better timers or ideas to smooth out the sound playing.
Melvin
yeah, use the windows high timer resolution,
like WM_PAINT, your timer messages is not the top priority of windows to retrieve in the messages,
like WM_PAINT, your timer messages is not the top priority of windows to retrieve in the messages,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Alrighty, I shall look into that. I have another question for you all: Is there a better way to find out if the WM_TIMER message has been posted? I have to tried to use PeekMessage, but, alas, i cannot get it to work right. So if any of you have a good example of how to make PeekMessage or something similar work properly, it would be greatly appreciated.
Thank you,
melvin
Thank you,
melvin
while(true){ if(PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE)) { switch(GetMessage(&msg, hwnd, 0, 0)) { case 0: // received WM_QUIT return msg.message; case -1: // error! break; default: TranslateMessage(&msg); DispatchMessage(&msg); break; } }}
[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement