Articles Archive
Articles Search
Director Wiki

Keeping your sounds in line

May 25, 1998
by Pat McClellan

Dear Multimedia Handyman,

I am using puppetSound to cue all of my sound members -- music, sound effects and voice over announcer. Frequently, I need to cue the music and VO at the same time, but I would like to delay the VO for a second or two so that the music can start first. Is there an easy way to build in the delay?

Rick Davis

Dear Rick,

There are a couple of ways to approach this. One obvious solution is to simply insert a second or two of silence at the head of your VO tracks. Then, you can cue both members in the same script and you'll get the effect of the delay you want. While this is the simplest approach, it doesn't offer you much flexibility. Once you have inserted the silence in the track, you're stuck with that duration. Plus, if you use the same track in several places, you don't necessarily want the same delay in every instance.

My suggestion is that you create a delay object. The concept is that we'll create an object -- an entity that lives in the computer's memory -- which will count off a specified number of ticks, issue the puppetSound command, and then disappear. You can issue the call for the delay object at the same time as you puppetsound the music track.

Let's start by creating the object's parent script. Open a new script and select the blue INFO button. Select "Parent" for the type of script. In the title field, name the script "parent: delayVO". Here's what should be included in the script...

-- delayVO object
property pWhichSound, pWhichChannel, pDelayTicks ¬
  , pStartTicks
on new me, whichSound, whichChannel, delayTicks
  add the actorList me
  set pStartTicks = the ticks
  set pWhichSound = whichSound
  set pWhichChannel = whichChannel
  set pDelayTicks = delayTicks
on stepFrame me
  if the ticks > pStartTicks + pDelayTicks then
    puppetSound pWhichChannel, pWhichSound
    deleteOne the actorList, me
  end if        

The on new handler creates an instance of the object by adding a reference of the object to the actorList. The other lines in the on new handler simply store the parameters (such as the delay time and the sound member) in the object's properties -- an object's private list of stored variables. By being on the actorList, this object will automatically receive instructions to execute the on stepFrame handler everytime the movie advances to the next frame. In this way, the object will repeatedly be prompted to check to see if the specified delay has elapsed. When the time has elapsed, the puppetSound command will be issued. When this has occurred, the object will dispose of itself by removing itself from the actorList. Simple and tidy.

Now, all we need to do is call the object. We'll do this from the same script where you puppetSound the music track. I'll assume that this happens on a button press, though it could easily be done anywhere.

on mouseUp
        puppetSound 1, "musicTrack1"
        new (script "parent: delayVO", "voTrack1", ¬
          2, 120)

The new command creates the object specified by script "parent: delayVO". Then, we need to pass the object the parameters in the order corresponding to the parent script: whichSound, whichChannel, and the delayTicks. In this case, I specified a sound member called "voTrack1", to be played in sound channel 2, after a delay of 120 ticks (2 seconds).

As you can see, you'll be able to use this object over and over with any sound member, played in any sound channel, with complete control over the duration of the delay. The cool thing about objects is that you can create dozens of simultaneous instances and they will never interfere with each other or get mixed up on their own parameters. With some easy modifications, you could use this delay object to control any other element of your program -- not just sound.

If you've never used objects, this is a simple example of how to get started and how they might be used in your next program.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2019, Director Online. Article content copyright by respective authors.