class_name BeamSFX extends AudioStreamPlayer3D
## Audio player that pitches up each frame `activate` is called, and pitches down any other time.

const MAX_PITCH := 1.0
const MIN_PITCH := 0.001

@export var pitch_increment := 3.236
@export var pitch_decrement := 1.618

var _active_this_frame := false


func activate() -> void:
	_active_this_frame = true
	if not playing:
		playing = true


func _process(delta: float) -> void:
	if not playing:
		return

	if _active_this_frame:
		pitch_scale = min(MAX_PITCH, pitch_scale + pitch_increment * delta)
	else:
		pitch_scale = max(MIN_PITCH, pitch_scale - pitch_decrement * delta)
		if pitch_scale <= MIN_PITCH:
			playing = false

	_active_this_frame = false
