Hi, I've been using Enterprise to build a standalone app that plays a small sound file repeatedly at regular intervals while a timer counts down. I have the code all worked out for the timing but I'm having a problem with the accuracy of the intervals between the sounds.
The timer keeps the time correctly, so that's not the problem, but the sounds sometimes come at irregular intervals. And very often the right number of repetitions are not accomplished in the time, for instance, if I have it set to repeat 20 times per minute, I might get 19 or 21 repetitions. Anyone have any suggestions or ideas?
I'm thinking that the problem might be related to how the app uses the computer's resources because the problem is more or less severe depending on what computer is running it (really bad on a machine running Vista that can already barely handle Vista). Is there any way of reserving a certain amount of the computer's resources just for this app while it is running?
Any other ideas or explanations?
Thanks!
accurate sound loop timing
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
I don't know how to get "super accurate" with timings because you're always reliant on the computer to keep an accurate clock, which it doesn't.
I guess you use a "send in time" construct for your timing loop or something like that. Any variation in the throughput will be compounded over the life of the cycle.
As a "top of the head" thought - this isn't necessarily any more "accurate" but at least it will always stay within a certain margin of error as synched with the computer's onboard clock, and therefore not creep wildly out of true.
Card script:
Button script (or other initialiser)
You can play with the intervals and/or switch to milliseconds, but it might help keep a more "constant" rhythm.
I guess you use a "send in time" construct for your timing loop or something like that. Any variation in the throughput will be compounded over the life of the cycle.
As a "top of the head" thought - this isn't necessarily any more "accurate" but at least it will always stay within a certain margin of error as synched with the computer's onboard clock, and therefore not creep wildly out of true.
Card script:
Code: Select all
global gRunFlag, gTock, gElapsed
on timeThis pInterval
local tTick
if gRunFlag then
put the seconds into tTick
add tTick - gTock to gElapsed
if gElapsed >= pInterval then
beep
put zero into gElapsed
end if
put tTick into gTock
send "timeThis 3" to me in 200 milliseconds
end if
end timeThis
Code: Select all
global gRunFlag, gElapsed
on mouseUp
put not gRunFlag into gRunFlag
put 0 into gElapsed
send "timeThis 3" to this card
end mouseUp
Thanks for your help, Spark!
I've been using a similar construct but you got me thinking about how I could streamline parts of the script. I think I got into trouble trying to have the program do too many other actions between the sound repetitions. I might have it worked out now, just have to get my hands on one of those slower Vista machines to test out the changes.
Thanks again.
I've been using a similar construct but you got me thinking about how I could streamline parts of the script. I think I got into trouble trying to have the program do too many other actions between the sound repetitions. I might have it worked out now, just have to get my hands on one of those slower Vista machines to test out the changes.
Thanks again.