Beginner Tutorial


Music and Sound Basics


15 minutes

Posted on: October 8, 2017

Learn Sumerian
Music and Sound Basics

Tags

music
sound
ambient
background

In this tutorial you will learn about:

Camera types
Light types

Background music and sound are important parts of any 3D application. In this tutorial, we’ll add background music and sounds, and create reactive sound effects.

You’ll learn about:

  • How to add background music
  • Ambient sounds
  • Control sound settings
  • State Machine

Prerequisites

Before you begin, you should have completed the following tasks and tutorials:

Step 1: Create or Open a Scene

From the Dashboard, create a new scene or open an existing one. We will be using a scene from a previous tutorial, Material Fundamentals.

Step 2: Add Background Music

To add background sound or music, we must add it to an empty Entity.

  1. From the Create Entity menu, select Entity under the Others category.

  2. Add a new component in the Inspector panel, and then select Sound.

  3. Drag and drop an audio file into the Drop Sound input, or browse and import audio you choose.

    Note: Audio files cannot exceed 10 MB.

  4. To edit the settings of your Sound component, click the edit button (pencil icon). This populates a new panel with all your audio settings.

  5. You can adjust the volume and select/deselect three other settings, as shown.

  • Loop: Puts your audio file on repeat and loops it when the scene is in play mode.
  • Auto Play: Plays your audio file automatically when the scene goes into play mode.
  • 3D Audio: Puts your audio file into 3D scene. For virtual reality, this enables the sound to come from a specific location. This is best tested by adding a Sound component to an Empty entity and placing it somewhere in the scene. If the Empty entity is behind the user, the sound will come from behind. If it’s in front of the user, the sound will come from the direction they’re facing. The sound will also get louder/softer as the user approaches or creates distance between themselves and the Translation (i.e., location) of the entity. If this setting isn’t selected, the sound will originate from no specific location.

Step 3: Add Sound Effects

To add responsive sound effects, use the State Machine. We will add a sound effect to play when an entity is clicked. We will use the Sphere from the Material Fundamentals tutorial. However, you can use any visible entity.

Using Sound Component

To add a sound effect to a scene that’s responsive to a click, we need to follow the same process in Step 2 above. However, we need to add the sound, or audio file, to the the entity that’s producing the sound. For this exercise, the Sphere will make a sound effect when it is clicked. Therefore, we need to add a sound file to the Sphere entity.

  1. Select the Sphere entity.
  2. Add a Sound component to the Sphere entity.
  3. Drag an audio file onto the Sound component’s Drop Sound input, or browse to locate it.

Audio files in a Sound component will be accessible in the State Machine.

Using the State Machine to add Responsive Sound Effect

  1. Select the Sphere in the Entities panel, and then add a new State Machine component. To learn more about the State Machine, see the State Machine Basics tutorial.

  2. In the state graph, use the default State 1 and rename it “Play Sound Effect”. Then choose Add Action.

  3. In the Add Action menu, search for and then add the Play Sound action.

  4. In the Inspector panel, choose the sound you want to play from the Sound menu. We selected our own My Sound.mp3 file.

  5. Add another State, name it “Click”, and then choose Add Action. In the Add Action menu, search for and then add Click/Tap on entity.

  6. In the Inspector panel, be sure to set the Click state as the default by clicking Set As Initial State.

  7. Finally, add two transitions between both states by clicking on an action and dragging an arrow to the other state.