- Home /
AudioClip.GetData returns only 0s
Hi everyone!
I'm trying to do a GetData() on a AudioClip but it only returns me 0s :( 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[i].ToString()) ;
}
}
Can you please help me ?
Did you ever solve this problem? I'm having the same issue. I've found several people having the same issue but never a solution.
If said audioclip is retrieved using WWW.GetAudioClip, there's nothing to do: the bug has been around since 3.5 beta, and apparently s solved in 4.0 (see my Audio Bugs thread in the forums).
If it is just a wav you imported in your project, then you are buggy, not Unity. Or you discovered a new, unknown to me, species of audio bug : would be a nice addition to my thread, post details.
Let me know,
Gregzo
http://forum.unity3d.com/threads/147834-A-list-of-audio-bugs-(iOS-mostly)
gregzo is right, if you use WWW.GetAudioClip, there is no solution except buying Unity 4. For the normal file, the first one was returning me only 0s. I changed file to test and with another .wav it did worked! ;)
Answer by gregzo · Sep 28, 2012 at 05:50 PM
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 44100*2*177 Debug.Log calls, ouch! Instead, use a bool allFloatsAreZero variable in the loop, will prevent crashes.
Let me know!
Gregzo
Answer by ceo1207 · May 09, 2016 at 05:01 PM
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.
Answer by SharkmanSam · May 30, 2016 at 05:22 AM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613081611im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a way to create a random Audiosource loop? 2 Answers
"Cannot get/set data from streamed sample" from audioclip 1 Answer
Is OnAudioFilterRead Still the Preferred Method for Procedural Audio? 0 Answers
Synch clips with BPM 2 Answers
how to make multiple sound augmented reality in 1 scene UNITY? 0 Answers