Exemplo n.º 1
0
    private void Update()
    {
        var peak = Lasp.AudioInput.GetPeakLevelDecibel(FilterType);
        var rms  = Lasp.AudioInput.CalculateRMSDecibel(FilterType);

        Lasp.AudioInput.RetrieveWaveform(FilterType, MusicState.Wavelength);
        MusicState.Peak = Mathf.Clamp01(1 - peak / Silence);
        MusicState.RMS  = Mathf.Clamp01(1 - rms / Silence);

        if (WavelengthTexture == null || WavelengthTexture.width != MusicState.Wavelength.Length)
        {
            WavelengthTexture = new Texture2D(2, MusicState.Wavelength.Length);
        }
        if (DeltaTexture == null || DeltaTexture.width != MusicState.Wavelength.Length)
        {
            DeltaTexture = new Texture2D(2, MusicState.Wavelength.Length);
        }

        var min = MusicState.Wavelength.Min();

        _min.AddValue(min);

        var max = MusicState.Wavelength.Max();

        _max.AddValue(max);

        var step = (max - min) / 1000f;

        for (var i = 0; i < MusicState.Wavelength.Length; ++i)
        {
            var f = (MusicState.Wavelength[i] - min) / (max - min);
            var e = WavelengthTexture.GetPixel(0, i).grayscale;

            var v = Mathf.MoveTowards(f, e, step);

            DeltaTexture.SetPixel(0, i, new Color(e, e, e, 1));
            DeltaTexture.SetPixel(1, i, new Color(e, e, e, 1));

            WavelengthTexture.SetPixel(0, i, new Color(f, f, f, 1));
            WavelengthTexture.SetPixel(1, i, new Color(f, f, f, 1));
        }

        WavelengthTexture.Apply();
        DeltaTexture.Apply();
        Shader.SetGlobalTexture("_Wavelength", WavelengthTexture);
        Shader.SetGlobalTexture("_Delta", WavelengthTexture);

        for (var i = _listeners.Count - 1; i >= 0; --i)
        {
            if (_listeners[i] == null)
            {
                _listeners.RemoveAt(i);
                continue;
            }
            _listeners[i].Tick();
        }
    }
Exemplo n.º 2
0
    public void Listen(SmartValue value)
    {
        var strength = 0f;

        _timer += Time.deltaTime;

        var frac = Mathf.Clamp01(Mathfx.Frac((_timer / 60) * BPM));

        strength = PulseShape.Evaluate(frac);

        value.AddValue(strength);
    }
Exemplo n.º 3
0
    void Update()
    {
        var ms = MusicManager.MusicState;

        _rms.AddValue(ms.RMS);
        _peak.AddValue(ms.Peak);
        RMS.value  = _rms.GetValue();
        Peak.value = _peak.GetValue();

        var p       = LineRenderer.Points;
        var pLength = ms.Wavelength.Length / STEP;

        if (p == null || p.Length != pLength)
        {
            p = new Vector2[pLength];
        }
        int pCounter = 0;

        for (var i = 0; i < ms.Wavelength.Length; i += STEP)
        {
            if (pCounter >= p.Length)
            {
                break;
            }
            var w = ms.Wavelength[i];
            if (w < _wMin)
            {
                _wMin = w;
            }
            if (w > _wMax)
            {
                _wMax = w;
            }
            var x = i / (float)ms.Wavelength.Length;
            var y = (w - _wMin) / (_wMax - _wMin);
            p[pCounter] = new Vector2(x, y);
            pCounter++;
        }
        LineRenderer.Points = p;
        LineRenderer.SetAllDirty();
    }
Exemplo n.º 4
0
 public void Listen(SmartValue value)
 {
     value.AddValue(MusicManager.MusicState.Peak);
 }
Exemplo n.º 5
0
 public void Listen(SmartValue value)
 {
     value.AddValue(Value);
 }
Exemplo n.º 6
0
 public void Listen(SmartValue value)
 {
     value.AddValue(Levels.GetSumUnderWavelength(MusicManager.MusicState.Wavelength));
 }
Exemplo n.º 7
0
    protected override void TickInternal(float strength)
    {
        Debug.Log(System.textureSheetAnimation);

        System.maxParticles = Rows * Columns;
        Vector2 realSize = SizeMultiplier * Size;
        float   maxDist  = Mathf.Sqrt(Rows * realSize.x * Columns * realSize.y);

        while (_buffer.Count > BufferSize)
        {
            _buffer.RemoveAt(0);
        }
        float alpha = Mathf.Clamp01(strength) * AlphaBoost;

        AlphaValue.AddValue(alpha);
        alpha = AlphaValue.GetValue();
        if (Exponential)
        {
            strength *= strength;
        }
        strength *= ValueMultiplier;
        _buffer.Add(strength);

        if (_particles == null || _particles.Length != System.main.maxParticles)
        {
            _particles = new ParticleSystem.Particle[System.main.maxParticles];
        }
        int numParticlesAlive = System.GetParticles(_particles);


        Vector2 min           = transform.position.xz() - realSize / 2;
        Vector2 step          = new Vector3(realSize.x / (Rows - 1), realSize.y / (Columns - 1));
        int     rowCounter    = 0;
        int     columnCounter = 0;

        for (int i = 0; i < numParticlesAlive; i++)
        {
            var   newParticlePos = new Vector2(min.x, min.y) + new Vector2(step.x * rowCounter, step.y * columnCounter);
            float distance       = Vector2.Distance(FocalPoint.transform.position.xz(), newParticlePos);
            distance = Mathf.Clamp01(distance / maxDist);
            int index = _buffer.Count - 1 - Mathf.FloorToInt(distance * _buffer.Count);
            index = Mathf.Clamp(index, 0, _buffer.Count - 1);
            if (index > _buffer.Count)
            {
                _particles[i].position = new Vector3(newParticlePos.x, 0, newParticlePos.y);
            }
            else
            {
                _particles[i].position = new Vector3(newParticlePos.x, _buffer[index], newParticlePos.y);
            }
            _particles[i].startColor = TemplateManager.GetTemplateAtTime(distance * ColorFrequency).Color0.WithAlpha(alpha);

            rowCounter++;
            if (rowCounter == Rows)
            {
                rowCounter = 0;
                columnCounter++;
            }
        }

        System.SetParticles(_particles, numParticlesAlive);
    }