Shop OBEX P1 Docs P2 Docs Learn Events
Vertical Sync counter — Parallax Forums

Vertical Sync counter

DynamoBenDynamoBen Posts: 366
edited 2007-09-24 18:34 in Propeller 1
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-17 15:36
    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.
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-17 21:01
    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

  • deSilvadeSilva Posts: 2,967
    edited 2007-09-17 22:20
    (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
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-17 22:34
    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?
  • AribaAriba Posts: 2,685
    edited 2007-09-18 00:46
    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
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-18 15:35
    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
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-21 18:13
    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?· confused.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-21 20:36
    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[noparse][[/noparse]statusPtr] rather than trying to directly test tv_status.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-21 20:59
    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 smile.gif
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-21 21:08
    deSliva you lost me on that one.. 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 PetersonKen Peterson Posts: 806
    edited 2007-09-22 17:00
    @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?
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-22 18:12
    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 smile.gif

    I planned to squeeze the ROM font to 16 lines, by changing TV, but that was shifted to the coming Tutorial...
  • DynamoBenDynamoBen Posts: 366
    edited 2007-09-24 18:34
    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
Sign In or Register to comment.