AudioSource.GetOutputData(); produces 0 values

As the title says, I’m creating a music visualiser and would like to read in the amplitude values of the audiosource however I’m only getting 0s out

I’m using AudioSource.GetSpectrumData(); and it is producing good values.

Here is my code :

using UnityEngine;
using System.Collections;

public class SamplerScript : MonoBehaviour 
{
	//Public Variables
	public int sampleNum;
    public int channel;
	public AudioSource audioSource;
	//Private Variables
	private float[] volume;
	private float[] frequency;
	//Temp Variables
    bool dataCollected = false;
    bool dataShown = false;

	// Use this for initialization
	void Start () 
	{
        //Set Up Arrays
		volume = new float[sampleNum];
		frequency = new float[sampleNum];
	}
	
	// Update is called once per frame
	void Update () 
	{
        if (dataCollected == false)
        {
            //Get Volume Data
            audioSource.GetOutputData(volume, channel);
            //Get Frequency Data
            audioSource.GetSpectrumData(frequency, channel, FFTWindow.Rectangular);
            dataCollected = true;
        }

        if (dataShown == false)
        {
            print("Volume Values");
            for (int i = 0; i < sampleNum; i++)
            {
                print(volume*);*

}

print(“Frequency Values”);
for (int i = 0; i < sampleNum; i++)
{
print(frequency*);*
}

dataShown = true;
}
* }*
}

My sample length is too short, there is no sound at the point where my sample is taken :slight_smile:

To fix this I just removed the booleans and let the Update show values every frame, eventually I had values.