web scripting for designers - CGR C/092 - fall 2003
Philip van Allen - v a n a l l e n @ a r t c e n t e r . e d u

room 133, Monday 4:00pm-7:00pm
room 133, Monday 7:00pm-10:00pm
all materials on this web site © copyright 2003, Philip van Allen
 
week 12a - director audio, globals/properties, duplicate sprites, collision detection

audio in director : 


control the sound

Sample director movie: view sound.dcr, download sound.dir

Director can control the playback of multiple sounds at the same time. Each sound plays in a different channel, and only one sound can play per channel. The sounds themselves are stored in the cast, and are played on command using the play() method.

Simple method:

If a sound stored in the cast was called "mySound", the following code would play the sound from start to finish for one time:

sound(3).play(member("mySound"))

This code will play the sound in channel 3. It is traditional to play sound starting at channel 3 because any audio in the score normally plays in channels 1 & 2. To play two sounds at the same time, you might use the following code:

sound(3).play(member("mySound"))
sound(4).play(member("myOtherSound"))

Advanced method:

For more advanced applications of sound, Director offers more control over the sound. This control includes the number of times to loop the sound and the ability to change the pitch of the sound. Other features include playing and/or looping only a portion of the sound that's in the original sound file.

The following code starts the sound and loops the last part of the sound (from 2 seconds in from the beginning to 4 seconds from the beginning) 5 times. In addition, it changes the pitch of the sound up by 5 semitones. Note that the "\" symbol means that the code is continued on the next line. The properties used are indicated with the "#" symbol, where each property and value is separated by a comma. The properties can be specified in any order, and only the #member property is required.

sound(3).play([#member: member("mySound"), \
#loopCount: 5, \
#loopStartTime: 2000, \
#loopEndTime: 5000, \
#rateShift: 5)])

Queuing sounds:

Director offers the ability to queue up one or more sounds before they are played (preloading 1.5 seconds of the sound by default). This allows the programmer to make sure the sound plays immediately when the play command is given. If queuing is not used, some delay is incurred while the sound is loaded. Queuing also allows for setting up the playback of several different sound in sequence from one channel.

The following code queues two sounds, and then plays them both with one play command:

sound(3).queue(member("mySound"))
sound(3).queue(member("myOtherSound"))
sound(3).play()

Sound properties:

This table shows all of the properties that can be used by the play() and queue():

Property Value Description
#member member("memberName") The sound cast member to queue. This property must be provided; all others are optional

#startTime
milliseconds, default is beginning of sound The time within the sound at which playback begins, in milliseconds
#endTime milliseconds, default is end of sound The time within the sound at which playback ends, in milliseconds. endTime must be later than loopStartTime, if it is used.
#loopCount numberOfLoops, integer, default is 1 The number of times to play a loop defined with #loopStartTime and #loopEndTime
#loopStartTime milliseconds, default is beginning of sound The time within the sound to begin a loop
#loopEndTime milliseconds, default is end of sound The time within the sound to end a loop
#preloadTime milliseconds, default is 1500 The amount of the sound to buffer before playback
#rateShift semitones, 0 = normal, may have a fractional part to create "out of tune" notes. Undocumented feature. The number of semitones to shift the normal pitch of the sound. Can be positive or negative to shift the pitch up or down respectively.



other sound methods : 

a selection of useful methods

See the lists at the bottom of this page for a complete list all of the sound related methods. Descriptions can be found in the Lingo Dictionary under the Director HELP pull-down.

 

 
stop() : 

stop the sound in a channel

stop() immediately stops any sound playing in the specified channel.

Example:

sound(3).stop()

 

 
pause() : 

pause the sound in a channel

pause() pauses the currently playing sound in the specified channel.

Example:

sound(3).pause()

 

 
isBusy() : 

check to see if a sound is playing in a channel

isBusy() returns TRUE or FALSE to indicate if a sound is currently playing in the specified channel. See also the status property.

Example:

if (sound(3).isBusy()) then
    member("soundStatusText").text = "sound is playing"
else
    member("soundStatusText").text = "sound is stopped"
end if

 

 
volume : 

the volume of a channel

volume gets or sets the current volume of a channel. Values can range from 0 (mute) to 255 (maximum). These values are scaled to the full volume set for the computer by the user or the soundLevel property.

Example 1:

sound(3).volume = 130

Example 2:

sound(3).volume = sound(3).volume + 10

 

 
pan : 

the pan position of a channel

pan gets or sets the position of the sound in the specified channel relative to the left and right speakers. The range is from -100 (all left channel) to 0 (center: equal amounts in both channels) to 100 (all right channel).

Example:

repeat with x = -100 to 100
    sound(3).pan = x
end repeat

 

 
soundLevel : 

the computer's system volume

soundLevel gets or sets the computer's overall system volume that controls the level of audio coming out of the speakers. Values can set from 0 to 7.

Example:

the soundLevel = 6

 

 
all sound methods : 

from the Director help system

Table of Contents > Using Lingo > Lingo by Feature > Sound > Sound information

channelCount soundEnabled
sound volume (sprite property)
soundBusy() isBusy()
sampleCount status


Table of Contents > Using Lingo > Lingo by Feature > Sound > Playing sound

puppetSound sound fadeOut
sound close sound playFile
sound fadeIn sound stop
breakLoop() elapsedTime
endTime fadeIn()
fadeOut() fadeTo()
getPlaylist() setPlaylist()
loopCount loopEndTime
loopStartTime loopsRemaining
member (sound property) pan (sound property)
pause() (sound playback) playNext()
queue() rewind()
stop() (sound) play() (sound)


 

all materials on this web site © copyright 2003, Philip van Allen

top