Changing Where the Sound is Played: Balance, Fade and Rotation

With mono sounds, i.e., sounds that have only one audio channel, we can change the way the sound is played from our speakers through the use of the SetBalance, SetFade, and Rotation actions. The SetBalance action is used to change which speaker (the right speaker or left speaker) the sound will play out of. The SetFade action sets the sound to play from the forward or backward audio channels. The Rotate action allows the sound to be set at a rotation between 0 and 360 degrees around the user.

The SetBalance action is used to change how the audio plays out of the left and right speakers. SetBalance has one parameter, a number between -1 and 1 that represents which speaker to play out of. A number between -1 and 0 causes the audio to play from the left speaker, with a value of -1 causing it to play completely from the left speaker. A value of 0 causes the audio to play from both speakers equally. A value between 0 and 1 causes the audio to play from the right speaker, with a value of 1 causing it to play completely from the right speaker. The default balance of Audio objects is 0. Example uses of the SetBalance action are below.

use Libraries.Sound.Audio

Audio left
Audio right
Audio center

left:Load("Sounds/Firework.ogg")
right:Load("Sounds/Robot.ogg")
center:Load("Sounds/Modem.ogg")

// set the balances of the objects (there is no need to set the balance of the center object because its default balance is 0)
left:SetBalance(-1)
right:SetBalance(1)

left:PlayUntilDone()
right:PlayUntilDone()
center:PlayUntilDone()

The SetFade action is used to change how the audio plays out of the forward and back channels. SetFade has one parameter, a number, which represents which channel, forward or back, the audio should play out of. This number behaves in much the same way that the parameter of the SetBalance action works. A number between -1 and 0 causes the audio to play out of the backwards channel. A number between 0 and 1 causes the audio to play out of the forwards channel. Examples of the SetFade actions follow:

use Libraries.Sound.Audio

Audio front
Audio back
Audio center

front:Load("Sounds/Firework.ogg")
back:Load("Sounds/Robot.ogg")
center:Load("Sounds/Modem.ogg")

// set the balances of the objects (there is no need to set the fade of the center object because its default fade is 0)
front:SetFade(1)
back:SetFade(-1)

front:PlayUntilDone()
back:PlayUntilDone()
center:PlayUntilDone()

The Rotate action is used to rotate the sound about the listener. Rotate takes one parameter, a number that represents the amount of degrees to rotate the sound around the listener. 0 degrees represents a rotation in front of the listener. 180 degrees represents a rotation behind the listener. Examples of the Rotate action follow:

use Libraries.Sound.Audio

Audio audio

audio:Load("Sounds/Fwip.ogg")

// set the audio to be rotated 90 degrees with respect to the listener
audio:Rotate(90)

audio:PlayUntilDone()

SetBalance, SetFade, and Rotate have corresponding GetBalance, GetFade, and GetRotation actions that return the current value of each setting.

It is important to note that SetBalance, SetFade, and Rotate cannot be used at the same time. For example, if the balance is set on an Audio object, and then a call is made to set the fade of that same Audio object, the balance will be reset to the default value. We will not be able to use these functions to create the illusion of 3D sound. To do that, use the positional audio functions described in the next section.

Activity: Changing where the sound is played: Balance, Fade and Rotation

Use the SetBalance, SetFade and Rotate action

Next Tutorial

In the next tutorial, we will discuss 3D Sound: Positional Audio, which describes how to play audio files Quorum.