Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Game Audio Development with Unity 5.X
Game Audio Development with Unity 5.X

Game Audio Development with Unity 5.X: Design a blockbuster game soundtrack with Unity 5.X

eBook
R$80 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Game Audio Development with Unity 5.X

Introducing Game Audio with Unity

Welcome to our journey into game audio and audio development with Unity. It is the leading cross-platform game engine that provides an abundance of features to make developing games easy. For this book, it doesn't matter if you are completely new to game audio, Unity, or game development. We will start with the assumption that you are a complete novice and build from there. With each new chapter, we will be introducing new concepts and additional material. Of course, if you are an experienced Unity developer with basic knowledge of audio development, you may want to skim over the first couple of chapters. Regardless of if you are a novice or master, the later chapters in this book will cover plenty of Unity features and tools to give you the knowledge of developing AAA game quality audio for your games.

In this chapter, we will cover the basics of Unity and add audio to a project and scene in Unity. As this is the first chapter, we will be covering a quick introduction to game audio and then spend some time installing and configuring Unity. From there, we will introduce the core Unity components and how they function. Here is a summary of what we will cover in this chapter:

  • Introduction to game audio
  • Getting started with unity
  • Importing audio into unity
  • Audio sources and listeners
  • 3D sound and spatial blending audio

As with most of the chapters in this book, it is expected that you follow along and complete each of the exercises. Completing the exercises hands on will reinforce all the concepts and provide you with a good foundation for the more complex material introduced in later chapters. All the material required to complete the exercises will either be provided via the book's downloaded source code or will be freely available online. Therefore, in almost all cases, you will be required to have an internet connection. If you feel that you understand the content in a chapter and just want to review the completed examples, then follow the instructions provided in the book's download to build the final examples.

Introduction to game audio

Chances are, if you have played a few computer, video, or mobile games in your life, you are already quite familiar with what great game audio should sound like. Perhaps; you even cherish the audio from a couple of your favorite games. However, if someone asked you how they composed or mixed that audio, unless you were a professional audio technician, you would likely be at a loss on how the audio in a game mixes together. Fortunately, in this section, we will start to introduce some of the basic concepts of game audio, which we will of course build upon in later chapters in this book.

Main game audio components

Game audio, unlike audio a sound designer would compose for film or television, will typically be broken down into three distinct areas as listed here:

  • Music: This includes content such as theme or background music, in-game music such as a radio or a band playing, and can even include certain audio effects. Creating or obtaining unique music for your game could be as complex as recording a music track in a sound studio to purchasing rights to a music track of the asset store. In Chapter 10, Composing Music, we will explore how to compose your own unique tunes.
  • Sound: This generally includes sound effects, such as creaking doors, explosions, footsteps, clicking, beeping, and many others. Most sound designers or developers will often browse through many of the free or paid sound effects sites to find a sound they like. Another option is to record your own sound effects, essentially becoming a Foley artist. In Chapter 10, Composing Music, we will look at some techniques to create some unique sound effects in software.
Foley artists are traditionally people who create sound effects for film, television, and now games. The term Foley was coined from the originator, Jack Foley, who created real-time sound effects for early motion pictures. Today, the practice is no longer real time, but the name "Foley" is still synonymous with recording and creating sound effects.
  • Vocals: The addition of vocals to games is a relatively new addition. Vocals were first introduced in cut or intro game scenes but now they are a main element in any AAA title. Furthermore, most AAA titles will enlist a well-known actor to provide vocals for further enhancement of the game. In Chapter 9, Character Lip Syncing and Vocals, we will cover some details about generating vocals. As well in several other chapters of this book, we will highlight the use of vocal cues in scenes.

While game audio design is similar to film and television, in many components, it differs primarily by its implementation. Audio for film follows a linear well-defined pattern, whereas in games audio is non-linear and may even be dynamic or adaptive. We will of course cover many aspects of how game audio is dynamic and adaptive in the Adaptive Sound and Music section.

Diegetic versus non-diegetic sound

If you have never heard of the term diegetic, you may just have gotten a queasy feeling in your stomach wondering what you got yourself into. Do not worry, the term diegetic refers to audio that is audible in the scene or screen as a part of the action or interaction. Conversely, non-diegetic refers to sounds that are added to the scene or screen and are not visible. Perhaps; it is more helpful if we look at some examples of diegetic and non-diegetic sounds, listed here:

  • Diegetic sounds include:
    • Sound effects: Explosions, gun fire, car engine, or collisions
    • Music: Band playing, musical instruments onscreen playing, or car radio
    • Vocals: Character dialogue, voices, or crowds
  • Non-diegetic sounds include:
    • Sound effects: Off screen sound effects such as coins entering a purse, tones to denote activity changes in a game, or footsteps
    • Music: Scary background theme music, a novelty theme, or boss theme music
    • Vocals: Narration, character vocal cues, or haunting voices

