Page 1 of 1

Timer object question

PostPosted: Tue Feb 10, 2009 8:49 am
by Bernardo
Hi everybody,

When activating the timer object with a button or page enter etc (interval = 1000ms) the elapsed time variable is 1014. So if I have to syncronize the tempo with the computer clock is not exactly the same... It goes 1014 ---> 2044 ---> more. Not like 1000 -> 2000 -> 3000.

Code: Select all
SetVar "[Count]" "[Count]+1"

count representing the seconds...

If you compare a variable created [Count]+1 (after the timerstart action) and the global [Second]... the beginning they are equal but after a couple of secs they are not in sync. Like thereĀ“s a delay between a global second and the timer counted variable.

When you use the elapsed time do you get 1000ms as a result?


Thanks again for the help
Bernardo

PostPosted: Tue Feb 10, 2009 11:43 am
by Neosoft Support
Unfortunately, the accuracy of the Windows timer (which NeoBook uses) can vary depending on a number of factors. According to Microsoft:

Although Windows timer messages can be scheduled with millisecond accuracy, they seldom deliver that result because the accuracy of a Windows timer is dependent on the system clock and current activity. Because WM_TIMER messages are processed at a low priority, somewhat like WM_PAINT messages, they are often delayed while other messages are processed.


Another problem is that the accuracy, or resolution, of timers can vary depending on the Windows versions and hardware. For example, the resolution of the timer on Windows XP can vary between 10 and 25 milliseconds. Which means that an interval of 1000 milliseconds could be triggered anywhere between 975 and 1025 milliseconds.

PostPosted: Tue Feb 10, 2009 12:21 pm
by Bernardo
Thanks for the info, Dave. Much appreciated.

Re: Timer object question

PostPosted: Sun Jan 26, 2014 6:44 am
by ajhunt
Hi All, So is it possible to get a true system countdown clock using the [Minute], [Second] variables. I am recording sound for exactly 01:30 minutes (as confirmed by the filename.wav properties in Windows) but when trying to do a countdown display on screen from 01:30 using a timerobject the display always stops before actually reaching 00:00. Obviousy if a button says "Record a 01:30 Recording" then the countdown from 01:30 down needs to match the true clock and end at 00:00.

Has anyone managed to do an exact countdown timer which dislays the true countdown according to the system clock?

Any help really appreciated as pulling hair out here with this problem.

Regards
Anthony

Re: Timer object question

PostPosted: Mon Jan 27, 2014 12:31 pm
by Neosoft Support
I think the standard Windows timer is simply not going to be accurate enough to do the kind of precise timing you need. There are other factors besides the timer that make this task difficult. Assuming that you could find a very precise timer, there would also be the lag time between when the timer reached its stopping point and the time the recorder stopped recording that would always push the length of the audio beyond the desired interval. The only way to get an audio of a precise length would be to program the entire process at a very low level where you have control over the bits of data as they are being recorded. Otherwise, maybe you could find a utility to trim the audio to the precise length after the recording stops.

...when trying to do a countdown display on screen from 01:30 using a timerobject the display always stops before actually reaching 00:00.


That's probably something to do with the code you're using to display the time. If you want to post your code we can take a look at it.

Re: Timer object question

PostPosted: Mon Jan 27, 2014 1:05 pm
by CN_Iceman
This is my example of a simple stopwatch... It is quite accurate, especially for measuring short times. I have not tried with long times.

Start Button
Code: Select all
SetVar "[HH]" "00"
SetVar "[MM]" "00"
SetVar "[SS]" "00"
SetVar "[Crono]" "00:00:00"

TimerStart "Timer1" "1000"


Stop Button
Code: Select all
TimerStop "Timer1"


Timer Object
Code: Select all
Math "[SS]+1" "0" "[SS]"
If "[SS]" ">" "59"
    SetVar "[SS]" "00"
    Math "[MM]+1" "0" "[MM]"
    If "[MM]" ">" "59"
        SetVar "[MM]" "00"
        Math "[HH]+1" "0" "[HH]"
    EndIf
EndIf

StrLen "[SS]" "[Size_SS]"
If "[Size_SS]" "=" "1"
    SetVar "[SS]" "0[SS]"
EndIf

StrLen "[MM]" "[Size_MM]"
If "[Size_MM]" "=" "1"
    SetVar "[MM]" "0[MM]"
EndIf

StrLen "[HH]" "[Size_HH]"
If "[Size_HH]" "=" "1"
    SetVar "[HH]" "0[HH]"
EndIf

SetVar "[Crono]" "[HH]:[MM]:[SS]"

Re: Timer object question

