Need very precise timings to show a stimulus

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Thu May 05, 2016 8:28 pm

Hi Bernd,

I have looked through your attachments. I can say this -- something like this would be required to accomplish what I want.

I asked around and I discovered a few things: Priming research is typically done with other kinds of software that (apparently) takes into account the refresh rates of the monitor. For instance, Inquisit is one such software and it allows you to set stimulus durations by frames. That is really the key -- start the prime exactly when the system monitor has just finished redrawing (or whatever).

Back to your code. I do not quite understand this:

Code: Select all

   
put (tTime - (tTime mod kFrameLength)) + kFrameLength into tNextTime
What is "mod", and how was kFrameLength determined?

Also:

Code: Select all

send "updateSwirl pLastTime, pPhase, pPhaseStart, pPhaseEnd" to me in tNextTime - tTime millisecs
What does that do, and why after "tNextTime-tTime"?

With your code (subliminal Cueing) --> you reference field 2, but I do not see a field 2 object. Also, I noticed that I can recreate the problem running either the runSequence or runSequenceadapted on default settings (even though they work the vast majority of the time).

Unfortunately I have to run for now, but I will return to this later! Thanks again!

okk
Posts: 178
Joined: Wed Feb 04, 2015 11:37 am

Re: Need very precise timings to show a stimulus

Post by okk » Thu May 05, 2016 9:55 pm

Hi,
perhaps this thread might be of some help: http://forums.livecode.com/viewtopic.php?f=10&t=25989

I moved from LC 6.1 to LC6.7 and higher and I noticed a considerable loss of speed when redrawing the screen. I tried to color chars in a text field with relative precise short timings, so it's not the same use case, but close. It sounds counter-intuitive, but you might want to try your code with LC 6.1. You can still download it from the LC download section. Bernd - who was amazingly helpful - mentioned in that thread, that due to the change to cocoa refresh times moved from 3 milliseconds (LC6.1) up to 16 milliseconds (LC6.7 and above). So if you can get a much faster screen refresh time with LC 6.1. it might solve your issue. Worth a try, I'd say, but this is probably only relevant if you work on a Mac.

Best
Oliver

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Thu May 05, 2016 11:39 pm

Hi Oliver, PoLyGLoT,

