Learn Unity audio basics

STYLY has the ability to upload MP3 files.
However, MP3 files uploaded directly to STYLY are heard at a constant volume throughout the space.

Using Unity’s audio, you can set the volume and the position of the audio to change with distance.

Master the audio to be able to create acoustic effects in a space.

Required Components

The basic components for playing sound in Unity are as follows

Image14

Audio file
An audio file such as mp3 or wav that can be imported into Unity and used as an Audio Clip .

Audio Clip

Imported audio files will be accessed as an Audio Clip in Unity.

At this stage, it is safe to assume that an Audio Clip is the same as an audio file.

Audio Source

The source of the sound, set the Audio Clip property of this component to the audio file you want to play.

The Spatial Blend property determines whether the sound source is 2D or 3D, which will be explained in more detail later.

Audio Listener

This component is attached to the MainCamera from the beginning.

It is safe to assume that the Audio Listener is located on the HMD in VR, or on the smartphone in AR, in other words, on the person who is experiencing the sound.

In STYLY, the Audio Listener is pre-built into the system side.
So, there is no need to upload the Audio Listener in the prefab scene, only the Audio Source!

Preparing Audio Files and Audio Source

Prepare the audio files you will use in this course.
You can use your own audio files, but if you do not have any audio files on hand, you can download them from sites that distribute free music materials.

For this study, we will use audio files from DOVA-SYNDROME, a site that distributes free music materials.

DOVA-SYNDROME will be introduced in detail in Section 4.

The first step in the process of downloading music materials is to check the Terms of Use and License, which allows commercial and non-commercial use of music materials on DOVA-SYNDROME without any credit statement.

Please be sure to read through the Terms of Use statement and the license.

Site Terms of Use

License

After reviewing the Terms of Use, access the download page.

https://dova-s.jp/bgm/play12427.html

Once you have accessed the page, click on the “Go to music download page” banner in the image.

Image2

The banner in the red frame of the image is the download link.
Click the link and download the audio file.

Image19

Save the file to any location.

Once saved, import it into your Unity project.

Right-click on the project window and select “Import New Asset.

Image3

A file selection dialog will appear. Import the MP3 file you just downloaded (or import your own audio file).

When the orange waveform object appears, import is complete.

Image21

Next, create an Audio Source in the scene.

Right-click on the Hierarchy window (hereafter referred to as “Hierarchy”) and select “Audio” > “Audio Source”.

Image5

You have now placed an Audio Source in the scene.

Image13

Setting an audio file to the Audio Source

Select the Audio Source object placed in the scene and look in the Inspector window to see the Audio Source component attached.

Image4

By setting an audio file in the “AudioClip” field of the Audio Source component, sound will be played from the Audio Source.

Set the audio file you just imported to the Audio Source.

Image6

Play the scene, and if music plays, the setting is complete.

Audio Source component settings

Looping the sound source

The following is a brief explanation of basic settings and frequently used setting items.

Putting a check mark in “Loop” under Audio Source will set a loop setting that will play the sound source again from the beginning when it is finished.

Image10

Changing the volume of sound

By changing the “Volume” of the Audio Source, you can change the volume of the sound.
1 is the maximum volume, the lower the value, the quieter the sound, and 0 is silent.

Image15

Changing the volume of sound according to distance

By changing the “Spatial Blend” of Audio Source, the sound volume changes according to the distance, creating a three-dimensional sound.

2D: The sound is heard at a constant volume regardless of the distance from the Audio Listener.
3D: The sound changes according to the distance from the Audio Listener.

Image20

These three items are the most frequently used items.
Other items can also be set to create various effects.

Let’s try to see what kind of changes can be made by actually touching them.

In this case, we set the following.

Image18

Since Spatial Blend was set to 3D, the sound volume now changes according to the distance.

Let’s actually play the scene.
During playback, try moving the Main Camera on the scene window and see if the sound volume changes according to the distance.

Image22

You can adjust the range of the sound by changing the settings.
This is useful when you have multiple sound sources in the same scene and want to change or mix the sound sources depending on the distance.

Click on “3D Sound Settings” in the Audio Source component.

This will open the settings for the range of sound.

Image1

In this article, we will focus only on the Min Distance and Max Distance settings, which have a significant impact on how sound reaches the listener.

Min Distance

This is the distance from the sound source to the point where the sound begins to attenuate.
If an Audio Listener is within this distance, the sound will not attenuate and will be heard at its maximum volume.

Max Distance

The distance at which the sound will stop attenuating.
Once it reaches this distance, the sound will not change in volume.
If the volume at which the attenuation will end is 0, the sound will not reach outside this range.

Min Distance / Max Distance is represented by a spherical gizmo in Unity.
Use the gizmo as a reference to adjust the reachable range.

Image17

This completes the basic Audio Source setup.

You can now prefabricate a scene containing an Audio Source object, or the Audio Source object itself, and upload it to STYLY.

You can freely control the Audio Source to create a variety of acoustic spaces.

Sites distributing free music materials

You can also use distribution sites to collect sound materials.

Sound is an important element in enhancing the immersive experience of VR, so make the most of it.

Many of the rules for using sound materials are complex, so be sure to read the terms of use.

Below are some recommended sites.

Unity Asset Store

Asset Store is an asset sales site provided by Unity Technologies.

https://assetstore.unity.com/

Since it is an official service, it makes the process of importing assets into Unity easy.
The site offers a variety of assets, including 3D models and audio materials, many of which are available for free.

After accessing the site, select the asset of your choice and open the details screen.

Then click on “Add to My Assets” to obtain the asset (if you have paid, click on “Buy”).

(If you have paid for the asset, select “Buy Now” to proceed to the purchase screen).

Image11

When you get an asset, the display will change from “Add to My Assets” to “Open in Unity”.
With your Unity project open, click “Open in Unity” to go to Unity.

Image9

The following screen will appear:
(If you do not see this screen, you can display a similar screen from Window > Package Manager.

If you are importing assets for the first time, download the assets from “Download” and import them into your project from “Import”.

After the second time, you will be able to import from the beginning.

Image12

When you click Import, the following screen will pop up.
Click Import in the lower right corner to import, or Cancel to cancel.
After importing, a folder containing the materials will be added to your project.
Let’s create a scene using the materials.

Image16

DOVA-SYNDROME

Image8

DOVA-SYNDROME is a site where you can download over 8400 background music and 1000 sound effects for free.
https://dova-s.jp/
All distributed sound sources can be used for free, no credit is required and sound manipulation is allowed.
The site distributes an overwhelming number of sound sources, so you should be able to gather all the necessary sound materials you need by using this site.

Sound Effects Labo

Image7

Sound Effect Lab is a site that distributes a variety of sound effects.

https://soundeffect-lab.info/

All materials distributed on this site are free to use under predetermined rules.

No credit notation is required.

The site is divided into several categories, such as “environmental sounds” and “nature/animals,” making it easy to find the sound effects you need.

By observing the terms of use and using various sound sources effectively, you can create a rich production.