These terms may sound rather abstract right now, but be rest assured, we will get fairly intimate with the use of non-diegetic sounds in the adaptive sound and music section. As you will learn, one of the cornerstones of developing great game audio is building up good non-diegetic sounds.

You may have already noticed that game audio borrows or shares a number of common film and television terms sound designers use. That, of course, is not by accident. Games have been using the same principals of audio design established for movies and television for many years. In fact, later on in this book, we will explore the use of various commercial Digital Audio Workstations (DAW) traditionally used for film or television and now plugins to Unity.

Audio layers or groups

In virtually all digital games, the three base audio components we defined earlier may also include effects that will be broken into distinct layers or groups. This not only simplifies audio composition and development, which can become quickly complex as we will see, but also separates out critical audio elements. While you can think of each layer of audio playing separately during the game, from the player's perspective they will hear all the layers mixed together. The following list defines a set of basic layers we will use to group our audio:

  • Ambient and environmental audio: This includes both diegetic and non-diegetic audio such as waterfalls, ocean waves, birds chirping, a rowdy tavern, crowds, a humming power plant, or a band playing music. This group is not just limited to audio sound clips but may also include effects such as reverb, echo, distortion, or other environmental audio effects. We will cover ambient audio effects in more detail starting in Chapter 2, Scripting Audio.
  • Direct feedback audio: This will include any sound elements that that need to react directly to player input in a scene or on the interface. Diegetic examples of this would be shooting/reloading a gun, throwing a grenade, or watching something explode. Non-diegetic examples of this would be the sound of character getting shot, boss music playing, vocal cues, or dialog. Starting in a Chapter 2, Scripting Audio, we will cover several examples of this type of audio.
  • Interface audio: This includes sounds activated as part of the game interface. This typically would include items such as button clicks or notifications. We really won't go into too much depth in this area, as interface sounds are fairly standard and use the same principals you learn to manage other audio that is easily transferable to the interface.
  • Background or theme music: This area is relatively self-explanatory and immediately conjures up your favorite game theme music. However, background music can be used to dynamically change and thus alter the tone of a game during various conditions. This form of audio change is known as adaptive music and is something we will spend a great deal of time on, starting in the Adaptive sound and music section. In Chapter 2, Scripting Audio, we will introduce the use of background music in a scene.

Remember, this is only a basic definition of layers we have grouped our basic audio components into. As you will see through the rest of this book, there are a number of other ways we can group or layer audio. In Chapter 3, Introduction to the Unity Audio Mixer, we will cover the use and definition of audio groups in more detail.

Now that we have some very basic audio terminology defined, let's get into putting some of this knowledge to use in Unity. In the next section, we will look at downloading and setting up Unity.

Getting started with unity

This section assumes that you have never installed Unity before and will take you through a step-by-step exercise on download and installation. If you have installed Unity before, you may still want to quickly review this section, just to confirm you have installed the required components.

Downloading unity

Follow the instructions to download Unity:

  1. Enter the following URL, https://store.unity.com/, into your favorite web browser or just click on the link.
  2. After the page loads, you will see several licensing options. For the purposes of this book, all you need is the Personal Unity license. So, just click on the Download now button on the Personal license as shown in the following screenshot:
Screenshot from Unity store showing Personal license Download now button
  1. A new page will load, showing a big green button labeled Download Installer. Click on the button to download the Unity Download Assistant with your web browser.
  2. After the package has completed downloading, open it as you would any other program. The Unity Download Assistant is relatively small so it should download quite quickly.

 

  1. Agree to any security notifications or notifications you normally encounter when installing new software on your computer. After the installer launches, you will see a screen similar to the following screenshot:
Unity Download Assistant starting
If you are unable to install software on your computer due to security restrictions or other account settings, be sure to contact your administrator and ask them to give you access or have them install the software. During the course of this book, we will be downloading several software packages so it is advisable that you have the ability to install new software on your machine in order to complete all the exercises in the book.
  1. Click on the Next button to continue. Then on the next page, select the checkbox to agree to the Unity license as shown in the following screenshot:
