parent
5776f4a805
commit
1cbec71002
@ -0,0 +1,42 @@
|
||||
extends Node
|
||||
|
||||
# Code adapted from KidsCanCode
|
||||
|
||||
var num_players = 12
|
||||
var bus = "master"
|
||||
|
||||
var available = [] # The available players.
|
||||
var queue = [] # The queue of {path, volume} dictionaries.
|
||||
|
||||
func _ready():
|
||||
for i in num_players:
|
||||
var p = AudioStreamPlayer.new()
|
||||
add_child(p)
|
||||
|
||||
available.append(p)
|
||||
|
||||
p.volume_db = -10
|
||||
p.finished.connect(_on_stream_finished.bind(p))
|
||||
p.bus = bus
|
||||
|
||||
func _on_stream_finished(stream):
|
||||
available.append(stream)
|
||||
|
||||
func play(sound_path: String, volume_db: float = -10.0):
|
||||
# Path (or multiple, separated by commas)
|
||||
var sounds = sound_path.split(",")
|
||||
var chosen = "res://" + sounds[randi() % sounds.size()].strip_edges()
|
||||
queue.append({
|
||||
"path": chosen,
|
||||
"volume": volume_db
|
||||
})
|
||||
|
||||
func _process(_delta):
|
||||
if not queue.is_empty() and not available.is_empty():
|
||||
var item = queue.pop_front()
|
||||
var player = available.pop_front()
|
||||
|
||||
player.stream = load(item["path"])
|
||||
player.volume_db = item["volume"]
|
||||
player.pitch_scale = randf_range(0.9, 1.1)
|
||||
player.play()
|
||||
@ -0,0 +1 @@
|
||||
uid://b6g5iasbsyq1x
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://wvfsgkl8qob6"
|
||||
path="res://.godot/imported/ambience.ogg-06f8005a28aaf7071eab8a3c7655940a.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/ambience.ogg"
|
||||
dest_files=["res://.godot/imported/ambience.ogg-06f8005a28aaf7071eab8a3c7655940a.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://dvmkltf62sl6d"
|
||||
path="res://.godot/imported/placement-a.ogg-bdb1e41ed026dd9d40a4cf95bf46f2f8.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/placement-a.ogg"
|
||||
dest_files=["res://.godot/imported/placement-a.ogg-bdb1e41ed026dd9d40a4cf95bf46f2f8.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://bclwh4gkbpgc0"
|
||||
path="res://.godot/imported/placement-b.ogg-d700d7e7fe0800ffc3998bbf539d723e.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/placement-b.ogg"
|
||||
dest_files=["res://.godot/imported/placement-b.ogg-d700d7e7fe0800ffc3998bbf539d723e.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://dlyw5vro7nndy"
|
||||
path="res://.godot/imported/placement-c.ogg-0914c55e4166d68221b1f531bfaac866.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/placement-c.ogg"
|
||||
dest_files=["res://.godot/imported/placement-c.ogg-0914c55e4166d68221b1f531bfaac866.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://beod8l1kkkncu"
|
||||
path="res://.godot/imported/placement-d.ogg-e0662b91eb0812e10f48dc671192b2e6.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/placement-d.ogg"
|
||||
dest_files=["res://.godot/imported/placement-d.ogg-e0662b91eb0812e10f48dc671192b2e6.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://1tf8k7b76bxv"
|
||||
path="res://.godot/imported/removal-a.ogg-d917c6911910529dc9d47d7785b2e382.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/removal-a.ogg"
|
||||
dest_files=["res://.godot/imported/removal-a.ogg-d917c6911910529dc9d47d7785b2e382.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://dqwaqhr6r6hui"
|
||||
path="res://.godot/imported/removal-b.ogg-c06a07f2ba569575112caae669ec8bc5.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/removal-b.ogg"
|
||||
dest_files=["res://.godot/imported/removal-b.ogg-c06a07f2ba569575112caae669ec8bc5.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://coeitccvxgdck"
|
||||
path="res://.godot/imported/removal-c.ogg-d4227e081d5850200b0d7221d5e128ef.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/removal-c.ogg"
|
||||
dest_files=["res://.godot/imported/removal-c.ogg-d4227e081d5850200b0d7221d5e128ef.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://d0pi1p2aqvfnb"
|
||||
path="res://.godot/imported/removal-d.ogg-a0f42199d9bdc9ce5fb842f46d43359d.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/removal-d.ogg"
|
||||
dest_files=["res://.godot/imported/removal-d.ogg-a0f42199d9bdc9ce5fb842f46d43359d.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://d2c30dgleod1s"
|
||||
path="res://.godot/imported/rotate.ogg-b4286264d3c0e679948714c50e420e7b.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/rotate.ogg"
|
||||
dest_files=["res://.godot/imported/rotate.ogg-b4286264d3c0e679948714c50e420e7b.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
[remap]
|
||||
|
||||
importer="oggvorbisstr"
|
||||
type="AudioStreamOggVorbis"
|
||||
uid="uid://bjgshtt2m3gi5"
|
||||
path="res://.godot/imported/toggle.ogg-1f105799e2386c6ae75253b056c1336b.oggvorbisstr"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sounds/toggle.ogg"
|
||||
dest_files=["res://.godot/imported/toggle.ogg-1f105799e2386c6ae75253b056c1336b.oggvorbisstr"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
Loading…
Reference in New Issue