Adobe Dreamweaver Forums



Last 10 THreads :         PS CS4 "Save As ..." format choices appear in duplicate (Last Post : Dan_Dill@adobeforums.com - Replies : 0 - Views : 1 )           »          Re: Colour differences on the web (Last Post : g_ballard@adobeforums.com - Replies : 0 - Views : 1 )           »          Re: SFW and date created (Last Post : Ann_Shelbourne@adobeforums.com - Replies : 0 - Views : 1 )           »          Re: sRGB vs. Adobe (1998) RGB (Last Post : Neil_Keller@adobeforums.com - Replies : 0 - Views : 1 )           »          help my flash site opens pop ups? (Last Post : Awebus - Replies : 2 - Views : 3 )           »          Flash IDE randomly creating Symbols (Last Post : MediaMackenzie.com - Replies : 0 - Views : 1 )           »          Wishing I could make Sprite Symbols using F8 (Last Post : MediaMackenzie.com - Replies : 0 - Views : 1 )           »          3 overlapping background images on same page (Last Post : brad_goldstein - Replies : 8 - Views : 9 )           »          help me with adjustments layers in CS4 (Last Post : Ann_Shelbourne@adobeforums.com - Replies : 4 - Views : 5 )           »          Re: Help authenticating installer (Last Post : Awebus - Replies : 0 - Views : 1 )           »         


User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-04-2008, 09:02 AM
ReubenH
 
Posts: n/a
Diggs:
Default flash.utils.Timer is distressingly inaccurate

Hi,

I am writing a music synthesizer program. For it to play fast pieces of music
where notes are, say, 100ms to 200ms apart, accurate timing is essential. Yet
the Flex Timer class has a relatively large error... on my XP laptop the timer
events arrive 0 to 30ms late (and thats with GUI updates turned off!), which is
sufficient to make playback sound very bad indeed.

I am wondering if there is anything I can do about this? At the moment I think
my best bet is have my timer events complete 50ms early (assuming 50ms is
worst-case lateness) and busy-wait the last up-to-50ms bit of time before
playing the next note. But that seems pretty hideous.

Questions:

#1. Is there anything I can do to reduce the delay, or at least make it more
predictable?

#2. Is there a "nice" way to busy-wait? AFAICS all I can do is spin until
flash.utils.getTimer() >= desired_timer_time...

#3. Maybe my whole design could be better. Is there a way to play two
consecutive MP3s (on the same SoundChannel) with an accurate period of time
between them that doesnt involve the Timer class?

Many thanks!



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-04-2008, 09:02 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: flash.utils.Timer is distressingly inaccurate


"ReubenH" <webforumsuser@macromedia.com> wrote in message
news:ge4ab0$79v$1@forums.macromedia.com...
> Hi,
>
> I am writing a music synthesizer program. For it to play fast pieces of
> music
> where notes are, say, 100ms to 200ms apart, accurate timing is essential.
> Yet
> the Flex Timer class has a relatively large error... on my XP laptop the
> timer
> events arrive 0 to 30ms late (and thats with GUI updates turned off!),
> which is
> sufficient to make playback sound very bad indeed.
>
> I am wondering if there is anything I can do about this? At the moment I
> think
> my best bet is have my timer events complete 50ms early (assuming 50ms is
> worst-case lateness) and busy-wait the last up-to-50ms bit of time before
> playing the next note. But that seems pretty hideous.
>
> Questions:
>
> #1. Is there anything I can do to reduce the delay, or at least make it
> more
> predictable?
>
> #2. Is there a "nice" way to busy-wait? AFAICS all I can do is spin until
> flash.utils.getTimer() >= desired_timer_time...
>
> #3. Maybe my whole design could be better. Is there a way to play two
> consecutive MP3s (on the same SoundChannel) with an accurate period of
> time
> between them that doesnt involve the Timer class?


I think the timer logic may be in the enterFrameHandler function, so it is
tied to when the playhead enters the next frame. I think your only solution
is to go with a really high frame rate.


Reply With Quote
  #3 (permalink)  
Old 11-04-2008, 09:02 AM
ReubenH
 
Posts: n/a
Diggs:
Default Re: flash.utils.Timer is distressingly inaccurate

Thanks for the reply!

enterFrameHandler... that sounds like something in Flash. I'm only really
familiar with the Flex SDK... is there an ActionScript class you can point me
at? How is the overall framerate for an .swf set? That might well be the key to
getting accurate timing....

Reply With Quote


  #4 (permalink)  
Old 11-04-2008, 09:02 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: flash.utils.Timer is distressingly inaccurate


"ReubenH" <webforumsuser@macromedia.com> wrote in message
news:ge4i00$h7g$1@forums.macromedia.com...
> Thanks for the reply!
>
> enterFrameHandler... that sounds like something in Flash. I'm only really
> familiar with the Flex SDK... is there an ActionScript class you can point
> me
> at? How is the overall framerate for an .swf set? That might well be the
> key to
> getting accurate timing....


I think this is a private method in most classes. But if you want to go
crawling around in the UIComponent code, knock yourself out ;-).

I'd have to look up how to change the frame rate, same as you, but I'm
confident it is in the Help.


Reply With Quote
  #5 (permalink)  
Old 11-04-2008, 09:02 AM
ReubenH
 
Posts: n/a
Diggs:
Default Re: flash.utils.Timer is distressingly inaccurate

frameRate appears to be a writable property of flash.display.Stage (see
http://livedocs.adobe.com/flex/2/lan...html#frameRate). I
look forward to experimenting with this property's effect on Timer behaviour
later.

Thanks for your reply.


Reply With Quote
  #6 (permalink)  
Old 11-04-2008, 09:02 AM
ReubenH
 
Posts: n/a
Diggs:
Default Re: flash.utils.Timer is distressingly inaccurate

Well whaddyaknow! The frame rate absolutely affects timer accuracy in a
beautifully deterministic way...

I coded up an experimental app which used a timer set to 100ms and a slider to
control the framerate. If the frameRate is 10 (frames per second) then the
frame period is 100ms which matches the timer period exactly and there is no
error at all, not a single millisecond.

But if the frame rate is 11, the frame period is 90.9ms, and the timer event
arrives a constant 98ms late.

Further experimentation showed the timer event lateness is directly and
reliably proportional to the frame period.

I suspect this an artefact of event dispatching... what I guess happens is the
OS-level timer fires, an event gets added to an internal queue somewhere, but
dispatching doesn't happen until the next frame.

All I need to do, in theory, is ensure the frame period modulo the timer
period is zero and all should be fine...

Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk