SpectrumAnalyzer returns a value when there's no sound playing through bus
Asked Answered
L

1

0

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)
Leftwards answered 24/1, 2023 at 14:54 Comment(0)
L
0

I "solved" it, but I'm not sure why it worked. I turned down the spectrum analyzer buffer length to the minimum value, and the glitch has gone away. Just posting this in case someone else has a similar issue.

Leftwards answered 24/1, 2023 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.