Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Game Audio Development with Unity 5.X

You're reading from   Game Audio Development with Unity 5.X Design a blockbuster game soundtrack with Unity 5.X

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787286450
Length 404 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Micheal Lanham Micheal Lanham
Author Profile Icon Micheal Lanham
Micheal Lanham
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Introducing Game Audio with Unity FREE CHAPTER 2. Scripting Audio 3. Introduction to the Audio Mixer 4. Advanced Audio Mixing 5. Using the Audio Mixer for Adaptive Audio 6. Introduction to FMOD 7. FMOD for Dyanmic and Adaptive Audio 8. Visualizing Audio in Games 9. Character Lip Syncing and Vocals 10. Composing Music 11. Audio Performance and Troubleshooting

3D sound and spatial blending

In this section, we are going to introduce the concept of 3D sound and show how this is implemented at the basic level within Unity. Since the introduction of virtual reality, there has been other implementations of 3D or spatial sound, which Unity can support through plugins, but that is outside the scope of this section. Either way, perhaps it is best to start with a definition of 2D and 3D sound using the following diagram:

Representation of 2D stereo versus 3D mono or spatial audio (see: https://icodelikeagirl.com)

In Unity, the basic simulation of 3D sound is achieved by reducing the audio to a single channel and then attenuating (altering the volume), depending on the distance and location to the listener. There are several variables that allow us to customize how an Audio Source is spatialized in Unity, which we will cover when we convert our lake waves 2D ambient sound to 3D in the exercise here:

  1. Continuing from the last section, be sure the Ambient_lake-shore-waves object is selected in the Hierarchy window.
  2. Go to the Inspector window and scroll the component list to the bottom so that all of the Audio Source component is visible.
  3. Drag the Spatial Blend slider all the way to the right in order to make the sound entirely 3D as shown in the following screenshot:
Setting the spatial blend on an Audio Source
Depending on the audio effect you are after, you may not want a full 2D or 3D Audio Source. Fortunately, with the Spatial Blend slider, you can select a mixture of both 2D and 3D sound. An example of an Audio Source that may use both 2D and 3D is an audio effect that needs to be heard everywhere but also has an obvious source.
  1. At this point, we won't make any other changes to the Audio Source but take note of the 3D sound settings and especially the graph at the bottom of the component. Observe the line representing the listener position on the graph. Pay particular attention to that line, and press the Play button to run the game.
  2. Move around the scene and move to the water down the boardwalk. Notice how the sound does get louder as you approach the water or if you turn the direction will also change to represent where the Audio Source is. However, the sound probably isn't quite as loud as we want and the falloff is just too gradual.
  3. Stop the scene from running by pressing Ctrl+P (command + P on Mac).
  4. Let's alter the 3D settings on our Audio Source. Change the Max Distance on the 3D Sound Settings of the Audio Source to 100. Notice how this changes the graph as shown in the following screenshot:
Changing the max distance of the Audio Source
  1. Press play and move around the scene again. Notice how the sound now attenuates better as you move close to the shore. Feel free to change the various 3D sound settings and see what effect they have on the audio playback.
The 3D Sound Settings volume/distance graph curves and lines can also be altered by clicking on them and dragging the line or keys to alter their position and shape. Double clicking on a curve or line will introduce a new key which will allow you to alter the shape of the curve even further. With this ability to alter an audio sources volume, spatial, spread, and reverb over distance is very powerful and can allow you to create some very interesting effects.
  1. When you are finished altering the Audio Source settings stop the scene. At this point, if you find a combination of different audio settings, you think, might work better, feel free to set those values now. After you are done making the changes, be sure to save the scene by selecting File - Save Scene from the menu.

As you can appreciate, now there are numerous ways to configure a sound to be 2D, 3D, or some mixture of both. How about we add another ambient sound for all the torches in our village by following this exercise:

  1. Switch your attention to the Hierarchy window and click on the search type dropdown on the left of search field. Then, be sure to select by Name as shown in the following screenshot:
Changing search filter type to by Name
  1. Enter prop_torch in the search field. Notice how the Hierarchy window filters the objects to just display those with the matching name. Select all the objects in the window by clicking on the top item and then while holding the Shift key, select each of the remaining items in the list. So, all the torch items are selected as shown in the following screenshot:
Selecting all the torch objects
  1. Making sure that all the objects are still selected, go to the Inspector window and click on the Add Component button at the bottom of the window. Then, as you did before, type audio in the search field to filter the list to audio components. Select the Audio Source component from the list to add it to all the prop_torch GameObjects.
In our example, we are modifying several copies of the same object, the torch. Yet that doesn't have to be the case. You can use this same technique to modify several different objects as long as they share a common component.
  1. After the Audio Source is added to the objects, set the properties on the component to match those in the following screenshot:
Torch Audio Source properties
  1. If you find yourself struggling to set any of the properties on the Audio Source component, refer to the preceding sections in this chapter. After you are done making the edits, press the Play button to run the scene.
  2. Be sure to explore the scene and be sure to move close to the water and around the torches. Feel free to make changes to the Audio Source settings as you explore. As always, if you find some settings sound better, remember those and make those edits again after you exit the play mode.
Have you noticed that the exercise instructions become less specific as you move through the exercises? Well, of course that is intentional and not only will it test your knowledge and make sure you are paying attention, but it also forces you to explore the Unity editor and find your own way to do something. There are numerous ways to do even the simplest tasks in Unity, and as you gain experience in the editor, you will find your own preferred ways of doing things.
  1. When you are done testing and tweaking audio, be sure to the save the scene and project.

Well, that completes this section and our introduction to 3D sound in Unity. We covered this material quickly and did not go into details of the 3D Sound Settings. There will be plenty of time to cover additional details about those settings in upcoming chapters.

You have been reading a chapter from
Game Audio Development with Unity 5.X
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781787286450
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image