Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by corbinyo · Oct 03, 2018 at 05:13 AM · androidaudiomusiclatencyvisualize

Major Latency on Android when using Microphone

I am having an issue with my unity project where I am making a music visualizer and picking up the audio with the Android Microphone (Samsung Note 9). The audio has a delay when making my gameobjects react (simple equalizer effect on a grid of cubes). Really not sure what the issue is other than the obvious issue that Android just has latency issues? Attaching my script in case anything stands out that would make the latency worse...

using System.Collections; using System.Collections.Generic; using UnityEngine; namespace AudioVisualizer { /// <summary> /// Object scale waveform. /// Scale objects along a given axis, to create an audio waveform. Objects are typically arranged in a line or close together. /// </summary> public class Master_ObjectScale_WaveForm_Grid_Material : MonoBehaviour { //____________Public Variables [Header("AUDIO SETTINGS")] [Tooltip("Index into the AudioSampler audioSources or audioFiles list")] public int audioIndex = 0; // index into audioSampler audioSources or audioFIles list. Determines which audio source we want to sample [Tooltip("The frequency range you want to listen to")] public FrequencyRange frequencyRange = FrequencyRange.Decibal; // what frequency will we listen to? [Tooltip("How sensitive to the audio are we?")] public float sensitivity = 2; // how sensitive is this script to the audio. This value is multiplied by the audio sample data. [Tooltip("What objects should we scale to create a waveform?\n Usually objects are placed in a line")] public List<GameObject> cubeobjects; // objects to scale with the music public List<GameObject> cubefaces; //cube faces to change material of public string CubeTag; public string FaceTag; [Tooltip("Scale objects along this axis")] public Vector3 scaleAxis = Vector3.up; // the direction we scale each object. [Tooltip("Max scale along 'scaleAxis'")] public float maxHeight = 10; // the max scale along the scaleAxis. i.e. if scaleAxis is(0,1,0), this is our maxHeight [Tooltip("How fast do we move the objects?")] public float lerp;// speed at which we scale, from currentScale to nextScale. public float minimum; public float maximum; public float timelerp; [Tooltip("Take the absolute value of samples?")] public bool absoluteVal = true; // /use absolute value of audio decibal levels [Tooltip("Sample from a recorded AudioFile?")] public bool useAudioFile = false; // flag saying if we should use a pre-recorded audio file //____________Delegates/Actions //____________Protected Variables //____________Private Variables [Header("GRID SETTINGS")] public Transform brick; public float gridX = 5f; public float gridY = 5f; public float spacing = 1f; private List<Vector3> startingScales; // the scale of each object on game start private List<Vector3> startingPositions; // the position of each object on game start /*________________Monobehaviour Methods________________*/ // Use this for initialization void Start() { StartCoroutine(NumberGen()); for (int y = 0; y < gridY; y++) { for (int x = 0; x < gridX; x++) { { var newInstance = Instantiate(brick, this.gameObject.transform); newInstance.localPosition = new Vector3(x * spacing, y * spacing, 0); } } } cubeobjects.AddRange(GameObject.FindGameObjectsWithTag(CubeTag)); cubefaces.AddRange(GameObject.FindGameObjectsWithTag(FaceTag)); //initialize starting scales and positions startingScales = new List<Vector3>(); startingPositions = new List<Vector3>(); foreach (GameObject obj in cubeobjects) { startingScales.Add(obj.transform.localScale); startingPositions.Add(obj.transform.localPosition); } } IEnumerator NumberGen() { while (true) { lerp = Random.Range(minimum, maximum); yield return new WaitForSeconds(timelerp); } } // Update is called once per frame void Update() { UpdateValueIncrease(); ScaleObjects(); ChangeMaterial(); } /*________________Public Methods________________*/ /*________________Protected Methods________________*/ /*________________Private Methods________________*/ void ChangeMaterial() { MeshRenderer my_renderer = GetComponent<MeshRenderer>(); if (my_renderer != null) { Material my_material = my_renderer.material; } for (int i = 0; i < cubefaces.Count; i++) { //Other.GetComponent<MeshRenderer>().material = my_renderer.material; cubefaces[i].GetComponent<MeshRenderer>().material = my_renderer.material; } } void ScaleObjects() { float[] audioSamples; if (frequencyRange == FrequencyRange.Decibal) { audioSamples = AudioSampler.instance.GetAudioSamples(audioIndex, cubeobjects.Count, absoluteVal, useAudioFile); } else { audioSamples = AudioSampler.instance.GetFrequencyData(audioIndex, frequencyRange, cubeobjects.Count, absoluteVal, false); } //for each object for (int i = 0; i < cubeobjects.Count; i++) { float scale = audioSamples[i] * sensitivity * AudioSampler.instance.globalSensitivity; float sampleScale = Mathf.Min(scale, 1); // % of maxHiehgt, via th audio sample float currentHeight = sampleScale * maxHeight; Vector3 desiredScale = startingScales[i] + currentHeight * new Vector3(0,0, increase);//transform.InverseTransformDirection(scaleAxis); // get desired scale, in correct direction, using audio cubeobjects[i].transform.localScale = Vector3.Lerp(cubeobjects[i].transform.localScale, desiredScale, Time.smoothDeltaTime * lerp); // lerp from current scale to desired scale //reposition the object after scaling, so that it's seemingly in the same place. float distanceScaled = (cubeobjects[i].transform.localScale - startingScales[i]).y; // get change in scale Vector3 direction = cubeobjects[i].transform.TransformDirection(scaleAxis); // get movement direction, relative to object cubeobjects[i].transform.localPosition = startingPositions[i] + distanceScaled * new Vector3(0, 0, increase); // move the object } } } }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wsdfz · Aug 07, 2019 at 03:10 AM

also has this problem when playing microphone input in real time on android platform, have you fixed this problem?

this post is about this problem: https://support.unity3d.com/hc/en-us/articles/206485253-How-do-I-get-Unity-to-playback-a-Microphone-input-in-real-time-

but no help for me.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

232 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Music between scenes. Works in editor not after building for androit? 0 Answers

How can I allow audio playback when my android app is out of focus? 1 Answer

When exporting android project to an eclipse project the music doesn't export 0 Answers

How to integrate android visualizer into unity? 1 Answer

Microphone Input Latency Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges