Ejemplo n.º 1
0
    public void UpdateJellifier(ref double[] fftOutput)
    {
        int batchSize = fftOutput.Length / _binRange.Length;

        double[] bins = null;
        AudioAnalyzer.BinFFTOutput(ref fftOutput, ref bins, _binRange, sampleRate);

        for (int i = 0; i < _toManipulate.vertexCount - 1; ++i)
        {
            for (; i % batchSize < batchSize && i < _toManipulate.vertexCount; ++i)
            {
                float distToBe = (float)((bins[i / batchSize] / (float)fftOutput.Length));
                distToBe  = Mathf.Clamp(distToBe, 0.01f, float.MaxValue);
                distToBe += 0.5f;
                Vector3 currentDist = verts [i];
                if (currentDist.magnitude != distToBe)
                {
                    verts [i]  = Vector3.Lerp(Vector3.zero, currentDist.normalized, distToBe);
                    colors [i] = Color.Lerp(Color.green * 0.6f, Color.red * 2, distToBe - 0.5f);
                }
            }
        }
        _toManipulate.colors   = colors;
        _toManipulate.vertices = verts;

        Vector3 rot = _filter.gameObject.transform.rotation.eulerAngles;

        rot.y += Time.deltaTime * 20;
        _filter.gameObject.transform.rotation = Quaternion.Euler(rot);
        float normalizedBassEnergy = Mathf.Clamp01((float)(bins [0] * 0.75f + bins [1] * 0.25f) / fftOutput.Length);

        _skyboxMat.SetColor("_SkyTint", Color.Lerp(Color.yellow, Color.red * 1.5f, normalizedBassEnergy));
        _skyboxMat.SetColor("_GroundColor", Color.Lerp(Color.green * 0.25f, Color.blue * 0.25f, normalizedBassEnergy));
        _skyboxMat.SetFloat("_Exposure", Mathf.Clamp(normalizedBassEnergy, 0.25f, 1.0f));
    }
Ejemplo n.º 2
0
 private void Update()
 {
     for (int i = 0; i < _barCounts.Length; ++i)
     {
         _barCounts[i] -= _barCountDecayRate;
     }
     System.Array.Clear(bins, 0, bins.Length);
     AudioAnalyzer.BinFFTOutput(ref _freqData, ref bins, _binRange, _sampleBand);         //new double[_binRange.Length];
     guiCallsAllowed = 2;
 }