-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


Unity

, 20 2017 . 14:42 +
zarytskiy 14:42

Unity

  • Tutorial
Unity . , , , .

. , .

:


, . (). .



, ( . ).

. .

, ,

. GetSpectrumData()


Unity GetSpectrumData(), . :

AudioSource.GetSpectrumData(float samples, int channel, FFTWindow window)

samples float, . (64 , 8192 )

channel , . 0

FFTWindow . . (Blackman) , . (Triangle) ,



512, - . 0, FFTWindow FFTWindow.Blackman

512 , .

source.GetSpectrumData(spectrum, 0, FFTWindow.Blackman);

maxScale, . , , .



, , . , . 512 , .. . , . , , , . ( )

:

private void makeFreqBands()
    {
        int count = 0;

        for (int i = 1; i <= 8; i++)
        {
            float avg = 0;
            int sampleCount = (int)Mathf.Pow(2, i);

            if (i == 8)
                sampleCount += 2;

            for(int j = 0; j < sampleCount; j++)
            {
                avg += spectrum;
                count++;
            }

            avg /= count;
            bands = avg * 10;
        }
    }

, . , , . . 8 ( 8, - , , ), .
2 ^ i+1 . .. 512 , ( 40-41 . 510 ). - , .

8-




, . ( update !). , .

void ProcBandBuffer()
    {
        for(int i = 0; i < 8; i++)
        {
            if(bands > bufferBands)
            {
                bufferBands = bands;
                bufferDecrease = 0.00005f;
            }

            if (bands < bufferBands)
            {
                bufferBands -= bufferDecrease;
                bufferDecrease = 1.2f;
            }
        }
    }

. . , . , , . , . .

. . .

(.. ). .. , .

void mapBufferedBands()
    {
        for (int i = 0; i < 8; i++)
        {
            if (bufferBands[i] > heighesBufferBand[i])
                heighesBufferBand[i] = bufferBands[i];

            rangedBufferBand[i] = bufferBands[i] / heighesBufferBand[i];
        }
    }

, , , float ( - !)

, 8 8. .. . !

19:30 Unity , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/338334/

:  

: [1] []
 

:
: 

: ( )

:

  URL