Delay problem

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Delay problem

Post by infratec »

You have to disable the Debugger.
SeregaZ
Enthusiast
Enthusiast
Posts: 619
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: Delay problem

Post by SeregaZ »

i am even set 22.675736 for more tune, and create exe file, and close any others programm - still not same, as original.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Delay problem

Post by infratec »

Can you provide a wav file?

I have no winamp.
SeregaZ
Enthusiast
Enthusiast
Posts: 619
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: Delay problem

Post by SeregaZ »

infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Delay problem

Post by infratec »

Hm...

I compensate a bit the calling

Code: Select all

DelayMicroSeconds(MusArr(i)\pause * 22.676 - 5)
But for me it sounds already a bit faster as the original.

Bernd
SeregaZ
Enthusiast
Enthusiast
Posts: 619
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: Delay problem

Post by SeregaZ »

sounds very closer. but how they get this so small pauses? i think it was made by VB6.0
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Delay problem

Post by kenmo »

My advice: do not not not use a sequence of delays to control your timing. Error will accumulate eventually, even using a function more precise than Delay().

I would try a method similar to this:

Code: Select all

    Debug "play"
    
    PlayedTicks.i = 0
    PlayedUS.i = 0
    CurrentUS.i = 0
    StartMS.i = ElapsedMilliseconds()
    
    For i = 0 To ArraySize(MusArr())-1
    
    Select MusArr(i)\type
      Case 1
        OPN_Write(0, MusArr(i)\reg, MusArr(i)\val)
      Case 2
        tmp = MusArr(i)\reg+256
        OPN_Write(0, tmp, MusArr(i)\val)
      Case 3   
        ;COMMENT AND UNCOMMENT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        
        ;infratec
        ;DelayMicroSeconds(MusArr(i)\pause * 23) ; but need * 22.675 as 0. 000 022 675s
        
        ;CELTIC88
        ;DelayEx(MusArr(i)\pause) ; i even dont know how to use it
        
        ;lowest pb value
        ;Delay(1)
        
        PlayedTicks + MusArr(i)\pause
        PlayedUS = PlayedTicks * 22.675
        While (CurrentUS < PlayedUS)
          Delay(1)
          CurrentUS.i = (ElapsedMilliseconds() - StartMS) * 1000
        Wend
        
    EndSelect
    
    If stopflag
      Break
    EndIf 
    
  Next
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Delay problem

Post by Joris »

For this kind of timings you need to use MS-windows API timers (how to do this on OSX I don't know). All other timing-functions can be influenced by the user when moving a window or whatever, which will result in time interrupts.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Delay problem

Post by Rinzwind »

Microsecond delay with no loop for Windows (found a c version on net, thought I share)

Code: Select all

Procedure usleep(usec)
	Define timer, ft.LARGE_INTEGER

	ft\QuadPart = -(10 * usec)
	timer = CreateWaitableTimer_(0, #True, 0);
	SetWaitableTimer_(timer, @ft, 0, 0, 0, 0);
	WaitForSingleObject_(timer, #INFINITE);
	CloseHandle_(timer);
EndProcedure

Debug ElapsedMilliseconds()
usleep(10000)
Debug ElapsedMilliseconds()

Repeat
  usleep(1)  
ForEver
CPU usage is 0.
Post Reply