コード例 #1
0
    void Update()
    {
        // 基本周波数の取得
        float freq = SoundAnalyzer.GetFundamentalFrequency(mic);

        // マイク秒数の取得
        int now = (int)(mic.time * 100.0f);

        // 基本周波数の描画
        int vertexCount       = now % NumTimes;
        int beforeVertexCount = beforeTime % NumTimes;

        if (vertexCount < beforeVertexCount)
        {
            // 表示がループした時は、頂点0から描画を開始
            beforeVertexCount = 0;
        }
        lineRenderer.SetVertexCount(vertexCount);
        for (int i = beforeVertexCount; i < vertexCount; i++)
        {
            float x = PositionTime + i * RateTime / NumTimes;
            float y = PositionHertz + freq * RateHertz / (AudioSettings.outputSampleRate / 2.0f);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        beforeTime = now;
    }
コード例 #2
0
    void Update()
    {
        List <KeyValuePair <float, float> > spectrum = SoundAnalyzer.GetSpectrumData(file);

        // 対数振幅スペクトルの描画
        lineRenderer.SetVertexCount(spectrum.Count);
        for (int i = 0; i < spectrum.Count; i++)
        {
            float x = PositionHertz + i * RateHertz / spectrum.Count;
            float y = PositionPower + RatePower * (float)Math.Log(spectrum[i].Value + 1.0);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        Debug.Log(SoundAnalyzer.GetFundamentalFrequency(file));
    }
コード例 #3
0
    void Update()
    {
        // 対数振幅スペクトルの描画
        List <KeyValuePair <float, float> > spectrum = SoundAnalyzer.GetSpectrumData(mic);
        LineRenderer FFTRenderer = FFTObject.GetComponent <LineRenderer>();

        FFTRenderer.SetVertexCount(spectrum.Count);
        for (int i = 0; i < spectrum.Count; i++)
        {
            float x = PositionTime + i * RateFFTHertz / spectrum.Count;
            float y = PositionHertz + RateFFTPower * (float)Math.Log(spectrum[i].Value + 1.0);
            FFTRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        // 基本周波数の取得
        float freq = SoundAnalyzer.GetFundamentalFrequency(mic);

        // マイク秒数の取得
        int now = (int)(mic.time * 100.0f);

        // 基本周波数の描画
        int vertexCount       = now % NumTimes;
        int beforeVertexCount = beforeTime % NumTimes;

        if (vertexCount < beforeVertexCount)
        {
            // 表示がループした時は、頂点0から描画を開始
            beforeVertexCount = 0;
        }
        lineRenderer.SetVertexCount(vertexCount);
        for (int i = beforeVertexCount; i < vertexCount; i++)
        {
            float x = PositionTime + i * RateTime / NumTimes;
            float y = PositionHertz + freq * RateHertz / (AudioSettings.outputSampleRate / 2.0f);
            lineRenderer.SetPosition(i, mainCamera.ViewportToWorldPoint(new Vector3(x, y, mainCamera.nearClipPlane)));
        }

        beforeTime = now;
    }