Help with constantly updating panning values!

Godot Version

v4.2.2.stable.official [15073afe3]

Question

Hey there, this is my first post on this forum. I have a simple project where I want to get the accelerometer values from a device, and control the panning effect of the audio according to the tilt of the device. The code which I currently have works brilliantly, but there are popping noises whenever the panning value is updated. Take a look:

extends Control

var x = 0.0
var y = 0.0
var z = 0.0
var coefficient = 0.35 #smoothing for accelerometer values

@onready var my_label = $Label #to print the accelerometer values for debug
var effect = AudioServer.get_bus_effect(0, 0)

func _process(_delta):
	
	var reading = Input.get_accelerometer()
	x = x + coefficient * (reading.x - x)
	y = y + coefficient * (reading.y - y)
	z = z + coefficient * (reading.z - z)
	
	var target_pan = clamp(y, -0.75, 0.75)
	effect.pan = target_pan #this works as intended, panning the audio. But there are popping noises
	
	my_label.text = "X: " + str(x) + "\nY: " + str(y) + "\nZ: " + str(z) + "\nClamp Y: " + str(target_pan) #printing values for debug purposes
	
func _on_button_pressed():
	$sound.play()

func _on_button_2_pressed():
	$sound.stop()

I have tried smoothing the pan transition with lerp and move_towards, but nothing seems to work. The audio popping noise remains. Furthermore, the audio I’m playing isn’t a very large file. It’s a small MP3.
Thanks!

1 Like

I am not an audio guy, but I did notice they added some audio features in 4.3. Do any of those new features help your issue? Do you have the same issue with the same code in 4.3?

No, unfortunately the new features do not help with panning. Will look into them for simultaneous playback of audio streams.

1 Like

I’m also not an audio guy either. I’ve experienced a few audio problems of my own though (e.g. unusable reverb filter) and the audio system does appear to need an overall improvement.

Here’s the tracker for Godot on all confirmed audio issues:

1 Like

Does the issue still exist in 4.3?

It is possible it is a bug and you got lucky and they fixed it already.

If not, have you searched open issues on the github repo to see if this is a known issue and if it has work arounds already?