Programming for Interactive Multimedia
Notes from Week Nine

Multimedia in Director

Sound in Director

Compatible file formats

.wav
.aif, .aiff
.mov (audio only QuickTime)
.mp3
RealAudio
SWA (Shockwave Audio-Director's native format)

Linking vs. embedding sound

The general rule is to import small sound files (sound FX and shorter spoken or song clips) and to link larger files to save on memory requirements. Any file you import into Director will lose it's compressed state and take on Director's internal format. This allows the sound to play between platforms more easily, but it may sound different than the original file. External sound enables you to use Lingo to buffer just enough of the sound to start it playing and then stream the remainder using the preLoadTime property of a playlist. The sound will begin playing much faster than if the user had to download the entire sound first. If the final format for the movie is a Shockwave movie for the web, sound should be external and should be in a streaming format like SWA, .mp3, RealAudio or QuickTime.

The recommended sampling rates and bit depths for multimedia in general and Director in specific (if you are going to link the sound) are 22,050 kHz, 16-bit.

Controlling system sound

You can control the system sound or the sound channel itself. There are two controls for the system sound: the soundEnabled (whether the sound is on or off),and the soundLevel (the volume steps of the system sound).

The the soundEnabled is a property can be tested and set: it is either TRUE (the default--sound is on) or FALSE (sound off). This control should always be given to your user as the user may be in an environment, like an office or cubicle, where the sound is distracting. Granted, they could turn the system sound off on their own using the computer controls, but it's good user care to make it easy for them.

Usually you would create a toggle switch to turn the sound on or off with one button rather than creating separate buttons on the stage. The easy way to do that is to us the logical operator "not" in the following way:

on mouseUp me
the soundEnabled = not(the soundEnabled)
end mouseUp

If the sound was on (property value was TRUE) it would be turned off (property value would be FALSE), if it was off (FALSE) it would be turned on (TRUE).

The the soundLevel property has steps from 0 (quietest) to 7 (loudest). The default level is 4. You usually set the soundLevel at the beginning of the movie, and you can use it to ratchet volume up by these set notches, but for smooth volume changes, you can use the volume property on the actual sound channel (see below).

Controlling sound channels

Turning all of the sound off may not be what you want. You may want to give the user the opportunity to turn off the background music, but you may still want them to here the special effects on rollover buttons for for other actions in a game. In that case you would want to control the sound channels individually, not just all sound or no sound.

There are many ways of playing sound. These are all described in detail in Chapter 18 of the book, so I will just summarize them.

The first breakdown is playing the sounds in the sound channels in the score versus playing sounds with Lingo. To play a sound in the score, you would place it in sound channel 1 or 2, which is located in the expandible section above the frame bar which has the red playback head. The sound would play as long as the playback head is in a frame containing that sound and for as long as there is no Lingo command telling it to stop. It will loop if the loop property is set (on the cast member in the Property Inspector). You can also control it with the Tempo channel--using the "wait for cue point -- end" option you can have the playback head stay on the frame until the song stops.

You can really control sound using Lingo. With Lingo you can have up to 8 channels of sound, versus 2 in the score. You can also play, pause, stop, control the volume of, pan, fade in and fade out sounds in the sound channel in the score or sounds placed in the virtual sound channels by Lingo.

The puppetSound command was used up until Director 8. You can still use it, but it has been replaced by a new set of commands:
sound().play()
sound().pause() --which stops the playback at the point the button was pressed so that play will play from that point
sound().stop() --which stops the sound and play would start again from the beginning

The parentheses take optional arguments. If you are controlling sound in the only playing sound channel in the score, you don't need any arguments. But if you are playing a sound in the virtual channels (essentially puppeting even if they no longer call it that) you would use arguments.
sound(channel).play(cast member) with channel being a number or a variable, and cast member being a number, the name (as a string "my song"), or a variable reference. The same is true for pause and stop.

Volume is the property of the sound channel that allows you to have smoother transitions--like turning up a dial. Volume is an 8-bit property, 0 (no sound) to 255 (loudest), as opposed to the soundLevel which is a 3-bit property 0 to 1. The syntax is
sound(channel).volume = value

You can fade in and fade out of sounds using the volume property and a repeat statement
repeat with i = 1 to 135 --median level or repeat with i = 135 down to 1
sound(8).volume = i
end repeat

or

you can use the fadeIn or fadeOut or fadeTo property
sound(channel).fadeIn(fadeTime)
with fadeTime being measured, unlike other time measurements in Director, in milliseconds, with the default being 1 second (1000 milliseconds). If you use fadeIn, it is best to first queue the sound member or else the fade so that the fadeIn doesn't happen before the song is fully loaded and starts playing (see book for discussion of queues). The default is the top or the last level the volume had been.

The fadeTo property adds the argument of final volume :
sound(8).fadeTo(163, 2000) -- medium loud, 2 seconds

The fadeOut is like the fadeIn, only you don't need to queue the sound since it's already playing.

You can also pan stereo sounds:
sound(channel).pan = value
where value is between -100 (all left speaker) and 100 (all right speaker), with 0 being the default (both speakers equal). There are several setting considerations with pan, so look at the definition in the book. To achieve a gradual pan across speakers, use this statement in a repeat statement (see page 968 in your book).

CuePointNames, cuePointTimes, cuePassed and synching sound to Director events

Director is frame-based and sound is time-based, so synching animation or actions to sound can be tricky. The only way to do this is by using cue points in your sound file. The cue points need to be created in the sound file in a sound editing program using markers or regions, and the sound must be imported into the cast to access any cue point information in Director. Cue points can accessed by the Tempo channel, or you can go to the Message window and type

put sound(channel).cuePointNames --or cuePointTimes

to get a list. You can use the on cuePassed handler to sync actions to those cuePoints
on cuePassed me channel, cuePointNumber, cuePointName
sprite(8).member = member("secondAnimationLoop")
end cuePassed

Read the end of Chapter 18 for more discussion of on cuePassed and the functions mostRecentCuePoint and isPastCuePoint

Digital Video in Director

(in process) Meanwhile, read chapter 20 of Director 8 Demystified and review your notes and the example files (see links below or on the class home page) to learn the following topics:
Compatible file types
Recommended compression scheme
Digital video properties (crop/scale, loop, show controller, paused, streaming, direct to stage)
Controlling video (Play, Pause, Stop, Revere, Rewind, Fast Forward, Fast Reverse)
masks
CuePoints, cueNames and synching video to Director events

References & Examples

Chapters 18 (audio) and 20 (video) and Lingo Lexicon in Director 8 Demystified.

Example files sound control example.dir and movie control example.dir or both (available with linked media in controls.zip (15+ megs)).

 

Programming for Interactive Mulitmedia I Home