Search Unity

Getting Audio Data in Unity 5

Discussion in 'Audio & Video' started by slidon403, Jul 7, 2015.

  1. slidon403

    slidon403

    Joined:
    Sep 5, 2014
    Posts:
    2
    Hi,

    I am trying to create a Unity audio visualization. There are a few threads on this but most are a few years old and use now obsolete methods so I thought I would bring it up again.

    What is the best way to extract audio data (such as decibel levels of different frequency bands). Most of the audio analyzing functions in the scripting api are now obsolete (such as GetSpectrumData) so I am unsure as were to start.

    Ideally I would like to get data as the audio is playing, e.g so I can stick my visualization in the Update function but it's possible there is another way of doing it.

    Thanks in advance
     
  2. HelloMeow

    HelloMeow

    Joined:
    May 11, 2014
    Posts:
    281
    GetSpectrumData should do what you want, but according to the docs you should use this one, where you give it a pre allocated array.

    GetSpectrumData(samples: float[], channel: int, window: FFTWindow)

    So for example:
    Code (csharp):
    1.  
    2. float[] spectrum = new float[1024];
    3.  
    4. audioSource.GetSpectrumData(spectrum, 0, FFTWindow.Hanning)
    5.