Unity terms of service page
  1. Click on the Next button to continue. The next page will likely offer you an option to choose between 32 and 64-bit architecture. It is usually best to take the default (64 bit in most cases) and click on the Next button to continue.
  2. The next page will allow you to choose the Unity components you want to install. This page allows you to choose from a number of components to install along with Unity. For the purposes of this book, you only need to install the default components. However, if you feel you may need or want other components, such as Android or iOS, feel free to select those as well. Just be sure to have the three main components selected as shown in the following screenshot:
The Choose Components section of the Unity install
  1. After you have made your component selections, click on the Next button to continue. For the next couple of dialog pages, just keep the defaults and let the installation download and install Unity. Since this can take a while, feel free to grab your beverage of choice while you wait for the installation to complete.

The Unity installation will generally run very smoothly, but if you do encounter some issues, it is best to follow the recovery instructions the installer may provide. If that doesn't fix the issue, just do a quick search and check the Unity forums. Unity has a huge community of developers that are very eager to assist newcomers with any issues, and it is almost certainly likely someone has already encountered a similar issue to yours.

Once the Unity installer has finished installing Unity, follow the instructions here:

  1. On the last page of the installer, you will usually be prompted with an option to launch Unity right away. Be sure that option is selected and then exit the installer.
  2. As the program launches, you may get a notice to provide an exception in your firewall; be sure to allow this. After Unity launches, you will be welcomed by a login screen as shown in the following screenshot:
Unity login or welcome screen
  1. If you have never installed Unity before, you will need to create a Unity Account. Just click on the blue create one text as shown in the preceding screenshot. This will take you to a registration area of the Unity site. From there, complete that account setup, and when you are done, return to this item.

  2. Now that you have a Unity account created, enter your email and password in the dialog and then click on the Sign In button. After you sign in, you will be directed to the project page.

That completes your first step to becoming a Unity developer. In the next section, we will create a new project and explore the Unity interface.

An introduction to unity

Now that we have Unity installed, let's dive right in and create a project and then take a quick overview of the interface. Perform the following directions to create a new Unity project:

  1. If this is your first time running Unity, at this stage, you will have a dialog with a button allowing you to create a new project; click on the NEW. For those of you who have jumped here from another section in the book, be sure to launch Unity and make sure you are logged in with your Unity account. From there select the NEW project button at the top of the Unity start page.
  2. The project dialog will open. Enter the project name as GameAudioBasics and then keep the defaults for all the other settings as shown in the following screenshot:
Creating a new project in Unity
  1. After you fill in the Project name, click on the Create Project button.
  2. Unity will close the dialog, and you will see a progress dialog flash as the project is initialized and the interface loads. When Unity is done loading, you will see a screen that looks similar to the following window:
Unity interface
If you have run Unity before or if you are using a different license, such as pro, your screen may appear to be quite different. Aside from any themes applied, you can return to the default layout by selecting from the menu Window | Layouts | Default.

Now that we have Unity running, let's review what each of the main windows or elements are for. You can follow along using the reference numbers shown in the preceding window screenshot to match the items in the list here:

  • Hierarchy window (1): This window shows the currently displayed scenes and scene elements called a GameObject in Unity. Currently, there should be a scene labeled Untitled in the window. Click on the arrow beside the scene to expand it and then click on the items beneath the scene. Notice how the other windows change depending on your selection.
  • Scene view (2): You can think of the scene window or the view as the design canvas for your game project. In this view, you can select and move objects around using the mouse or the principal direction arrows (the colored arrows). Feel free to select objects in the view and move them around. Don't worry about moving things out of place or getting lost as we are creating a new scene before we start building anything of importance.
  • Inspector window (3): This window exposes and allows you to edit the properties and components of the currently selected GameObject. A lot of the time you spend working in Unity will be editing values in this window. Again, feel free to explore this window by editing some properties of a GameObject.
  • Project window (4): This window shows all the resources or assets you have in the entire Unity project. As you can, see the project is currently quite bare. Not to worry, we will be quickly adding new assets.
  • Game view (5): This window or view shows how the game will look to the player. It differs from the Scene view because it only shows what the player sees. If you click on the game window tab, you will see a sparse view of the ground layer and sky. Again, this is because we have yet to add anything interesting.
  • Play mode (6): This is the set of buttons at the top of the Unity interface control running the game in the editor. The buttons allow you to play and pause the game play. If you click on the play button right now, not much will happen other than the Game view will present itself.

At an advanced level, that covers the main elements of the Unity interface without getting bogged down in too many details. It could very well take you months or years to become an expert in using all the features of Unity. So, in order to not overwhelm you, we will only focus on the relevant information you need to complete an exercise.

