-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaudio_manager.gd
More file actions
37 lines (28 loc) · 883 Bytes
/
audio_manager.gd
File metadata and controls
37 lines (28 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends Node
var num_players = 16
var bus = "master"
var available = [] # The available players.
var queue = [] # The queue of sounds to play.
func _ready():
# Create the pool of AudioStreamPlayer nodes.
for i in num_players:
var p = AudioStreamPlayer.new()
add_child(p)
available.append(p)
p.connect("finished", self, "_on_stream_finished", [p])
p.bus = bus
func _on_stream_finished(stream):
# When finished playing a stream, make the player available again.
available.append(stream)
func play(sound_path, vol=0.0):
queue.append([sound_path, vol])
if available.empty():
print("full")
func _process(_delta):
# Play a queued sound if any players are available.
if not queue.empty() and not available.empty():
var next = queue.pop_front()
available[0].stream = next[0]
available[0].volume_db = next[1]
available[0].play()
available.pop_front()