[fpc-pascal]CD-Rom handling
ddt at headrush.co.za
ddt at headrush.co.za
Sun Sep 8 18:46:43 CEST 2002
Hi,
I am currently creating a simple simulation game that is highly dependant
on my abillity to know which frame is currently being played on an audio
cd-rom.
I am using the SDL cdrom API to do all my CD-Rom stuff (it makes sense
since it is an SDL game)
My game needs to be able to jump to frames on the CD relative to the frame
currently being played (if your wondering I am trying to create a
simulation of hip-hop style record scratching).
SDL_CD's cur_frame function doesn't work because it is track relative(I
have to work as if there is ONLY frames)
I have tried to handle it by using SDL_Getticks, the idea being that if I
know the ticks value of the last scratch and the tick value of the current
scratch I can work out how many frames has played since then (there is
exactly 75 frames per seccond or 3 frames for every 4 ticks) but this
refuses to work (I am not sure why).
Part of the problem appears to be that I the scratches can be either
forward or backward, but the ticks are allways forward.
The system emulates a scratch with a mouse drag, if the mouse X is
increased during the drag then it will scratch forward when the button is
released, if it decreases it scratches backward.
Here is the relevant code as it is right now, any help fixing it would be
greatly appreciated. The current bug is that even when you scratch
backward, last almost always is higher than when you last scratched (which
means you don't go back) this code is executed when the mousebutton is
released:
{Begin Code snippet}
If (EX > SX) then Dir := FWD else {EX/SX - Start/End X value of the mouse
Dir := BWD; {BWD/FWD is constants declared for readabillity}
time2 := SDL_Getticks;
time1 := time2 - time1;
Last := last + (time1 div 4) * 3;
Ammount := ABS(EX - SX) * 10;
If Dir = FWD then
Last := Last + Ammount else
Last := Last - Ammount;
SDL_CDPLAY(CD,last,1000000);
{Skip to last, last is supposed to be the correct new spot after the
scratch, the seccond number is how many to
stop before the next scratch}
time1 := SDL_Getticks;
writeln(last); {This is here for debugging purposses}
{END code snippet}
PS. I am using Daniel Moisette's h2pas headers for SDL.
TIA
A.J. Venter
www.headrush.co.za
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
More information about the fpc-pascal
mailing list