So far we have been looking at an empty project and scene. In the next section, we will import a project from the Unity Asset Store.

Downloading and importing project assets

One of the really great features of Unity is the Unity Asset Store. Game development is a complex process that requires many artistic skills in multiple areas to develop quality assets, such as 3D models, animation, textures, sound, music, shaders, and more. Chances are, if your development team is just you or a small group of developers and artists, your team will lack the skillset or time to develop all the assets for your project. Fortunately, the Unity Asset Store provides professional game quality assets at very competitive pricing or in some cases for free. Unity itself also provides a number of high-quality sample projects free of charge on the store. We will be using a couple of those projects in this book as the base for our exercises in audio development.

Follow the instructions here to download and import the project we will use for the rest of the exercises in this chapter:

  1. From the menu select Window | Asset Store. This will open a new tab beside the Scene and Game views called Asset Store.
  2. After the page loads in the window, there should be a search box visible at the top of the window. Enter the text unity viking village in the search box and click on the search button as shown in the following screenshot:
Searching in the Unity Asset Store
  1. When the search completes, there will be a list of search results. The first result in the list should match Viking Village from Unity Technologies. Click on this item, and you should see the asset page as shown in the following screenshot:
Viking Village asset page
  1. Click on the blue button labeled Download, as shown in the screenshot to start downloading the asset.
  2. As the asset downloads, the button will show the progress. The download may take a while, so be patient and of course feel free to grab another one of your favorite beverages.

 

  1. When the download completes, the button will read Import. Click on the button to import the project into Unity. You will be immediately prompted by a dialog informing you that this is a complete project, as shown here:
Project import warning
  1. Click on the Import button on the dialog to continue the project import. Importing a new project over our project is entirely okay since we have nothing we wanted to save at this point.
  2. A dialog will appear showing you the progress of the import. This take a couple minutes after which you will be prompted with the Import Unity Package dialog, as shown here:
Import Unity Package dialog
  1. The Import Unity Package dialog shows all the assets to be imported as a part of the project. Feel free to scroll through the list and review the items being imported. Then, click on the Import button on the dialog to complete the project import.
  2. Yet another dialog will open showing you the progress of the last stage of the import. Just be patient and enjoy that beverage or grab another, the asset will load in several more minutes.

This project asset we are importing is on the large side, at around 900 MB. Fortunately, we will only need to do this once. As we will continue to reuse this project throughout the book. Generally, the assets you download from the Asset Store will often be under 100 MB.

The amount of time to import a project will be determined by the size of the asset and the content. Assets such as textures, for instance, will be compressed and often take extra time to load. Unfortunately, the sample project we are loading is composed of several compressed assets.

  1. When the import is complete, you will now find that the Project window is now showing several new asset folders.

Now, that we have our base project imported, in the next section, we take a quick look at the main scene and several features that will help us going forward.

A tour of the village

After doing all that work getting the project loaded; okay, perhaps not so much work as waiting, let's load the project scene and take a quick tour of the asset by following the directions here:

  1. Click on the Scenes folder in the Project window and then double-click on the The_Viking_Village.unity file to open the scene. The screenshot here shows the Project window:
Opening the project scene
  1. After the scene loads, you will notice that the Hierarchy window is now filled with objects. Click on the Scene view tab to open the view and you should now see something very similar to what is shown in the following screenshot:
Hierarchy window and Scene view
  1. Press the editor play button, as shown in the preceding screenshot to start the scene and run the game.
  2. As the game is running, the Game view will automatically present itself. Use the following commands to move around the game and explore the environment and features:
    • W, A, S, D: The standard first person movement commands. Use these keys or the arrow keys to move around the scene.
    • Mouse: This controls the look direction.
    • Spacebar: This is used to jump up. Quickly taping the Spacebar key will cause the camera to hover/fly while in manual mode.
    • C: This toggles between a controlled camera walkthrough and the manual or keyboard movement (first person).
    • Esc: This exits the mouse lock and makes the mouse visible in the editor again.
  3. Take your time to explore the environment and feel free to move around as much as you like. When you are ready to move on, press the Esc key to make the mouse visible again and then press the play button again to stop the game running.
  4. Hopefully, you noticed, as you were moving around the game, how quiet everything was. Fortunately, that makes this scene the perfect canvas for us to develop our own game audio. This is exactly what we will do for the next several chapters in this book.

Installing Unity and getting your first project loaded is a great first step to becoming a Unity game developer. Congratulate yourself for your patience in spending the time to work through this section. In the next section, we will get back to more audio development basics.

Importing audio into unity

