it does not do what it's supposed to for some reason when easy_audio is turned off it sounds like it plays the audio 212 times, or with wrong effect parameters. but atleast now it doesnt crash
102 lines
5.2 KiB
GDScript
102 lines
5.2 KiB
GDScript
class_name ChangableAudioStreamPlayer3D extends AudioStreamPlayer3D
|
|
## If enabled, it will default to an [color=#f00] AudioStreamPlayer3D [/color] [br]
|
|
## If disabled, it will use [color=#ff0]SpatialAudio3D [/color]
|
|
@export var easy_audio: bool = true:
|
|
set(value):
|
|
easy_audio = value
|
|
if value:
|
|
set_to_easy_audio()
|
|
else:
|
|
set_to_raytraced_audio()
|
|
|
|
@export_group("SpatialAudio3D properties")
|
|
@export_subgroup("Sound Properties")
|
|
@export var reverb_enabled: bool = true ## Enable reverb-effects with all its computations.[br][br]Disable if you just need it for occlusion detection, for example fading ambient rain when entering a house.
|
|
@export_range(-81, +80, 3.0, "suffix:dB") var reverb_volume_db: float = -6 ## Maximum volume of the reverbs.
|
|
@export_range(-1, 5, 0.05, "or_greater", "suffix:s") var reverb_fadeintime: float = 2.0 ## Fade-in time when a reverb is added at a wall.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position. In a large area, when the raycast suddenly hits a close wall, the sudden appearing reverb can sound unnatural.[br][br]Set to -1 for dynamic fade time (based on wetness).
|
|
@export_range(-1, 8, 0.05, "or_greater", "suffix:s") var reverb_fadeouttime: float = 2.0 ## Fade-out time when a reverb is removed.[br][br]The default of 2s is a good value where changes in environment merge well into the overall sound mix.[br]If you have small areas with little changes of distances, set this value to low (0.2s) so that repositioned reverbs don't get stuck for too long in a position.[br][br]Set to -1 for dynamic fade time (based on wetness).
|
|
@export_range(1, 20_000, 0.1, "suffix:Hz") var occlusion_lp_cutoff: int = 600 ## Frequency when soundsource is occluded behind walls.
|
|
@export_range(0, 5, 0.05, "or_greater", "suffix:s") var occlusion_fadetime: float = 0.5 ## Fadetime when occlusion changes.
|
|
@export_range(0, 100, 0.1, "or_greater", "suffix:m") var bass_proximity: int = 50 ## The closer you are to a wall, the more bass you will hear.[br][br]The effect starts at this value (distance to the wall).[br][br]0 to disable.
|
|
|
|
@export_subgroup("Physics")
|
|
@export_range(1, 100, 1, "or_greater", "suffix:m") var max_raycast_distance: int = 100 ## Maximum distance for the reverb raycasts.
|
|
@export_flags_3d_physics var collision_mask: int = 1 ## Mask for the raycast where to add reverb.
|
|
@export var roomsize_multiplicator: float = 6.0 ## How much hall to add compared to room size.[br]Sometimes you have a small room but you need a long reverb.
|
|
@export_range(1, 340, 1, "or_greater", "suffix:m/s") var speed_of_sound: int = 340 ## How fast sound travels through the air.
|
|
@export var prox_reduction: float = 24.0 ## How much proximity reduces the reverb
|
|
@export_range(4,32,1) var reverb_raycast_count: int = 4 ##how many reverb raycasts to shoot out horizontally
|
|
|
|
@export_subgroup("System")
|
|
@export_range(1, 60, 0.1, "or_greater", "suffix:per second") var audiophysics_ticks: int = 10 ## The number of audio physics calculations per second.[br]Tied to _physics_process().[br][br]Use 30-60 for fast moving sounds like a motorcycle passing by.[br][br]Default: 10.
|
|
@export var loop: bool = false ## Loop audio indefinitely.
|
|
@export var shut_up: bool = false ## Mute output.
|
|
@export var debug: bool = false ## Visualize raycasts, measurement rays and reverb-audioplayers.
|
|
|
|
var audio_player: AudioStreamPlayer3D = null
|
|
|
|
func do_set_stream(new_stream:AudioStream):
|
|
stream = new_stream
|
|
if easy_audio:
|
|
audio_player.stream = new_stream
|
|
else:
|
|
audio_player.do_set_stream(new_stream)
|
|
|
|
func do_play(start_position: float = 0.0) -> void:
|
|
if audio_player is SpatialAudio3D:
|
|
audio_player.do_play(start_position)
|
|
else:
|
|
audio_player.play(start_position)
|
|
|
|
func do_stop() -> void:
|
|
if audio_player is SpatialAudio3D:
|
|
audio_player.do_stop()
|
|
else:
|
|
audio_player.stop()
|
|
|
|
func set_to_easy_audio():
|
|
if audio_player != null:
|
|
audio_player.queue_free()
|
|
|
|
audio_player = self
|
|
|
|
func set_to_raytraced_audio() -> void:
|
|
if audio_player != null:
|
|
audio_player.queue_free()
|
|
|
|
audio_player = SpatialAudio3D.new()
|
|
|
|
audio_player.reverb_enabled = reverb_enabled
|
|
audio_player.reverb_volume_db = reverb_volume_db
|
|
audio_player.reverb_fadeintime = reverb_fadeintime
|
|
audio_player.reverb_fadeouttime = reverb_fadeouttime
|
|
audio_player.occlusion_lp_cutoff = occlusion_lp_cutoff
|
|
audio_player.occlusion_fadetime = occlusion_fadetime
|
|
audio_player.bass_proximity = bass_proximity
|
|
|
|
audio_player.max_raycast_distance = max_raycast_distance
|
|
audio_player.collision_mask = collision_mask
|
|
audio_player.roomsize_multiplicator = roomsize_multiplicator
|
|
audio_player.speed_of_sound = speed_of_sound
|
|
audio_player.prox_reduction = prox_reduction
|
|
audio_player.reverb_raycast_count = reverb_raycast_count
|
|
|
|
audio_player.name = "music player"
|
|
|
|
audio_player.audiophysics_ticks = 10
|
|
audio_player.loop = loop
|
|
audio_player.shut_up = shut_up
|
|
audio_player.debug = debug
|
|
|
|
add_child(audio_player)
|
|
|
|
func _ready() -> void:
|
|
add_to_group("sound_player")
|
|
if easy_audio:
|
|
set_to_easy_audio()
|
|
else:
|
|
set_to_raytraced_audio()
|
|
audio_player.stream = stream
|
|
audio_player.do_set_stream(stream)
|
|
|
|
audio_player.global_position = global_position
|