PostPosted: Tue Jan 28, 2014 10:43 pm
by ajhunt
Hi Neo Team and Ice, Thank you for your help and suggestions and I will go through my code again and see if I can improve it but will cut and paste the relevant code below anyway. Thank you too Ice for your stopwatch code and I will no doubt experiement with that too. As usual this company and forum is the best ever on the www - where else do you get help and advice like this with the company and members within hours. Thanks a million Neo Team and Ice. Regards Anthony

SetVar "[[MaximumRecordingSeconds]" "90"
Run "[PubDir]CaptureAudio.exe" "Start" "RunOnce+Hidden" "" ""

.Countdown Display Start Seconds
Math "([Hour]*3600)+([Minute]*60)+[Second]" "0" "[StartSeconds]"

SetVar "[InstructionsText]" "[Instructions_06B]"
ShowObject "TimeRemainingText" "None" "0"

SetVar "[SomethingPressed]" "False"
IfEx "[ControlDevice] = Keyboard OR [ControlDevice] = Button"
npHookKeyboardStart "[Result]"
npOnKeyboardHook "SPACEPressed" "Key" "KeyName"
Else
npHookMouseStart "[Result]"
npOnMouseHook "MOUSEPressed" "Event" "x" "y" "data"
Endif
..............................................................................................
:AudioRecordingLoop
..............................................................................................
Math "([Hour]*3600)+([Minute]*60)+[Second]" "0" "[FinishSeconds]"
Math "[FinishSeconds]-[StartSeconds]" "0" "[UsedSeconds]"
Math "([MaximumRecordingSeconds]+1)-[UsedSeconds]" "0" "[DownSeconds]"

If "[DownSeconds]" ">" "[MaximumRecordingSeconds]"
SetVar "[DownSeconds]" "[MaximumRecordingSeconds]"
EndIf
............................
.Minutes and Seconds
............................
DefineVar "[Int2]" "Integer" "" "Local" ""
Math "[DownSeconds]" "0" "[Int2]"
Math "[MaximumRecordingSeconds]-[Int2]" "0" "[AudioLength]"
Math "trunc([Int2]/60)" "0" "[MM]"
Math "trunc([Int2]-([MM]*60))" "0" "[SS]"
If "[MM]" "<" "10"
SetVar "[MM]" "0[MM]"
EndIf
If "[SS]" "<" "10"
SetVar "[SS]" "0[SS]"
EndIf
SetVar "[MyDownSeconds]" "![MM]:[SS]"
............................
If "[SomethingPressed]" "=" "True"
GotoLine "ExitAudioRecordingLoop"
Else
GotoLine "AudioRecordingLoop"
EndIf
..............................................................................................
:ExitAudioRecordingLoop
..............................................................................................
Run "[PubDir]CaptureAudio.exe" "Stop" "RunOnce+Hidden" "" ""
SetVar "[InstructionsText]" ""
HideObject "TimeRemainingText" "None" "0"
SetVar "[SomethingPressed]" "True"

Re: Timer object question

PostPosted: Wed Jan 29, 2014 12:59 am
by dec
Hello,

Can I suggest the use of npWave plugin here? If the problem is related with some kind of synchronization between a NeoBook Timer and the "external recorder program", maybe the use of npWave can help, in the sense that the plugin inform you about the recorder time/position progress like you can see in the plugin recorder publication sample:

Image

Sorry if I really do not understand the problem here. ;)

Re: Timer object question

PostPosted: Wed Jan 29, 2014 11:15 am
by Neosoft Support
Thanks for posting your code. It seems to work although it uses a lot of CPU time and keeps counting after reaching 00:00. (I had to change the code because I don't have CaptureAudio.exe.) The problem with this approach is that executing the Run action at the end is always going to take some amount of time to complete which will throw off your timing. I don't think there is any way around this. Maybe using dec's plug-in would work since the timing and recording are synchronized.

Re: Timer object question

PostPosted: Wed Jan 29, 2014 11:52 am
by ajhunt
Hi Neosoft Team, is there a better approach I should be using then or will this suffice? Many thanks for your speedy reply as always. Regards Anthony

Re: Timer object question

PostPosted: Thu Jan 30, 2014 10:58 am
by Neosoft Support
A Timer object would be more efficient and require less effort from the CPU, but it wouldn't improve on the accuracy.

Re: Timer object question

PostPosted: Fri Jan 31, 2014 7:01 am
by ajhunt
Thanks NeoSoft Support. I'll think about using a timer object again, but that is where this all started with the variations in miliseconds the timer can take and the accuracy.

Re: Timer object question

PostPosted: Fri Jan 31, 2014 11:04 am
by Neosoft Support
I'll think about using a timer object again, but that is where this all started with the variations in miliseconds the timer can take and the accuracy.


Accuracy is going to be a problem no matter what you do.