Solar System with 3D Audio Plugin for Unity

Skill LevelArea of FocusOperating SystemSoftware Tools
Intermediate3D Audio, GamingAndroid3D Audio Plugin for Unity, Snapdragon Profiler

This project is designed to add planetary sound effects to create a solar system with 3D sound using the Qualcomm® 3D Audio Plugin for Unity. It is designed to show you how to offload the reverb process to the DSP and monitor the performance using the Snapdragon Profiler.

The solar system looks very beautiful and attractive, and I want to hear the realistic sounds from planets. The main objective of this project is to use the Qualcomm 3D Audio Plugin for Unity and build this fun application.

Parts and Software used in the project

Below are the items used in this project.

  1. Android device with Qualcomm® Snapdragon™ 845 mobile platform.
  2. Windows PC as the developer environment.
  3. Unity 2018.3.9f1 Personal version.
  4. Snapdragon Profiler, a tool used to view the application performance in real time.
  5. Qualcomm 3D Audio Plugin for Unity, imported into Unity.

Setting up the development environment

  1. Request Qualcomm 3D Audio Plugin for Unity https://developer.qualcomm.com/software/3d-audio-plugin-unity, and install it to PC.
  2. Download Snapdragon Profiler from https://developer.qualcomm.com/software/snapdragon-profiler, and install it to PC.
  3. Download Qualcomm 3D Audio Plugin for Unity from https://developer.qualcomm.com/software/3d-audio-plugin-unity, and import into Unity.
  4. Download the code from the GitHub repository and make sure that the planet textures and audio assets are in the correct folders.
  5. Learn to add 3D sounds by following the steps provided here: https://www.youtube.com/watch?time_continue=129&v=VehZkzX4EcE
  6. Choose android platform and connect android device, then compile the project, if no problem, an APK will be generated and installed automatically.

    MainScene on the Unity, put main camera above the solar system

    NeptureScene on the Unity, put Main Camera on the Nepture’ track.

  7. You can use Snapdragon Profiler to view the CPU and DSP performance of the application.

