public override void _Ready() { GetNode <WorldEnvironment>("sky").Environment.BackgroundColor = new Color(Lib.Node.BackgroundColorHtmlCode); GetNode <WorldEnvironment>("sky").Environment.GlowEnabled = true; GetNode <WorldEnvironment>("sky").Environment.GlowIntensity = 0.8f; GetNode <WorldEnvironment>("sky").Environment.GlowStrength = 1f; GetNode <WorldEnvironment>("sky").Environment.GlowBicubicUpscale = true; InitSound(); AddChild(Audio); spectrumEffect = (AudioEffectSpectrumAnalyzerInstance)AudioServer.GetBusEffectInstance(AudioServer.GetBusIndex("Record"), 0); recordEffect = (AudioEffectRecord)AudioServer.GetBusEffect(AudioServer.GetBusIndex("Record"), 1); var recordNode = new AudioStreamPlayer() { Autoplay = true, Stream = new AudioStreamMicrophone(), Bus = "Record" }; AddChild(recordNode); for (int i = 0; i < 16; i++) { var ring = GetNode("Woofer").GetNode <MeshInstance>("Ring" + i); ring.MaterialOverride = new SpatialMaterial() { AlbedoColor = Color.FromHsv(i * 22f / 360, 1, 1), EmissionEnabled = true, Emission = Color.FromHsv(i * 22f / 360, 1, 1) }; } }
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 )); }