Пример #1
0
 void Update()
 {
     float[] s = JAudioAnalysis.Instance().spectrum;
     for (int i = 0; i < s.Length; i++)
     {
         int sample_idx = i / m_sampleStep;
         m_sampleSpectrum[sample_idx] = m_sampleSpectrumSmoother[sample_idx].AddData(s[i]);
     }
 }
Пример #2
0
 // Update is called once per frame
 void Update()
 {
     float[] m_spectrum = JAudioAnalysis.Instance().spectrum;
     // Analysis 2: 将所有频率在时间上平滑,分析曲线在时间上的突变
     for (int i = 0; i < m_spectrum.Length; i++)
     {
         m_spikeSpectrum[i] = m_spectrumSmoother[i].AddData(m_spectrum[i]);
     }
 }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        float[] s = JAudioAnalysis.Instance().spectrum;
        m_audioSpectrumCache.AddData(s, Time.fixedTime - m_startCacheSpectrumTime);

        if (Time.time < 11.0f)
        {
            return;
        }

        DrawByLine();
    }
    void Update()
    {
        // 获取曲线
        AudioListener.GetSpectrumData(m_spectrum, 0, FFTWindow.Rectangular);
        float[] s = JAudioAnalysis.Instance().spectrum;
        for (int i = 0; i < s.Length; i++)
        {
            m_ampMin = Mathf.Min(m_ampMin, s[i]);
            m_ampMax = Mathf.Max(m_ampMax, s[i]);
        }

        //DebugDrawSpectrumColor();
    }
    // Update is called once per frame
    void Update()
    {
        // Analysis 1: 计算曲线在不同频率上的最大值
        float count_all = 0;

        float[] s = JAudioAnalysis.Instance().spectrum;
        for (int i = 0; i < s.Length; i++)
        {
            count_all += s[i];
        }
        count_all /= JAudioAnalysis.spectrumSize;
        m_amp      = m_ampSmoother.AddData(1 - Mathf.Clamp((count_all - JAudioAnalysis.Instance().ampMin) / (JAudioAnalysis.Instance().ampMax - JAudioAnalysis.Instance().ampMin), 0, 1));
    }
Пример #6
0
    void FormTexture()
    {
        int   m_spectrumSize = JAudioAnalysis.spectrumSize;
        float m_ampMin       = JAudioAnalysis.Instance().ampMin;
        float m_ampMax       = JAudioAnalysis.Instance().ampMax;


        Color[] color_buf = new Color[width * draw_step];

        int   last_draw_x      = -1;
        float all_pixel_width  = Mathf.Log(m_spectrumSize);
        float each_pixel_width = all_pixel_width / width;

        for (int x = 0; x < m_spectrumSize; ++x)
        {
            int draw_x = (int)(Mathf.Log(x + 1) / all_pixel_width * width);
            if (draw_x == last_draw_x)
            {
                continue;
            }
            if (draw_x >= width)
            {
                break;
            }

            float amp   = JAudioAnalysis.Instance().spectrum[x];
            float ratio = (amp - m_ampMin) / Mathf.Max(1, m_ampMax - m_ampMin) * 5;
            for (int step_y = 0; step_y < draw_step; ++step_y)
            {
                for (int step_x = last_draw_x < 0 ? 0 : last_draw_x; step_x <= draw_x; ++step_x)
                {
                    color_buf[step_x + (step_y * width)] = new Color(ratio, 0, 0, 1);
                }
            }

            last_draw_x = draw_x;
        }
        m_texture.SetPixels(0, cur_draw_height, width, draw_step, color_buf);
        m_texture.Apply();
        cur_draw_height = (cur_draw_height + draw_step) % height;
    }
Пример #7
0
    void DrawByLine()
    {
        float last_draw_x = -1;

        for (int x = 0; x < JAudioAnalysis.spectrumSize; ++x)
        {
            if (Mathf.Log(x + 1) - last_draw_x < 1.0f / Screen.width * 2)
            {
                continue;
            }

            for (int y = 0; y < m_audioSpectrumCache.size; ++y)
            {
                float amp   = m_audioSpectrumCache.spectrumCache[y, x];
                float ratio = (amp - JAudioAnalysis.Instance().ampMin) / Mathf.Max(1, JAudioAnalysis.Instance().ampMax - JAudioAnalysis.Instance().ampMin) * 5;
                Color c     = new Color(ratio, 0, 0, 1);
                Debug.DrawLine(new Vector3(Mathf.Log(x + 1), y * 10.0f / m_audioSpectrumCache.size - 5, -1),
                               new Vector3(Mathf.Log(x + 1), (y + 1) * 10.0f / m_audioSpectrumCache.size - 5, -1),
                               c);
                last_draw_x = Mathf.Log(x + 1);
            }
        }
    }
    void FormatWholeTexture()
    {
        WAudioAnalysis.AudioSpectrumDataCache m_audioSpectrumCache = JAudioAnalysis_offlineSpectrum.Instance().m_audioSpectrumCache;
        int   m_spectrumSize = JAudioAnalysis.spectrumSize;
        float m_ampMin       = JAudioAnalysis.Instance().ampMin;
        float m_ampMax       = JAudioAnalysis.Instance().ampMax;

        int   last_draw_x      = -1;
        float all_pixel_width  = Mathf.Log(m_spectrumSize);
        float each_pixel_width = all_pixel_width / width;

        for (int x = 0; x < m_spectrumSize; ++x)
        {
            int draw_x = (int)(Mathf.Log(x + 1) / all_pixel_width * width);
            if (draw_x == last_draw_x)
            {
                continue;
            }
            if (draw_x >= width)
            {
                break;
            }
            for (int y = 0; y < m_audioSpectrumCache.size && y < height; ++y)
            {
                float amp   = m_audioSpectrumCache.spectrumCache[y, x];
                float ratio = (amp - m_ampMin) / Mathf.Max(1, m_ampMax - m_ampMin) * 5;
                Color c     = new Color(ratio, 0, 0, 1);
                for (int step_x = last_draw_x < 0 ? 0 : last_draw_x; step_x <= draw_x; ++step_x)
                {
                    m_texture.SetPixel(step_x, y, c);
                }
            }
            last_draw_x = draw_x;
        }
        m_texture.Apply();
    }
 private void Awake()
 {
     GetComponent <AudioSource>().Play();
     m_instance = this;
 }