How does it work?

  1. How to make Planets rotation and revolution?

    To realize this demand, I created a script in Solar-System-With-3D-Sound/Assets/Scripts/PlanetMove.cs

          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          
          public class PlanetMove : MonoBehaviour
          {
          public Transform origin;    //Rotation center
          public float gspeed;        //Revolute speed
          public float zspeed;        //Rotate speed
          public float ry, rz;        //to ensure eccentricity
          
          void Start()
          {
            //
          }
          
          void Update ()
          {
          
          	Vector3 axis = new Vector3 (0, ry, rz);     
          	this.transform.RotateAround (origin.position, axis, gspeed * Time.deltaTime);   
          	this.transform.Rotate (Vector3.up * zspeed * Time.deltaTime);       
          } 
          }
        

    The script is easy to understand, and you should drag it to the planets, here you can see there are five parameters, which means you must fill them before running the project. (and the script reusability is high.)

    Setting the Parameters for the Planet Moving Script.

  2. How to switch to different scenes with the button? (for adding interaction)

    To achieve the requirement, I add a script here:Solar-System-With-3D-Sound/Assets/Scripts/SwitchToMain.cs

          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          using UnityEngine.UI;
          using UnityEngine.SceneManagement;
          
          public class SwitchToMain : MonoBehaviour
          {
              // Start is called before the first frame update
              void Start()
          {
              //register a listener function.
                  this.GetComponent<Button>().onClick.AddListener(OnClick);
              }
          
              // Update is called once per frame
              void OnClick()
              {
                  SceneManager.LoadScene("MainScene");
              }
          }
        

    The script mainly registered a listener function named OnClick in start function. When there’s any click event and Onclick will be transferred, the script also needs to be added to the button.

    Setting the Switch to Main Script Onclick Event.

  3. How to achieve zoom in and out?

    We all know 3D sound is related with distance, i.e., if we are close to the audio source, we will hear the sound from audio source loudly, and if we are far from it, we can’t hear it. So in order to test and verify, I try to make gameobject to manual zoom, I add a script in: Solar-System-With-3D-Sound/Assets/Scripts/ZoomInAndout.cs

          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          
          public class ZoomInAndout : MonoBehaviour
          {
          //In order to record two old touch’s distance.
          
              private Touch oldTouch1;  
              private Touch oldTouch2; 
              void Start() {
                  
              }
              void Update() {
                  
                  if (Input.touchCount >= 0)
                  {
                      return;
                  }     
                  
                  //Get new touches from input.(from screen touch)
          
                  Touch newTouch1 = Input.GetTouch(0);
                  Touch newTouch2 = Input.GetTouch(1);
                  
                  //the second touch, just record ,not handle.
          
                  if (newTouch2.phase == TouchPhase.Began)
                  {
                      oldTouch2 = newTouch2;
                      oldTouch1 = newTouch1;
                      return;
                  }
                  
                  //caculate two distance.
          
                  float oldDistance = Vector2.Distance(oldTouch1.position, oldTouch2.position);
                  float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position);
                  
                  float offset = newDistance - oldDistance;
                  
                  //get scale factor.(becaue offset is too bigger than pixel.)
          
                  float scaleFactor = offset / 100f;
          
                   //zoom in out.
          
                  Vector3 localScale = transform.localScale;
                  Vector3 scale = new Vector3(localScale.x + scaleFactor,
                      localScale.y + scaleFactor,
                      localScale.z + scaleFactor);
                 
                  //only when scale greater or equal to 0.5, change it’s scale.
          
                  if (scale.x >= 0.05f && scale.y >= 0.05f && scale.z >= 0.05f)
                  {
                      transform.localScale = scale;
                  }
                 
                  //update two old touch.
          
                  oldTouch1 = newTouch1;
                  oldTouch2 = newTouch2;
              }
          }
        

    The script mainly to make gameobject zoom in and out, you can see more details by comments.

    Setting the Script to Zoom in and Out.

  4. How to use Qualcomm 3D Audio Plugin for Unity?

    Refer to https://developer.qualcomm.com/software/3d-audio-plugin-unity/quick-start-guide, it includes the following steps:

    1. Installation of the Qualcomm 3D Audio Plugin.
    2. Setup of the Qualcomm 3D Audio Plugin.
    3. Set Spatializer Plugin to QObjectsSpatializer and Ambisonic Decoder Plugin to QSoundfieldSpatializer.
    4. Place a Q3D AudioListener on the same object that has your AudioListener.
    5. Navigate to Window -> Audio Mixer to set up Q3D Audio Groups for sound objects and soundfields.
    6. Using the Qualcomm 3D Audio Plugin to Spatialize Audio.
    7. Adding Reverb to a Spatialized Audio Scene.
  5. How to convert Mono audioclips to 3D audio sound objects?

    Q3DAudioGlobalSettings provides several “SpatializeMonoAudioSources" check boxes that can enable settings in the Qualcomm 3D Audio Plugin to automatically detect Audio Sources that have mono AudioClips and make them Q3D Audio sound objects.

  6. How to offload reverb to DSP?

    Set "1st Choice Reverb Processor" and "2nd Choice Reverb Processor" to "COMPUATE_DSP." Currently this is a global setting that can't be changed at runtime.

There’s also some other problems encountered, and I made a simple record on my blog, more details can be seen from: https://blog.csdn.net/weixin_38498942/article/details/89337481

  1. Download code from github according to the repository from .
  2. The repository has two compiled APK for you to install on your smartphone and test. OnCPU.apk installs the application where the Reverb runs on the CPU. OnDSP.apk installs the application where the Reverb runs on the DSP.
  3. Install the APK on the smartphone and run the application.

    Main Screen seen after launching the application.

  4. You can use Snapdragon Profiler to view the performance.

    Application performance in Snapdragon Profiler showing less CDSP % Utilization.

    Application performance in Snapdragon Profiler showing more CDSP % Utilization.

NameEmailTitle/Company
Zhensunzhen@thundersoft.comThundersoft
Rongyangrong0925@thundersoft.comThundersoft
Koukouzw0723@thundersoft.comThundersoft
Bofangbo0326@thundersoft.comThundersoft
Qinyansq0930@thundersoft.comThundersoft

Qualcomm 3D Audio Plugin for Unity and Qualcomm Snapdragon are products of Qualcomm Technologies, Inc. and/or its subsidiaries.