Search Unity

How to understand GetSpectrumData?

Discussion in 'Scripting' started by like_a_boss, Jan 27, 2015.

?

how to understand GetSpectrumData

  1. you can not understand it

    4 vote(s)
    100.0%
  2. its pretty easy

    0 vote(s)
    0.0%
  1. like_a_boss

    like_a_boss

    Joined:
    Jan 17, 2015
    Posts:
    15
    Code (JavaScript):
    1. var spectrum :float[]=AudioListener.GetSpectrumData(1024,0,FFTWindow.Hamming);
    2.  
    3.  
    4. var c1:float=spectrum[1]+spectrum[1]+spectrum[1];
    5. var c2:float=spectrum[3]+spectrum[3]+spectrum[3];
    Hello,Could sombody explain what it above means? How to read it?
    if i get it right there is 0-1024 units of something which reprezents 0-22000Hz
    And now: if 22000Hz / 1024 then spectrum[1] = around 21Hz Frequency of sound

    so------var c1 has 1+1+1=3 then it is around 3 x 21=63Hz
    1.but what is exactly that "c1" is it a number from 0-63Hz taken when such freq is heard by lisner ? or maybe something else

    2.what if for exp somebody wants to get numbers between 10 000hz-22000hz
    3. Why var c1:float=spectrum[1]+spectrum[1]+spectrum[1]; is not =var c1:float=spectrum[3]
    and why is it in parts?
     
    Last edited: Jan 27, 2015
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    the spectrum array repesents powers of various frequency bands
    spectrum[1] is the power of a certain band
    spectrum[2] is the power of a higher band, spectrum[3] for a further higher band, etc
    each band covers a multiple of the fundamental frequency of the interval used.
    spectrum[1] +spectrum[1] +spectrum[1] is just 3 times the power of band 1 (whoever wrote this example was dumb, i've seen it before) you can just write spectrum[1]*3
     
  3. like_a_boss

    like_a_boss

    Joined:
    Jan 17, 2015
    Posts:
    15
    so GetSpectrumData is like a cake of freq sliced in pieces (in this exp 1024) and evrey piece holds some range of frequencys? but these slices are not equly big
    is it mean that?
    spectrum[10] =10*10=100; since 1=around 21hz then 100units is around= 2100Hz then spectrum data takes the value of avarage amplituede of the slice that this 2100Hz is within >and as music is changing so the amplituedes of that 2100Hz.. Is it more correct? or still i didt get it