3Dsound.py
This script demonstrates the use of 3D sound, otherwise known as spatialized
sound.
# WorldViz Copyright 2002====================================================
# This script demonstrates the use of 3D sound, otherwise
known as spatialized
# sound. To mimic the sound changes that occur in
real environments with
# real sounds, the computer will change the sound being
played between the
# two speakers (or 4 speakers for fancy cards) to create
the sense of spatialized
# sound. Vizard uses Microsoft Direct Sound as it's
interface to this procedure,
# which in turn will use any 3D sound acceleration that
is available on your
# sound card. As such, you'll have to turn to either
Microsoft or your sound
# card manufacturer to try and figure out what is really
going on. Good luck.
#
# In this demo, the sounds are played from the bell tower,
fountain, and avatar.
#===========================================================================
import viz
import vizact
viz.setMultiSample(4)
viz.fov(60)
viz.go()
import vizinfo
vizinfo.add("Press
1 to play the bells\nPress spacebar to toggle sound debug mode")
piazza = viz.addChild('piazza.osgb')
#Attach sound to fountain
piazza.playsound('fountain.wav',viz.LOOP,node='fountain-sound')
#Play bell sound from bell tower when key is pressed
bell_sound = piazza.playsound('bells.wav',viz.STOP,node='bell-sound')
bell_sound.minmax(0,3)
vizact.onkeydown('1',bell_sound.play)
#Add an avatar in a walking state
avatar = viz.addAvatar('vcc_male2.cfg')
avatar.state(2)
#Move the avatar in a circle around the origin
avatar.setPosition([-4, 0, 0])
avatar.setCenter([4,0,0])
avatar.addAction(vizact.spin(0,1,0,15))
#Play footsteps sound from the avatar's location
avatar.playsound('footsteps.wav',viz.LOOP)
#Visualize location of sounds
viz.setDebugSound3D(True)
#Toggle sound debug with spacebar
vizact.onkeydown('
',viz.setDebugSound3D,viz.TOGGLE)