Пример #1
0
    void Start()
    {
        AudioSource mAudio     = GetComponent <AudioSource>();
        int         clipLength = mAudio.clip.samples * mAudio.clip.channels;

        float[] clipData = new float[clipLength];
        mAudio.clip.GetData(clipData, 0);
        int length = mAudio.clip.samples / bufferSize;

        Debug.Log(length);
        float[] dataL  = new float[length];
        float[] dataR  = new float[length];
        float[] buffer = new float[bufferSize * mAudio.clip.channels];
        for (int i = 0; i < length; i++)
        {
            // fill buffer
            for (int j = 0; j < bufferSize * mAudio.clip.channels; j++)
            {
                buffer[j] = clipData[i * bufferSize * mAudio.clip.channels + j];
            }
            Analyse(buffer, mAudio.clip.channels);
            dataL[i] = sValueL;
            dataR[i] = sValueR;
        }

        graphL.Redraw(dataL, .04f);
        graphR.Redraw(dataR, .04f);
    }