PDA

View Full Version : Vertical Sync counter



DynamoBen
09-17-2007, 10:22 PM
I'm creating a video test app that displays the number of frames that have passed since the start of the test. The idea is I can review the recorded video file and see how many dropped frames there were (a jump from 1 to 3 is a dropped frame).

However to do this I need increment a counter each time a vertical sync occurs. The only way I can think of doing this is by adding a counter in the vertical sync code in the TV object. Can anyone suggest or think of another or better way to accomplish this?

Mike Green
09-17-2007, 10:36 PM
The TV driver has a tv_status parameter (look at the comments at the end of the source file). It is set to different values depending on whether the driver is producing video, vertical sync pulses, or is disabled. You could set up a cog that watches for a change in status from invisible to visible and increments a counter if so (and displays it on the screen). If you don't have to do anything else, you could do this task in your main program.

DynamoBen
09-18-2007, 04:01 AM
This is what I have come·up with.·
My numbers seem to be increasing faster than 30fps. What is the default frame rate? Is there way to specify frame rate?
·
repeat
··· if tv_status<>status_state
····· if tv_status==2························ ' sync data 1=invisible, 2=visible
······· str(string($0A,16,$0B,12))
······· hex(sync_count++,2)
······· status_state := tv_status

deSilva
09-18-2007, 05:20 AM
(a) The last line of your code is not correctly inented - but I presume this is just a copy issue..
(b) In non-interlaced mode, tv_status is set each field = 60 times per second

DynamoBen
09-18-2007, 05:34 AM
The code I posted is represented exactly the way I have it. How do you mean its not indented properly?

For this to work I only want to increment the counter when tv_status changes state (1 to 2). The last line is there to update the temp variable called status_state. When tv_status and status_state are different I know that the tv_status state has changed so I update the counter and then update the temp variable.

60fps seems right based on what I'm seeing, any way to slow things down?

Ariba
09-18-2007, 07:46 AM
Your last line is only executed if tv_status==2. So status_state will always be 2.
Place the last line one indent backwards, and it should work, as expected.

Andy

DynamoBen
09-18-2007, 10:35 PM
Good suggestion·my counter is incrementing at 30fps. Thanks for all the help.

· repeat
··· if tv_status<>status_state
····· if tv_status==2······················· ' sync data 1=invisible, 2=visible
······· str(string($0A,16,$0B,12))
······· hex(sync_count++,4)
····· status_state := tv_status


Post Edited (DynamoBen) : 9/21/2007 6:06:12 PM GMT

DynamoBen
09-22-2007, 01:13 AM
Pardon my "newbieness" in this question but I'm a bit stumped.
I'm having trouble reading the tv_status variable when I setup my code objects as follows:

My code (read tv_status and display counter)
|_ TV_Text
····|_ TV

If I make a copy of TV_Text and bury my code in it my counter works fine, but I'm trying to avoid this as much as I can. What am I not missing?· http://forums.parallax.com/images/smilies/confused.gif

Mike Green
09-22-2007, 03:36 AM
What you're missing is that, when you make a copy of TV_Text, it's a separate copy ... it has a different set of variables. Unfortunately, Spin is not set up to easily handle shared objects. At the very least, you need to add a routine to the standard TV_Text that returns the address of the tv_status variable. You can call this from your main program (or whatever initializes TV_Text) and save it for later use, say in a variable called statusPtr. Later, you can check LONG[statusPtr] rather than trying to directly test tv_status.

deSilva
09-22-2007, 03:59 AM
I see the point in copying the status block into VARs for the utilization of multiple video...

However I kicked it all out of my TV programs (and my version of TV_TEXT) and used the DAT original.

- Remove the VARs
- Remove the LONGMOV
- Do the fine-work ...

Makes the programs much more readable and avoids above problems.
However: No second or third monitor http://forums.parallax.com/images/smilies/smile.gif

DynamoBen
09-22-2007, 04:08 AM
deSliva you lost me on that one.. http://forums.parallax.com/images/smilies/confused.gif

Are you saying you edited your TV_text file and removed:
- VARs
- LONGMOV

And now you handle these things in your object instead of TV_Text?


Post Edited (DynamoBen) : 9/21/2007 9:41:04 PM GMT

Ken Peterson
09-23-2007, 12:00 AM
@DB:

Whenever I have an object that is shared at different levels, I change the code for the object to put all of the variables in the DAT section rather than the VAR section. Multiple copies of objects have individual VAR sections, but they all share the same DAT section. In your case, if you did this, all TV_TEXT objects would refer to the same TV output.

Mike's suggestion for creating accessor functions for getting variable pointers is also very handy in many cases. Too bad we can't use function pointers!

Ken

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


The more I know, the more I know I don't know.· Is this what they call Wisdom?

deSilva
09-23-2007, 01:12 AM
DynamoBen said...
Are you saying you edited your TV_text file and removed:
- VARs
- LONGMOV

Not all, just the TV-status block


said...
And now you handle these things in your object instead of TV_Text?

No, there is no handling... However I changed it to non-interlaced, for the sake of better quality on 240 line monitors...

That leaves just 7 lines for the 32 line ROM-fonts, but is VERY readable now http://forums.parallax.com/images/smilies/smile.gif

I planned to squeeze the ROM font to 16 lines, by changing TV, but that was shifted to the coming Tutorial...

DynamoBen
09-25-2007, 01:34 AM
What is "proper" way to do this?

The options are:

1. Just edit the existing copy of tv_text

2. Make a new copy of TV_text then edit the copy

3. Make a copy of tv_text and add in my code into it

Originally I made a copy of TV_Text and added my code to it. The issue I ran into was if I added days, hours, minutes, seconds, and frames to the displayed counter it slowed down and wasn't displaying every frame. I then moved the counter routine to its own COG but this got me thinking that breaking things apart (TV, TV_Text, My Object) to remedy the issue more cleanly.

Post Edited (DynamoBen) : 9/24/2007 10:40:10 PM GMT