fragmer
27th March 2006 06:27 UTC
Fps?
Hello again, AVSers.
I haven't been actively AVSing for over a year, but recently I've been asked to do FX for a live performance for a friend's band. So...
I'm writing a little AVSTrans library with arrays, vectors, lots of shortcuts and keyboard/mouse functions. Everything is going smoothly so far, except for one simple function - an FPS counter.
For some reason, the old formula:
fps=1/gettime(time);time=gettime(0);
doesn't work for me. I get very inaccurate and quantized, widely spaced values - as if AVS is having rounding errors.
Has something changed in AVS while I was absent? Is there a better way? Am I doing something wrong?
eheiney
27th March 2006 06:57 UTC
How about:
fps=gettime(time);time=gettime(0);
or
time=gettime(0);dt=time-last;last=time;
fragmer
27th March 2006 07:06 UTC
Yes, I am familiar with all those formulas. The problem is, if you check the values that this formula spits out, you see that they are very inaccurate. Try
reg00=1/gettime(time);time=gettime(0);
and check the debugger. You'll see that there are just a few fps values that the function spits out - 66.666666 and 62.50000, and sometimes 32.258064 or 31.25000, but not much in between. At least for me.
eheiney
27th March 2006 07:16 UTC
Yeah, I get either 62.4999999 or #INF000000.
I suppose I may be a bit confused about what you're looking for, I've never heard of an FPS counter. What does it do, what is it for, and what were you expecting the values to be?
edit: Gah, okay I know what you're talking about now... I feel stupid. :(
edit2: Still not sure how to fix it though. I know Jheriko posted a few attachments in the past few months with FPS counters but I can't seem to find them anywhere.
StevenRoy
27th March 2006 21:12 UTC
These values look like the sort of thing you might see if you have "Wait for retrace" turned on. The "granularity" between them is a result of the timer's millisecond resolution. This is normal.
If you want "smoother" values, you can use an averaging technique. For example, in one of my presets, I use code similar to this:
t=gettime(0);spd=(spd+(t-lt))*.5;lt=t;
reg00=1/spd; // This is the "smoothed" Frames-Per-Second count
This will smooth out the values, but only a little bit. For something that actually looks like a real FPS counter, more "clever" steps may have to be taken. For example, I just came up with this:
t=gettime(0);spd=(spd+(t-lt))*.5;lt=t;
assign(megabuf(fp),spd);fp=(fp+1)%30;
if (fp%5,0,
assign(reg00,0)+assign(c,0)+
loop(30,assign(reg00,reg00+megabuf(c))+assign(c,c+1))+
assign(reg00,30/reg00)
);
This calculates the average FPS of the last 30 frames, every five frames. I think that looks rather good. Of course, depending on what you're looking for, you may need to tweak it a bit.
If, by the way, you're only using this value to give your preset "frame-rate independence", then you don't need all this trickiness and you can stick with your original code.