Book Image

Game Audio Development with Unity 5.X

By : Micheal Lanham
Book Image

Game Audio Development with Unity 5.X

By: Micheal Lanham

Overview of this book

Game Audio is one of the key components in making a game successful and it is quite popular in the gaming industry. So if you are a game developer with an eye on capturing the gamer market then this book is the right solution for you. In this book, we will take you through a step by step journey which will teach you to implement original and engaging soundtracks and SFX with Unity 5.x. You will be firstly introduced to the basics of game audio and sound development in Unity. After going through the core topics of audio development: audio sources, spatial sound, mixing, effects, and more; you will then have the option of delving deeper into more advanced topics like dynamic and adaptive audio. You will also learn to develop dynamic and adaptive audio using the Unity Audio Mixer. Further, you will learn how professional third party tools like FMOD are used for audio development in Unity. You will then go through the creation of sound visualization techniques and creating your own original music using the simple yet powerful audio workstation Reaper. Lastly, you will go through tips, techniques and strategies to help you optimize game audio performance or troubleshoot issues. At the end of the book, you’ll have gained the skills to implement professional sound and music. Along with a good base knowledge audio and music principles you can apply across a range of other game development tools.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
About the Reviewer
Acknowledgments
www.PacktPub.com
Customer Feedback
Dedication
Foreword
Preface

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

Note

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.

Note

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.

Note

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.

Note

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.