Aside from downloading content from the Asset Store, there are a number of ways of introducing content into a Unity project. Most often, the simplest way of adding content to your project is placing the appropriate files into the relevant project folders. Unity is then smart enough to inspect the new files, provided the file type is supported by Unity, and determine the asset type to automatically import the content. Since there are a number of audio file types out there, let's take a look at the audio file format Unity currently supports in the following list:

  • .wav / .aif: Both of these formats are uncompressed, lossless formats, which means they are exact copies of the original audio. The .aif originated on the Mac, while .wav came from the PC. Now both formats are supported by either operating system.
Compressing audio or other forms of media is done in order to reduce the file size for easy transport or download. Since media compression will cause a loss of quality to the media, the term lossy is used to denote a compressed media format. Whereas, lossless or no loss, denotes a media format with no compression and thus no loss in quality.
  • .mp3: This is the most common compressed or lossy format for audio. This format became very popular for transferring/downloading music.
  • .ogg: This, also known as Ogg Vorbis, was developed as a patent free alternative to mp3. The standard format is lossy but it can support lossless as well.
Unity can also import tracker module formats such as impulse tracker (.it), scream tracker (.s3m), extended module file format (.xm), and the original module file format (.mod). We won't cover these file types until later, in Chapter 10, Composing Music.

Now that you have a better understanding of the supported audio files types, let's import a couple of files into our project in the following exercise here:

  1. Before importing any content, we will create a new set of folders in the project. This will help us organize and find this content later. As you can see, by just taking a quick look through the Project window, a game project may contain numerous assets in multiple areas.
  2. Right-click (control + Click on Mac) on the root Assets folder in the Project window. Then, select Create | Folder from the context menu.
  3. A new folder will be created under the Assets folder with the cursor prompting for input. Name the new folder Audio.
  4. Right-click (control + Click on Mac) on the new Audio folder and select Create | Folder from the context menu. Name the folder Ambient and your Project window now look like the following screenshot:
New Audio and Ambient folders created in Project window
  1. Right-click [control + Click on Mac] on the Ambient folder and select Show in Explorer from the context menu. This will open a file explorer on your desktop. Double-click on on the Ambient folder to open it; the folder should be empty.
  1. Go to your desktop and open the books downloaded source code Chapter_1_Audio folder in another file explorer window. Drag the folders so that they are adjacent to each other and both visible. A sample screenshot is shown here:
Ambient and source code folder: Chapter_1_Audio side by side
  1. Drag and drop all the files from the Chapter_1_Audio folder into the Ambient folder. Then, switch back to the Unity editor. After a couple seconds, you should see the Ambient folder in the Project window update with the imported audio files, as shown here:
Imported audio files showing in project folder
  1. Select the lake-shore-waves2.wav audio clip in the folder and then divert your attention to the Inspector window. You should see something similar to what is shown here:
Inspector window showing imported audio clip
  1. Click on the asset play button, as shown in the preceding screenshot, and enjoy the soothing sounds of waves hitting the lake shore. We will get into more details about what those other properties are in the next section.

Inspecting the imported audio files

Now that we have imported some new audio files into our project, let's take a more detailed look at how Unity handles them by following the exercise here:

  1. Focus your attention to the bottom of the Inspector window showing the audio file import settings. The following is a labeled screenshot of the details we want to pay attention to:
Examining the audio file details
  1. The following is a definition of what each of those sections/terms mean:
    • Audio channels: This shows the various audio channels composed into the file. Unity can support up to eight channels of audio. The file we are showing has two channels in order to support stereo.
    • Compression: Unity will automatically apply compression against imported audio files. Very often you will want to stay with the defaults, but we will look at ways of altering the compression method here. Vorbis, the compression type shown, is similar to mp3. The compression formats supported by Unity are: Vorbis, PCM, and ADPCM.
    • Sample rate: This represents the frequency at which the audio sample was recorded, displayed as the samples per second. Most audio will be recorded in the range of 44100 and 48000 Hz. Generally, the higher the sample rate, the better quality the audio will be and Unity supports up to 192000 Hz.
    • Mono/Stereo: This stipulates if the audio will play in stereo or mono. This setting will be honored if a sound is played in 2D space. However, if the sound is played in 3D, this will change. We will explore 3D sound in more detail at the end of this chapter.
    • Play time: This displays the minutes and seconds an audio file will play for.
  2. Now that we have those definitions under our belt, we will take a look at how to alter some of the import settings. Switch your attention to the top of the Inspector window as shown in the following screenshot:
