A.D.A. Amiga Demoscene Archive

  Welcome guest! Please register a new account or log in

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / Timing issue

 

Author Message
z5_
Member
#1 - Posted: 20 Dec 2008 15:36 - Edited
Reply Quote
Let's say you have the following situation:

- do startup-code
- p61_init
- clear vbi_timer
- go into mainloop
- wait until the vbi_timer has reached a certain value
- do_effect

Is there any reason why "do_effect" seems to be sooner or later according to using different amiga's (030, 060) or even using different winuae setup's (running on amiga forever workbench compared to slotting the intro in df0 and booting from there).

In reality, do effect should be in synchro with a certain point in the music but since i'm not using direct linking to patterns (i don't know how to), i'm using vbi timing instead.

Since the next do_effect should happen x vbi counts after the first do_effect (synchronised to the music), if the first one isn't correct, all the next ones aren't either.
ZEROblue
Member
#2 - Posted: 20 Dec 2008 22:13
Reply Quote
If you don't satisfy the interrupt request properly I think there's a chance it might trigger twice right after another on faster processors. Putting a NOP after writing to INTREQ will sync the pipeline and make sure the register has actually been written before you fall down to a lower interrupt state. Anyone can feel free to correct me on this if I'm remembering wrong here.

You can lower the sound buffer size in UAE to reduce some audio lag as well.
z5_
Member
#3 - Posted: 21 Dec 2008 13:40 - Edited
Reply Quote
I'm going to rephrase my question. Suppose you want to start your first effect when the tune is at a certain point (for example a beat which plays exactly after 1 second measured from when the tune starts to play). So:
- demo startup
- tune starts to play (p61_init)
- wait 1 second
- start first effect

The obvious way would be to do this with pattern linking but let's say that we don't use this (i seem to remember that this is not an option when using mp3's anyway). So you need to setup a timeline. What's the best way to set up that timeline? My vbicounting time line doesn't seem reliable at all for some reason.
dodke
Member
#4 - Posted: 21 Dec 2008 15:11
Reply Quote
my sucky bp08 demo (compo version) ran in ntsc mode (60hz) and was out of sync if it was available. i made it with 50hz sync and wasn't obviously thinking too much at the time.
other than that I'm pretty certain a vbi_timer should be accurate if done correctly.
Todi
Member
#5 - Posted: 21 Dec 2008 18:28
Reply Quote
@z5_
P61 is your friend, we always sync our demos with these:

P61_Pos
dc.w 0 ;Current song position (read only)
P61_CRow
dc.w 0 ;Current pattern row (read only)
ZEROblue
Member
#6 - Posted: 21 Dec 2008 19:40 - Edited
Reply Quote
Counting frames like you're doing now works fine if done correctly. Did you check your interrupt? If it's not satisfied properly then your frame counter could increase more than once per frame.

Another reason the frame count appears unreliable could be that you're comparing it to an exact value, and at the wrong place in your code. Testing the counter for an exact value of 100 at the end of your rendering loop will not work if your effect f.ex takes 4 frames to render and the counter skips from 98 to 102 during this time.
z5_
Member
#7 - Posted: 21 Dec 2008 19:48
Reply Quote
@ZEROblue: going to have a proper look at it.

@Todi: shit, i didn't realise that it was that easy to sync using the P61 routine.
Kalms
Member
#8 - Posted: 23 Dec 2008 01:53
Reply Quote
z5: Is the drift large? That is, if you wait for 50*20 vblanks, will that wait last roughly 20 seconds on your test configurations? (Just use a watch to measure this.) Or a lot less/more on some configurations?
z5_
Member
#9 - Posted: 23 Dec 2008 12:59 - Edited
Reply Quote
I timed the whole "thing" in winuae using amiga forever workbench environment . It was always correct. I then made an exe and tested it on various systems. I was surprised to see that it ran out of synch on a winuae environment other than the usual amiga forever workbench i used to develop.

The really strange thing is this:
- boot winuae
- run exe
- out of synchro
When i run the intro 100 times, it is always out of sync. I then reset winuae (using the winuae reset button), and then, using the exact same config, the intro runs in sync everytime i try.

Conclusion: when it runs out of sync, it keeps running out of sync until i reset winuae. When it runs in sync, it keeps running in sync. Thus, it can actually run out or in sync using exactly the same winuae config on exactly the same pc. When i say out of sync, iirc, the effects are happening faster than the tune.

On the real hardware side, on 68060 i waited 10 vbi counts to start the first effect (i use vbi count equal or greater to start next part) but on my 68030 i had to reduce that to 4 vbi counts or it would run out of sync. Sadly, i had few opportunity to test it as my Amiga died on me a couple of days ago.
Kalms
Member
#10 - Posted: 23 Dec 2008 14:45 - Edited
Reply Quote
z5: It's important to distinguish between two cases:

1. The audio and the video are running at different speeds.

2. The audio and the video are running at the same speed, but one is X ms delayed relative to the other.

I think that you are referring to situation #2 but that is not 100% clear from your previous text. ("When i say out of sync, iirc, the effects are happening faster than the tune." indicates situation #1 but the rest of the text indicates situation #2.)

Can you clarify which of the two is happening?
ZEROblue
Member
#11 - Posted: 23 Dec 2008 15:25
Reply Quote
Sounds like both a case of a too large audio buffer in WinUAE, and a VBI triggering more than once per frame. Can you paste the VBI code at least?
z5_
Member
#12 - Posted: 23 Dec 2008 17:26
Reply Quote
@Kalms: I do have the impression that the delay is getting bigger as the intro progresses (which would suggest option 1) but this is quite difficult to determine.

@ZEROblue: i am doing the "writing twice to INTREQ" trick (can't tell out of my head the exact details).

Anyhow, i'm sure that it's my vbi/frame couting not being correct. Still, i find it strange that exactly the same winuae config can give perfect/bad sync and that resetting winuae can actually solve the problem.
Kalms
Member
#13 - Posted: 23 Dec 2008 18:51 - Edited
Reply Quote
z5: Set up the demo such that it flashes the screen once, then -- supposedly -- waits for 30 seconds, then flashes the screen again. Use a wall clock to determine whether or not the wait was 30 seconds. What is the result? How many seconds?

I hope that the above test would take 30 seconds. If not, how much faster/slower? any figure? 15 seconds? 60? approx. 29 or 31 perhaps?

Test both with p61 enabled and p61 disabled. Does that change the result?
z5_
Member
#14 - Posted: 23 Dec 2008 20:18
Reply Quote
Using winuae and the pc clock next to it, it clocks in at 30 seconds (allthough it would be rather hard to distinguish between 29-30-31 without using a stopwatch which i don't have at the moment). Seems completely the same on different configs with different settings. Disabling P61 doesn't have any effect.

Anyhow, it's too late for what i intended to do. I'm going to do more tests after christmas/new year to have a more accurate view on when the problem occurs. In the meantime, i'm going to try and ressurect my amiga.

 

  Please register a new account or log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0