Beispiel #1
0
    public Color MusicToRGB()
    {
        spectrum = (AudioEffectSpectrumAnalyzerInstance)AudioServer.GetBusEffectInstance(0, 0);
        high     = RangeLerp(GD.Linear2Db(spectrum.GetMagnitudeForFrequencyRange(5000, 20000, AudioEffectSpectrumAnalyzerInstance.MagnitudeMode.Average).Length()), bottomDb, 20, 0, 255);
        mid      = RangeLerp(GD.Linear2Db(spectrum.GetMagnitudeForFrequencyRange(500, 5000, AudioEffectSpectrumAnalyzerInstance.MagnitudeMode.Average).Length()), bottomDb, 20, 0, 255);
        low      = RangeLerp(GD.Linear2Db(spectrum.GetMagnitudeForFrequencyRange(10, 200, AudioEffectSpectrumAnalyzerInstance.MagnitudeMode.Average).Length()), bottomDb, 20, 0, 255);

        return(Color.Color8
               (
                   (byte)high,
                   (byte)mid,
                   (byte)low,
                   255
               ));
    }
Beispiel #2
0
    public override void _Process(float delta)
    {
        float maxFreq = 11050;
        int   minDbl  = 60;
        int   segs    = 16;
        float prevHz  = 0;

        for (int i = 0; i < segs; i++)
        {
            var hz   = i * maxFreq / segs;
            var mag  = spectrumEffect.GetMagnitudeForFrequencyRange(prevHz, hz);
            var nrg  = Mathf.Clamp((minDbl + GD.Linear2Db(mag.Length())) / minDbl, 0, 1);
            var ring = GetNode("Woofer").GetNode <MeshInstance>("Ring" + i);
            ring.Scale = new Vector3(ring.Scale.x, nrg * 20 + 1, ring.Scale.z);
            ((SpatialMaterial)ring.MaterialOverride).EmissionEnergy = nrg;
            prevHz = hz;
        }
    }