Inspector window audio import settings panel
  1. Since we will be importing a number of audio files into Unity, it is important we review each of these settings in more detail here:
    • Force To Mono: This setting allows you to force Unity to down sample the file into a single channel, which is useful for sounds be played in 3D or you just don't want to play in stereo.
    • Normalize: This setting won't activate unless you force mono. Normalize refers to the down sampling process of converting a multichannel sound to a single channel. Normalize all the channels to be sampled at an equalized volume.
    • Load In Background: This sets the clip to load in a background while the game is running. If you have a large audio file, you will certainly want to check this setting.
    • Load Type: This tells Unity how to load the clip into memory and supports the following settings:
      • Decompress On Load: This works well for small to medium size files. The files will be decompressed into memory on load and not suffer any CPU performance when playing.
      • Compress in memory: This is best for large files played less frequently. Files will need to be decompressed before playing but the savings in memory may make this a preferred option.
      • Streaming: This plays the file directly from the disk. It is a great option for media played infrequently or memory management is an issue.
    • Preload Audio Data: By default, the audio clip will be loaded unless this option is unchecked. Again, this is another good option for less frequently played files.
    • Compression Format: This is the format used to compress the clip and is dependent on the game build settings. The format will match one of the following settings:
      • PCM: The pulse-code modulation is a format best used for smaller file sizes.
      • ADPCM: This is the format best used for short sounds with a lot of noise such as footsteps and weapons.
      • Vorbis/MP3: This is best used to compress larger files such as our sample file. The quality of compression can be set by the quality slider.
      • HEVAG: This is similar to ADPCM.
    • Quality: This is a slider that allows you to downgrade the quality of a clip with the benefit of reducing the file size.
    • Sample Rate Setting: This sets how the sample rate of the clip should be handled and will be one of the following:
      • Preserve Sample Rate: This prevents the sample rate from being modified.
      • Optimize Sample Rate: This will select the highest rate sampled within the file and apply that.
      • Override Sample Rate: This allows the sample rate of the file to be downgraded. This will generally reduce the audio quality but for some large files or specific audio effects this may be preferred. This setting can never be used to artificially increase the quality or sample rate of a clip.
    • Sample Rate: This value can only be changed if the Override Sample Rate setting was selected. Again, a sample can easily be downgraded to reduce the file size and quality but this setting cannot be used to upgrade a file beyond what it was originally recorded at.
  2. As you can see, there is a lot going on in this panel and initially it may be difficult to grasp all the terminology used. Fortunately, this panel is something we will come back to several times over the course of this book and you will get to become quite familiar with the terms and settings.

Let's use some of that new knowledge to tweak the settings on that torch.wav file we just imported by conducting the following exercise:

  1. Select the torch.wav file in the Project window Assets/Audio/Ambient folder.
  2. In the Inspector window, check the Force To Mono setting. The torch clip will be used as a full 3D sound and does not need two channels or stereo. Be sure the Normalize box is also checked.
  3. Click on the Apply button at the bottom of the panel. After a few seconds, this will apply the changes to the audio clip; Notice at the bottom of the Inspector window how the audio is now using only a single channel. Click on the play button to play the clip, you will most likely not hear much difference.
  4. Click on the Sample Rate Setting drop down-list and select the Override Sample Rate option. Then, open the Sample Rate list and select 22050 Hz from the list and then click on the Apply button. After the settings are applied, the preview clip should match the following screenshot:
Preview showing modified audio clip settings
  1. The reason we downgraded the clip is to reduce some of the harsher tones. Feel free to downgrade or adjust the sample further to see the effects it has on the sound quality. Be sure to reset the clip to the settings shown in the preceding screenshot as we will be using this sound later in the chapter.
Downgrading the torch clip to balance the tones may not be an optimal solution in some cases and in fact there are many other ways of equalizing a clip, as we will see. However, optimizing a clip at the source, as we did here, will always be in your best interest. In fact, if your game becomes bogged down due to overuse of audio, one of the core solutions is to optimize the imported file settings first. Audio performance and optimization is something we will cover in more detail in Chapter 11, Audio Performance and Troubleshooting.
  1. After you are done editing the audio clip settings, select File | Save Project from the menu. This will save the project and allow us to close the editor now if we need to.

That completes our introduction to importing audio content into Unity. In the next section, we will look at how these clips can be added to our village scene.

Audio sources and listeners

Before we add audio to our scene, we need to cover a few more basic concepts within Unity.

