Vizard 8 » Reference » Multimedia » Ambisonic 3D sound
8.0

Ambisonic 3D sound

Vizard has support for WorldViz custom ambisonics sound systems.  Access to these sound systems is provided through the vizsonic module.

Note: The WorldViz ambisonics sound system is required to run the example code on this page.

Advantages of using ambisonics: (Enhanced Higher Order Ambisonic Spatialization)

Unlike more basic methods such as Vector Base Amplitude Panning (VBAP) and other panning laws (5.1, 7.1 etc), which effectively move a source between pairs of speakers, Ambisonics is a method to reconstruct an actual sound-field in space (using the Huygen’s principle). The sonic result is then accurate across a sizable ‘sweet’ area, rather than at a single ‘sweet’ spot, and all speakers contribute to the sound-field, demanding less powerful speakers for the same output power. Ambisonics decodes a sound-field using spherical harmonics, and HOA uses increasingly detailed representations. The system proposed uses 3rd order Ambisonics, which involves 16 spherical harmonics, and is suitable for systems of 16 to 40 or more speakers.

 

Benefits of HOA for Auditory Display:

The WorldViz solution adds a number of enhancements to HOA specifically for immersive spatialization, detailed below.

Using the vizsonic module

The vizard ambisonic module (vizsonic.py) creates a wrapper around the <node3d>.playsound function and allows for two new parameters, volume and directionality to be specified. Note that because the wrapper only replaces the <node3d>.playsound function any sounds played through the ambisonic system must be attached to a node3d object.  This also means that the majority of functions related to using ambisonics are the same as the those for node3d objects.

 

Below is a demo module showing the new playsound function being used to attach a sound to a node circling the user.

from vizsonic import *

viz.go()

# make a model to which we'll attach the sound
model = viz.addText( 'Helicopter', viz.WORLD )

# have the model circle the user
R = 5
model.center(0,0,R)
model.setPosition(0,0,-R)
model.addAction(vizact.spin(0,10,0,45))

# attach a sound to the model and set the volume to max and directionality to beam sound.
sound = model.playsound('helicopter.wav',viz.LOOP, volume=1.0, directionality=1.0)

When programming for an ambisonics system there are a few things to keep in mind.  First all sound files should be loaded at the beginning of the module.  Next there are only 24 sources we can use.  Therefore creating multiple copies of the same sound file should be avoided if possible.  For example the code below is bad since an object is created every time the space key is pressed:

model = viz.addText( 'ball.wrl', viz.WORLD )

def play():
    sound
= model.playsound('bounce.wav')
   
vizact
.onkeydown(' ', play)
viz
.go()

Instead the object for the sound file should be created once then each time it needs to be played the play function should be called.  In general this is better code anyway.

model = viz.addText( 'ball.wrl', viz.WORLD )
sound
= model.playsound('bounce.wav')
sound
.stop()# prevents the sound from playing immediately

def play():
    sound
.play()
   
vizact
.onkeydown(' ', play)
viz
.go()

WorldViz supplies a mac mini which is used as a controller and processor for the sound files being played by the vizard script.  In order to allow the mac mini to play the sound files in the vizard script the mac mini must be network accessible and mapped to a drive letter (Z by default).  When a script is started for the first time the ambisonics code will then sync the files in the user's local "sound" folder with the files on the mac mini, only copying files if they are new or newer than existing files on the mac mini.

 

Here is another sample script showing an object with two attached sounds playing them dependent on interaction with the scene.  The court contains a ball that plays a bounce sound when it hits the floor and a crash sound when it hits the ceiling.

''' Simple example script that plays a crash when the ball hits the ceiling and
    a bounce when it hits the floor
'''

import viz
import vizact
from vizsonic import *
viz.go()

#Enable physics, but don't use gravity
viz.phys.enable()
viz.phys.setGravity(0,1,0)

ball = viz.add('ball.wrl')
ball.setPosition(0, 1.7, 5)
ball.setVelocity(viz.Vector([0, 1, 0],length=3.0))

#Make sure balls maintain constant velocity
def UpdateVelocity():
    ball.setVelocity(viz.Vector(ball.getVelocity(),length=3.0))
vizact.ontimer(0,UpdateVelocity)

# add room
court = viz.add('court.ive')

#Enable collisions with the court room based on its mesh
court.collideMesh()
court.disable(viz.DYNAMICS)


# add a bounce sound
bounceSound = ball.playsound('bounce.wav')
bounceSound.stop()# prevents the sound from playing immediately