@Oliver, I just tested on LC 6.1.3 and in fact the screen refresh is much faster, almost no delays. I had forgotten about that :( thanks for reminding.

Things have gotten much more involved regarding timing in 6.7 and on.

@ PoLyGLoT,

Hi PoLyGLoT,
What is "mod", and how was kFrameLength determined?
Mod:

when you divide an integer(dividend) by an integer(divisor) then you might get a real number, i.e. in the case of 13/4 = 3,25

When you are interested in the remaining integer after division you can do

13 mod 4 = 1

Likewise you can do

13 div 4 = 3

in case of timing to the next screen refresh, assuming it is synced to the system clock and occurs every 50 milliseconds then you can say

Code: Select all

put (char -3 to - 1 of the milliseconds) into tTime
put 50 -( tTime mod 50) into tMod
put tTime & cr & tMod
this would put as an example
364
36
into the message box
meaning that in 36 milliseconds the next screen refresh will take place. (at 400)
have a look at the dictionary for mod and div.

But the hard part is to find out what the exact screen refresh rates are, it seems for a Mac it is either 60 or 75 Hz, 60 Hz would be every 16.7 milliseconds. I just don't know. My testing gives inconsistent results.

If you want to do scientific research on subliminal effects I would get the accepted software and you are out of any trouble proving that you get the exact 16.7 milliseconds.
But then the fun is gone.

kFrameLength is a constant (dictionary) declared at the top of the script like
constant kFrameLength = 40
-- The length of time in millisecs between frame updates. Here, 40ms gives us a
-- framerate of 25fps.
constant kFrameLength = 40
I am not even sure anymore if Kevin wanted to get a consistent framerate or if he also wanted to sync to the screen update.
send "updateSwirl pLastTime, pPhase, pPhaseStart, pPhaseEnd" to me in tNextTime - tTime millisecs
these are all parameters send with the send in time message which will arrive at handler "updateSwirl" in tNextTime-tTime milliseconds. The last part is how Kevin syncs to his framerate.
With your code (subliminal Cueing) --> you reference field 2
field 2 is there, look at it with the Project Browser. It is at the right side of the stack. If you made the stack smaller it might not be visible anymore. It logs the different timings.

Kind regards
Bernd

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Fri May 06, 2016 3:39 am

Hi all,

I may have found a solution. I have found a way to record video at 60 frames per second. Of those 60 frames, I made 1 frame my prime (either LEFT, RIGHT, or blank). 1/60 seconds = .0166667, which equals 16.7 milliseconds. I made a 3 frame "XXXXXXX" and a 48 frame "XXXXXXX" for before and after the prime (these equate to 50 ms and 800 ms, respectively).

I recorded these at a high resolution, and now each time I play the video clip, I can see the flicker! Given that most monitors have a 60hz refresh rate, this should be completely fine (right?).

If so, I need to figure out 1 more thing: how to buffer the video completely before starting playback. It would be good if the card could load, then the video is already buffered and loaded into memory, and then executes on my command. It's not super critical, and I think importing the video files should take care of it. But still, it would be the finishing touch!

I meet with someone tomorrow who conducts this kind of research, and I will ask this person about my solution! Thanks for all the help, and I'll keep you all posted. :D

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Fri May 06, 2016 10:50 am

Hi Polyglot,

to make a video sounds the most reasonable way to approach this. The video files should be very small so no problem to load and play them. 60 frames per second should be no problem.
Also the video eliminates much of the latencies when doing this with fields in LC since the native video playing of the operating system is taking over.
Video has its own set of problems and a skipped frame (especially the cueing one) would be very bad in your special case. But as long as you can reproducibly notice the flicker you should be fine.
and I'll keep you all posted.
It would be nice to know how you fare.
Kind regards
Bernd

theotherbassist
Posts: 115
Joined: Thu Mar 06, 2014 9:29 am

Re: Need very precise timings to show a stimulus

Post by theotherbassist » Fri May 06, 2016 12:49 pm

Just fyi, you can use the term "tick" in place of 1/60 of a second in Livecode. Might make the math a little easier.

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Fri May 06, 2016 8:54 pm

Hi,

I have imported a movie ("subLEFT.mov") into Livecode. But I cannot get it to play at all (either on opencard or just by clicking play on the file within livecode).

Code: Select all

on opencard
   play  videoClip "subLEFT.mov"
end opencard
I have QuickTime installed on my computer. Am I supposed to have a field on the card that it plays into? Or do I have to use the "player" toolbar?

Thanks in advance!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Fri May 06, 2016 9:46 pm

Hi Polyglot,

I can not get this to play in LC 7.1.3 either. Use a player and set its filename.

Kind regards
Bernd

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Fri May 06, 2016 9:59 pm

bn wrote:Hi Polyglot,

I can not get this to play in LC 7.1.3 either. Use a player and set its filename.

Kind regards
Bernd
I tried this and it still doesn't play:

Code: Select all

   set filename of player "vid" to "subLEFT.mov"
   start player "vid"
I can't get it to play even when I click "play" on the videoclips section for imported files. It looks like it does something, but no video appears. The file plays fine outside of LiveCode.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Fri May 06, 2016 10:26 pm

you set the filename in the properties inspector right to the name, it opens a file dialog and you choose your movie.

I don't think a player plays imported videoclips.

Kind regards
Bernd

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Fri May 06, 2016 10:34 pm

So I have this in the "Source" box for player "vid":

C:/Users/PC/Desktop/tapa livecode/subLEFT.mov

I then tell the "vid" to start on opencard. Doesn't work. I also cannot even get the "Controller" to appear on the player. So weird.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Fri May 06, 2016 11:06 pm

try in preferences -> check "load quicktime on startup", then from the message box type

Code: Select all

set the dontuseqt to false
hit return key.
in properties inspector check "showController"

Maybe this helps
Kind regards
Bernd

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Fri May 06, 2016 11:33 pm

bn wrote:try in preferences -> check "load quicktime on startup", then from the message box type

Code: Select all

set the dontuseqt to false
hit return key.
in properties inspector check "showController"

Maybe this helps
Kind regards
Bernd
OK, thank you. What was needed was a restart of my CPU (I had just installed QuickTime).

Video player is working and files are loaded and playing using the controller.

However, the video playback through livecode sometimes has the same "no flicker" problem. Do they compress the videos or something? Or render them differently?

When I play it via VLC player on my computer, it works fine. Maybe there is a way to play the video in 60 fps or..??

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Need very precise timings to show a stimulus

Post by bn » Fri May 06, 2016 11:51 pm

Maybe there is a way to play the video in 60 fps or..??
this is not Livecode that determines the framerate. It is the .mov. Livecode passes the playing through.
When you record the video you determine the framerate.
This is a tough problem without having a sample movie. Maybe you could provide a link to download such a file.

When recording your movie it is important that use a codec that does not do temporal compression. That means some of the compression is done by providing index frames and only show changes between index frames.
A codec with only spatial compression would be ok. There each frame is "compressed" similar to JPEG, but between frame there is no interpolation.
Do you happen to know what codec you used?

Kind regards
Bernd

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Need very precise timings to show a stimulus

Post by PoLyGLoT » Sat May 07, 2016 12:13 am

bn wrote:
Maybe there is a way to play the video in 60 fps or..??
this is not Livecode that determines the framerate. It is the .mov. Livecode passes the playing through.
When you record the video you determine the framerate.
This is a tough problem without having a sample movie. Maybe you could provide a link to download such a file.

When recording your movie it is important that use a codec that does not do temporal compression. That means some of the compression is done by providing index frames and only show changes between index frames.
A codec with only spatial compression would be ok. There each frame is "compressed" similar to JPEG, but between frame there is no interpolation.
Do you happen to know what codec you used?

Kind regards
Bernd
Hi Bernd,

Thanks for all your input. I *believe* H264? Is that a codec? I recruited help to make the video. :)

And as I mentioned, it plays perfectly well on the desktop with VLC media player.

Can you recommend a codec that would achieve what you are saying for windows?

Thanks!

Post Reply