Of course, the best way to do that is to get hands on and explore more of the scene objects with the following exercise:

  1. If you have taken a break, open back up Unity and reload the GameAudioBasics project, which we saved at the end of the last section. Of course, if you haven't taken a break, good for you, and just continue as you were.
  2. Now, divert your attention to the Hierarchy window and specifically the search field at the top of the window. Click on the down arrow at the left of the search field, to select the form of the search as shown in the following screenshot:
Setting the search type
  1. Now, enter AudioListener; make sure to use the same case in the search field. This will filter the GameObject in the Hierarchy window with an AudioListener component attached, as shown in the following screenshot:
Hierarchy window showing filtered list of game objects with AudioListener
  1. As you can see, this filtered list of objects is showing us the various scene cameras. A camera in Unity is what captures the rendered view of the scene. As such, you can think of a camera as the player's eyes to the game world. Therefore, it only makes sense that we also make the camera be able to listen to the world using the AudioListener component. That way, as the camera moves around the scene, the ears or Audio Listener, will also be tightly coupled.
A GameObject in Unity is the base scene object. What differentiates one object from another is the components attached to the GameObject. A component is a script that applies specialized functionality to a GameObject. A component could include everything from a camera, audio listener, audio source, mesh renderer, and so much more. The Inspector window allows you to view, modify, add, and remove components on a GameObject.
  1. Select Camera_high at the top of the list in the Hierarchy window and take a look at the Inspector window and bottom-right corner of the Scene view as shown in the following screenshot:
Camera preview and Inspector window
  1. As you can see, there are a number of components attached to the Camera_high object in the Inspector window. We won't get into the details of all the components but just take notice of the Camera and Audio Listener. Remember that these two components equate to the scene's eyes and ears. Select the Camera_high object selected and press the Play button to run the scene.
  2. After the scene starts running and switches to the Game view, press the Esc key to unlock the mouse. Then, go to the Inspector window and scroll through the components. Feel free to turn off and on components by unchecking the checkbox beside the component name. You can even alter the component settings if you like. Notice how the Game view changes as you make those changes. Don't be afraid to change several things; as long as you are in play mode, nothing will be saved.
  3. When you are done with exploring the Inspector window, press the Play button again to stop the game running.

Good. As you can see, we already have a number of Audio Listener components set up on the scene. This means that we can certainly hear any audio. However, we are still missing the source of our audio, which hasn't been configured. In the next section, we will add an Audio Source component to our scene.

Adding an audio source

In order to hear any audio in a scene, we need two components added to game objects. They are the Audio Listener - the ears, and the Audio Source - the noise. As you probably already realized, the dead silence of our scene must mean there are no configured Audio Sources. In the following exercise, we are going to rectify that issue by adding an Audio Source:

  1. Open the Unity editor and make sure the Viking Village scene is loaded. If you are continuing from the last section, be sure to click on the X on the right side of the Hierarchy window search field. This will remove the type filter and show all the scene objects again.
  2. Locate the GameObject called AccessibleVolume in the Hierarchy window and click on the arrow beside it to expand and show its child objects. Select the Capsule 5 object and press F, to frame select the object as shown in the following screenshot:
Frame selecting the Capsule 5 GameObject
  1. What we want to do is use the Capsule 5 object as an Audio Source for our lake-shore-waves ambient sound we imported earlier. We will use this object as it is conveniently situated close to where we want our Audio Source. Before adding the audio though, let's make a couple changes to the capsule.
We are going to add the audio to the scene following the audio layers and groups we defined earlier. Therefore, the first layer we will be adding the audio to is for the ambient and environmental background noises.
  1. With the capsule object still selected, rename the object Ambient_lake-shore-waves and then set the Z position on the Transform component to 60 as shown in the following screenshot:
Renaming and altering the position of the Capsule 5 GameObject
Giving your game objects an appropriate name is essential, especially as your scene becomes more complex. Notice how we prefixed the object name with our layer name and then followed that with the audio clip name.
  1. After you changed the Z position of the Transform, you will notice that the object moves to shore of the lake in the Scene view. This is exactly what we want, as this capsule object will be the source for the lake-shore-waves ambient sound.
  2. Next, click on the button Add Component button at the bottom of the Inspector window. Type audio in the search text and notice how the list filters to components with audio in the name. Select the Audio Listener component as shown in the following screenshot:
Adding the Audio Source component
  1. We now have an empty Audio Source component on our object. Click on the target icon located next to the AudioClip property. This will open the Select AudioClip dialog. Select the lake-shore-waves2 clip from the list as shown in the following screenshot:
Setting the AudioClip on the component
  1. Close the dialog after selecting the clip. We won't worry about all the other settings on the component right now. However, we do want to make sure the clip loops, since, after all, it is ambient sound that should keep playing over and over again. Click on the checkbox next to the Loop setting to make sure the audio loops.
