AudioClip.GetData returns only 0s

Hi everyone!

I’m trying to do a [GetData() on a AudioClip][1] but it only returns me 0s :frowning:
To be clear, my float tab is populated only by 0

I’m using a WAV file that said to be in Inspector : 16 Bits, 44100 Hz, Stereo, 02:57.803, 29.9 MB (WAV)

public AudioClip clip ;

void Start()
{
	myData = new float[clip.samples * clip.channels] ;
	clip.GetData(myData, 0) ;
	for (int i = 0 ; i < myData.Length ; ++i)
	{
		Debug.Log(i+"  -> "+myData*.ToString()) ;	*
  • } *
    }
    Can you please help me ?

[1]: Unity - Scripting API: AudioClip.GetData

Hi baz,

Your code should work. Check your clip’s import settings. If it’s a 3d clip, no need for it to be stereo. Load type should be load into memory.

Also, check your data’s length (Debug myData.length). Then, to check all these floats and make sure they are not all null, don’t debug all of them! That’s 441002177 Debug.Log calls, ouch! Instead, use a bool allFloatsAreZero variable in the loop, will prevent crashes.

Let me know!

Gregzo

Im also having problems with GetData…
It works fine in the editor on PC…
Wont work in the build…

I see 5.4 beta seems to address GetData not working in START() but ive tested on other threads and no luck. Using oGG

maybe,it is because that the file you import into clip is compressed file.
you can try some file of wav format,you can GetDate easily,but if you import mp3 or some else compressed file,you can not get the value of samples through GetData.