asingcrow/godot/Components/MicMeterHoriz.gd

20 lines
580 B
GDScript3

extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var spectrum_record
# Called when the node enters the scene tree for the first time.
func _ready():
var idx = AudioServer.get_bus_index("Record")
spectrum_record = AudioServer.get_bus_effect_instance(1,1)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var magnitude = spectrum_record.get_magnitude_for_frequency_range(0,11050.0).length()
var energy = clamp((60 + linear2db(magnitude)) / 60, 0, 1)
$RecordMeter.value = energy * 100