Audio clips will typically be designed to either play forever, called a loop, or play just once, called a single shot. In most cases, you will want your ambient sounds to loop, but not always. Whereas, audio-like weapons or footsteps will generally be a single shot. A looping audio clip is one that is designed to play over and over again with no noticeable break or change when the clip plays over.
  1. With the Audio Source is added to the scene, press the Play button. Explore the scene by moving around and listening to the audio as you move. When you are done exploring, press Ctrl+P (command + P on Mac) to stop the scene running.

 

  1. Select File | Save Scene from the menu, to save the changes we made to the scene. It is a good habit to save your scene often in Unity and especially when you are working with large scenes.

Good, we now have an ambient Audio Source in our scene. Of course, most likely, the first thing you noticed is that the sound was everywhere and that certainly is not what we want. We obviously only want our waves sound to be more audible when we get closer to the lake and certainly not so pronounced everywhere. What we need is to make our Audio Source use 3D or spatial sound and this is exactly what we will cover in the next section.

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.

Summary

In this chapter, we introduced a few core concepts in game audio, which we will expand on in successive chapters. After the audio introduction, we focused on downloading and installing Unity, followed by a quick walk through of the editor. From there, we imported a complete sample project from the Asset Store as a basis for completing the exercises in this and the later chapters. We then imported audio assets into the sample project and learned about compression, sample rates, channels, file formats, and more. With those new audio assets, we configured an ambient sound in our sample project, deciding later to convert that sound to 3D after understanding some basics of spatializing sound. Finally, we finished the chapter by adding another ambient sound to our scene and altering the various Audio Source settings to our auditory preference.

With this introductory chapter done, in the next chapter we will again dive into new areas of game audio and Unity development, which will include an introduction to Unity scripting, audio triggers, physics, and weapons sounds and music.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 1. Explore the basics of audio development in Unity to create spatial sound, mixing, effects, composition, adaptive audio and more.
  • 2. Leverage the Audio Mixer of Unity 5.x to create blockbuster sound and music for your game.
  • 3. Learn about developing professional audio for games with FMOD Studio and composing original music with Reaper.
  • 4. Build amazing audio synchronized graphic visualizations with Unity.
  • 5. Understand how real-time character lip syncing can be implemented.

Description

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.

Who is this book for?

The ideal target audience for this book will be game developers, both Indie as well as semi pro. No prior knowledge of Unity and audio development is assumed,

What you will learn

  • • Develop game audio and other audio effects with Unity
  • • Getting familiar with the new Audio Mixer introduced in Unity 5
  • • Implement dynamic and adaptive audio using various tools and strategies
  • • Explore interesting ways to incorporate audio into a game with sound visualization
  • • Use 3rd party professional audio development tools like FMOD
  • • Compose original music and record vocals
  • • Understand and troubleshoot audio performance issues

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2017
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781787120808
Vendor :
Unity Technologies
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 30, 2017
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781787120808
Vendor :
Unity Technologies
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 852.97
Mastering Unity 2017 Game Development with C#
R$306.99
Unity 2017 Game Optimization
R$272.99
Game Audio Development with Unity 5.X
R$272.99
Total R$ 852.97 Stars icon

Table of Contents

11 Chapters
Introducing Game Audio with Unity Chevron down icon Chevron up icon
Scripting Audio Chevron down icon Chevron up icon
Introduction to the Audio Mixer Chevron down icon Chevron up icon
Advanced Audio Mixing Chevron down icon Chevron up icon
Using the Audio Mixer for Adaptive Audio Chevron down icon Chevron up icon
Introduction to FMOD Chevron down icon Chevron up icon
FMOD for Dyanmic and Adaptive Audio Chevron down icon Chevron up icon
Visualizing Audio in Games Chevron down icon Chevron up icon
Character Lip Syncing and Vocals Chevron down icon Chevron up icon
Composing Music Chevron down icon Chevron up icon
Audio Performance and Troubleshooting Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(2 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
DANIEL ROMAN Dec 20, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book for beginners in game audio.
Amazon Verified review Amazon
IvanDBeltran Oct 29, 2020
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Conceptually the book is an excellent resource. It contains step-by-step instructions which serve as a starting point for further development. However, the example project will not work with newer versions of Unity out-of-the-box, some tweaking needs to be done updating deprecated classes in the project to make it work which will not make it suitable for beginners. The audio assets provided could also be better, although it is understandable that is not the scope of the book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.