music program timing troubles

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Mar 22, 2006 at 19:47

im writing a tracker program, but i cant get the ticks to play
straight.
have you done this before, can you help me?
Sleep() doesnt seem to work it gets delays in it.
i tried QueryPerformanceCounter() and stuck it in the main loop
but even that gets delays in it.
any help would be appreciated.

6 Replies

Please log in or register to post a reply.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Mar 22, 2006 at 23:20

yeh i worked it out, you dont use sleep, what you do is

while((double)(end-start)/frequency.QuadPart<(double)frame*program_time)
{
QueryPerformanceCounter(&counter);
end=counter.QuadPart;
}

which basicly means you hog cpu time so queryperformance counter
can return exactly on time. you just time the loop to how fast your
song is playing.

and thats how… phew.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 22, 2006 at 23:22

Accurate timing is one of the thorniest issues in software development…it’s a headache for running game update loops, too. QueryPerformanceCounter is only good for measuring small time intervals, over large ones it is inaccurate and gets continually reset, causing (sometimes negative) jumps. I find the most reliable timer is timeGetTime, with timeStartPeriod and timeEndPeriod. But it still isn’t perfect. On Intel computers there is also the rdtsc instruction, but it comes with its own can of worms (not the least of which is that it isn’t portable).

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 22, 2006 at 23:22

Ahh, you figured it out while I was typing =)

Glad you got it to work, though it’s still not such a great idea to hog the CPU like that.

E70f63aceb25fa57bee707b4edbef0c1
0
L1zb3th 101 Apr 06, 2007 at 04:19

Sleep is usefull…
but, it receives ms or miliseconds …
1000 ms = 1 s
check that :P

B7dcbc0c0f07253f25ff5c25fe38c081
0
SamuraiCrow 101 Apr 06, 2007 at 16:54

I don’t know about the PC or DirectSound but on the Amiga platform there is a call-back built in to the AHI drivers and the old-style Trackers used to run on a timer-based interrupt. The oldest Trackers used Amiga’s video-blank interrupt but that meant that the tempo playback was tied to the vertical scan rate of the graphics chips.

D5f5f67b73d8beb00461328d68de36e5
0
fhein 101 Sep 19, 2007 at 14:53

Maybe you could create a custom mixer with a few seconds buffer and stream from that? Should give pretty good timing if possible. Haven’t started with audio programming myself yet, but I think it sounds like a suitable solution for a tracker kind of program.

Ahh, Amiga.. Now that’s a fine computer :)