I recorded a video explaining my issue. Here's the YouTube link:
Summary:
I have a SpectrumAnalyzer effect that detects when a person on the phone is speaking. I check to see if the SpectrumAnalyzer.get_magnitude_for_frequency_range() is above a certain threshold and change the avatar sprite to look like it's talking. The issue is that even when there's no sound passing though the bus with the SpectrumAnalyzer effect, there's this loop of return values that shows up in a cycle. It will return (0,0) for about a second or two, then cycle through some non-zero values, then go back to zero. Please see the video for more detail.
The code is below.
extends "res://Scenes/TextPopup.gd"
export(NodePath) var TitleLabel
onready var SpeakerSprite = $NarratorParentNode/SpeakerSprite
var Speaker = "Anita"
var Anim = "Blink"
export var Debug = true
func _ready():
SpectrumAnalyzer = AudioServer.get_bus_effect_instance(5, 3)
hide()
Set_Speaker_Sprite("None", "None")
# if Debug:
# Toggle_Visible(true)
func _process(delta):
if visible:
if Speaker == "Anita":
var m = SpectrumAnalyzer.get_magnitude_for_frequency_range(165, 255)
if m.x > 0.00003:
if SpeakerSprite.animation != "AnitaSpeak":
SpeakerSprite.animation = "AnitaSpeak"
else:
if SpeakerSprite.animation != "AnitaBlink":
SpeakerSprite.animation = "AnitaBlink"
print(m)