[x3d-public] audio and timesensor synchronization

Joe D Williams joedwil at earthlink.net
Mon Sep 4 13:00:40 PDT 2023


Hi All,
I have a scene with AudioClip and TimeSensor animations.When Open, if same file then, same as Reopen, the audio restarts, but the animation time sensor (after instantaneous reset to 0) restarts where it left off, rather than actually restarting. This leaves the sound and animations out of synch and so useless. Really appears like my timer is running with WorldTime when it is turned off then gets reset using relative to World Time when reopen or open. 

I thought I should have the  answer to this by starting the animation timers under control of the audio startTime. Just don't start animation timers until audio starts then all should synch.

So, I can understand some caretaking like this when the author is reloading to fix some stuff and just wants to proceed rather than start an animation over from the beginning, but it seems to me that the author also ought to have the keys to get a complete restart from the beginning.

So, in this case, I really do want to be able to keep this audio in sync with the animation. When I do tell the animation timer to start with the audio, I want to be able to depend on that rather than the tool taking over and deciding what to do with regard to the TimeSensor timing depending upon the last time I did Open or Reopen with the same or similar file. In this case the Audio startTime sent to the animation timer is not being honored.  

This is how it is coded:

    <TimeSensor DEF='GBTimer' cycleInterval='100' 
      enabled='false' loop='true'/>

    <Sound DEF='SceneMusic' >
      <AudioClip DEF='Melodies' 
         loop='true' enabled='true' 
         url='"wrv2_103seconds.wav"'/>
    </Sound>




    <ROUTE fromField='startTime' fromNode='Melodies'
                   toField='set_startTime' toNode='GBTimer'/>
    <ROUTE fromField='isActive' fromNode='Melodies'
                    toField='set_enabled' toNode='GrampsBoxTimer'/>

Is the basics. When the audio starts, then the animation timer starts. But I also want to stop the animation at the last frame when it ends, instead of repeating the animation. There must be a better way, but I am using:

    <BooleanSequencer DEF='GBTimerLoopControl'
      key='0 0.9 1' keyValue='true false false'/>
    <ROUTE fromField='fraction_changed' fromNode='GrampsBoxTimer'
       toField='set_fraction' toNode='GBTimerLoopControl'/>
    <ROUTE fromField='value_changed' fromNode='GBTimerLoopControl'
      toField='loop' toNode='GBTimer'/>

Which turns off the animation timer after one cycle. 

Sending the loop false twice seems necessary since if sent only at fraction time 1 it lets animation timer move to start and actually send 0 fraction instead of ending at last frame. I think the loop true/false should be evaluated before start is set, not set start then check loop, Loop false at tic fraction 1 should not allow the timer to proceed to 0. If loop is false at load,then start is not sent.     

And I also want the AudioClip to stop after one play with no repeat so I did this:

<ROUTE fromField='value_changed' fromNode='GrampsBoxTimerLoopControl' toField='loop' toNode='Melodies'/>

Since the animation timer ends its cycle a few seconds before the audioclip, (100 seconds vs 103 seconds) this should also keep the audioclip from looping. Unfortunately,it does not and the audio continues until it is stopped by unknown, Seems like loop false recognized some time later than needed to stop the audio at its end. as the audio plays.  By changing the animation timer cycletime I see the loop false is recognized at some time which seems related to when I send the audio loop false and that I might be able to with luck pick a lucky time that matches the stop time I need. 

So, please help me figure out how to control this thing the way I need to. 

Thanks All,
Joe











.





More information about the x3d-public mailing list