# add a crash sound
crashSound = ball.playsound('crash.wav')
crashSound.stop()# prevents the sound from playing immediately


#Enable collisions with the ball based on a sphere shape
ball.collideSphere()

#We want to be notified of the balls collisions
ball.enable(viz.COLLIDE_NOTIFY)

#Called when two objects collide in the physics simulator
def oncollide(e):
    # if the ball is less than eye height assume it just hit the floor
    if ball.getPosition()[1] < 1.7:
        bounceSound.play()
    else: # otherwise we hit the ceiling
        crashSound.play()

viz.callback(viz.COLLIDE_BEGIN_EVENT,oncollide)

Setting sound properties

Vizsonic allows the user to specify the reverberation settings for the current simulation using the <vizsonc>.setReverb function. While these settings can be changed during the simulation, they may result in audible clicks. Below is an explanation for some of the sound settings in the simulation.

# example of using vizsonic to set the reverberation
roomsize = 20
shininess = 0.4
attenuation  = 0.8
simplicity = 0.2
volume = 0.7
vizsonic.setReverb (roomsize, shininess, attenuation, simplicity, volume)

Setting the ambient sound

The vizsonic module also allows the user to set the ambient soundfile track. The ambient soundfile loops continuously and has no specific spatial location. This can be changed during the simulation. Sound files may be .wav or .aiff format, but should be mono. Filenames should be within the folder specified by the setpath command.

import vizsonic

viz.go()

# play the sound file in the background
vizsonic.setAmbient("carousel.wav", 0.5)

Accessing the Shakers

The worldviz sound installation may come with a floor-shaker for very low frequency effects. The vizsonic module allows the user to set the mix-volume of the floor-shakers. The shakers will be sent the same audio feed as the subwoofer, however as a special effect they may be enabled periodically with the shaker message. Therefore, simply setting the shaker volume to 1 will not cause any low frequency effect unless at the same time there is a sound-file playing with low frequency content. It may be prudent to include some low-frequency sound-files in the search path to be used for this purpose, if extensive use of the shakers is desired.

Testing a speaker configuration

The vizsonic module includes several methods to test the physical setup of an ambisonics installation.  Below is an example script making use of each function with a proceeding explanation.

import vizsonic

viz.go()

''' This test is to ensure that the speakers are properly arranged and audio
    cables correctly connected. A noise source is switched periodically between
    each of the speakers in turn, along with a voice recording of a number. The
    spoken number should match the speaker number, and the noise source should
    sound ideally of equal loudness and timbre between each speaker.'''
vizact.onkeydown('1', vizsonic.testChannels)

''' This test plays a test sound (a cymbal percussion hit) periodically cycling
    in a clockwise direction around the simulation space. The movement should
    sound evenly spaced and equally distant. It may be used as a test source to
    configure the reverberation settings of the simulated room, for example.'''
vizact.onkeydown('2', vizsonic.testPan)
    
''' This test loads a set of example sounds and plays them randomly within the
    simulated space, to provide a more heterogeneous example than the panning
    cymbal.'''
vizact.onkeydown('3', vizsonic.testSounds)

''' This test adds to the above tests a simulated navigating user - walking and
    turning around in the simulated space.'''
vizact.onkeydown('4', vizsonic.testWalking)
    
''' Tests the subwoofer channel independently from the other speakers.'''
vizact.onkeydown('5', vizsonic.testSub)
    
''' Should cause the shaker to vibrate '''
vizact.onkeydown('6', vizsonic.testShaker)
    
''' This command cancels the tests and simulations and resets the navigation to
    center position.'''
vizact.onkeydown('7', vizsonic.testNone)

Advanced configuration options

There are several options which can be set from Vizard in order to control the way that the mac mini handles loading sound files and configuration of the speakers.  In general they should not need to be adjusted.  Below is an example with the values supplied the same as the default settings for the module.

viz.setOption('sonic.server','soundmac')
viz.setOption('sonic.speakercfg','/Users/worldviz/Desktop/sound-system/auralizer/speakers-link.txt')
viz.setOption('sonic.path','/Users/worldviz/Desktop/sound-system/sounds/')
viz.setOption('sonic.reverb','8 0.9 0.8 0.6 0.2')

Additionally you can set server path for locating sound files using <vizsonic>.setPath([path]) and set the speaker configuration file using <vizsonic>.setSpeakers([filename]), although these options should generally not be used.

See also

Other sections:

Tutorial: Multimedia

Tutorial: 3D sound

Example scripts:

Adding sounds

3D sound