DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Programming & Development > Sound and Music Programming
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 03-22-2006, 12:47 PM   #1
rouncer
Senior Member
 
rouncer's Avatar
 
Join Date: Mar 2006
Location: perth
Posts: 886
Default music program timing troubles

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.
rouncer is offline   Reply With Quote
Old 03-22-2006, 04:20 PM   #2
rouncer
Senior Member
 
rouncer's Avatar
 
Join Date: Mar 2006
Location: perth
Posts: 886
Default i worked it out.

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.
rouncer is offline   Reply With Quote
Old 03-22-2006, 04:22 PM   #3
Reedbeta
DevMaster Staff
 
Join Date: Oct 2004
Location: Seattle, WA
Posts: 3,707
Default Re: music program timing troubles

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).
___________________________________________
Currently working at Sucker Punch
reedbeta.com - OpenGL demos and other projects
Luabridge - a lightweight, dependency-free C++/Lua binding library.
CD Lite - an unobtrusive, minimal CD player application for Windows.
Reedbeta is offline   Reply With Quote
Old 03-22-2006, 04:22 PM   #4
Reedbeta
DevMaster Staff
 
Join Date: Oct 2004
Location: Seattle, WA
Posts: 3,707
Default Re: music program timing troubles

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.
___________________________________________
Currently working at Sucker Punch
reedbeta.com - OpenGL demos and other projects
Luabridge - a lightweight, dependency-free C++/Lua binding library.
CD Lite - an unobtrusive, minimal CD player application for Windows.
Reedbeta is offline   Reply With Quote
Old 04-05-2007, 10:19 PM   #5
L1zb3th
New Member
 
Join Date: Mar 2007
Location: Argentina
Posts: 10
Default Re: music program timing troubles

Sleep is usefull...
but, it receives ms or miliseconds ...
1000 ms = 1 s
check that :P
L1zb3th is offline   Reply With Quote
Old 04-06-2007, 10:54 AM   #6
SamuraiCrow
Senior Member
 
Join Date: Oct 2005
Location: Waterville, MN
Posts: 424
Default Re: music program timing troubles

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.
SamuraiCrow is offline   Reply With Quote
Old 09-19-2007, 08:53 AM   #7
fhein
New Member
 
Join Date: Sep 2007
Location: gbg.se
Posts: 10
Default Re: music program timing troubles

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
fhein is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 07:34 AM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.