Skip to content

Commit

Permalink
Add listener-relative reflections. (closes #1)
Browse files Browse the repository at this point in the history
Make more SteamAudio settings configurable.
Add hacky "loop sub stream" option.
  • Loading branch information
stechyo committed Dec 30, 2023
1 parent 0169f52 commit 7c6040f
Show file tree
Hide file tree
Showing 16 changed files with 648 additions and 101 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
# godot-steam-audio
This is a GDExtension that integrates the [steam-audio](https://valvesoftware.github.io/steam-audio/) library into Godot. [Demo](https://www.youtube.com/watch?v=foKd96lR_qM)
This is a GDExtension that integrates the [steam-audio](https://valvesoftware.github.io/steam-audio/) library into Godot 4.2.

Right now, this extension still needs a [fork](https://github.com/stechyo/godot) of Godot to work, because
some internal functions aren't exposed (https://github.com/godotengine/godot-proposals/issues/8609). Once
either my PR gets merged or someone else exposes these functions, the extension will work with an official
version of godot. Linux and Windows are currently working, and macOS probably works, but I don't have the time
nor the money to support Mac, sorry.
### [Demo Video](https://youtu.be/9ltXpaphysc)
![A picture of the editor screen with some godot-steam-audio nodes.](doc/imgs/editor.png)

This extension is in an experimental phase, will have bugs and missing polish, and may likely have
crashes.
This extension is in a pre-alpha phase, will have bugs and missing polish, and might crash. Linux and Windows
are currently working. Mac probably works, but I don't have the time nor the money to support that, sorry.

### Features
- Spatial ambisonics audio
- Occlusion and transmission through geometry
- Distance attenuation
- Reflections (reverb)

To come:
- More editor configuration
- Reflections (reverb)
- Baked scenes for higher-performance reflections
- More raycasting support

### Installation
- Download the [latest release](https://github.com/stechyo/godot/releases/tag/steam-audio) or clone and build [my fork of Godot](https://github.com/stechyo/godot/tree/4.2-gdext/audio-stream-funcs).
- Download the [latest release](https://github.com/stechyo/godot-steam-audio/releases) of the extension or build it yourself.
- Download the [latest release](https://github.com/stechyo/godot-steam-audio/releases/latest) of the extension or build it yourself.
- Download the [latest supported release](https://github.com/ValveSoftware/steam-audio/releases/tag/v4.5.0) of steam-audio, and copy the binaries
that you find in the `lib` folder for your operating system to the `bin/` folder of your project, which
should contain a `libgodot-steam-audio` library (.dll or .so) and a .gdextension file.

Your project should have a `bin/` folder with:
- `libgodot-steam-audio.gdextension`
- `libgodot-steam-audio.linux.template_debug.x86_64` for Linux, or a similar .dll for Windows
- `libphonon.so` for Linux, or `phonon.dll` and some other files for Windows - these are the steam-audio lib
binaries.
- `libphonon.so` for Linux, or `phonon.dll`, `phonon.lib` and some other files for Windows - these are the
steam-audio library binaries.

### Project setup
In the `project` folder you have an example setup. Basically, you need:
Expand All @@ -40,6 +39,11 @@ In the `project` folder you have an example setup. Basically, you need:
and with a `SteamAudioStream`
- `SteamAudioGeometry` for each `MeshInstance3D` that you want to use for sound occlusion

### Why do I need your fork of Godot? That's annoying.
I agree, but I can't do much about it, because some internal functions aren't exposed
(https://github.com/godotengine/godot-proposals/issues/8609). Once either my PR gets merged or someone else
exposes these functions, the extension will work with an official version of godot.

### Contributing
This extension expects the steam-audio lib to be placed in `src/lib/steamaudio` in order to compile.
Check the Makefile for an example install.
Expand All @@ -50,3 +54,4 @@ Corporation in the United States of America and elsewhere.

Vespergamedev's [GDNative module](https://github.com/vespergamedev/godot_steamaudio) was helpful in figuring
out how to use the steam-audio lib.

Binary file added doc/imgs/editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
196 changes: 174 additions & 22 deletions project/scenes/demo.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=24 format=3 uid="uid://bilxmr83dwsgw"]
[gd_scene load_steps=28 format=3 uid="uid://bilxmr83dwsgw"]

[ext_resource type="Script" path="res://src/player.gd" id="1_c2adp"]
[ext_resource type="AudioStream" uid="uid://badsntcuvwx3t" path="res://sound/2.mp3" id="3_0iivb"]
[ext_resource type="AudioStream" uid="uid://dv4y870s0caeb" path="res://sound/1.mp3" id="3_sy0jh"]
[ext_resource type="SteamAudioMaterial" uid="uid://bljhgad6g2vnm" path="res://addons/steamaudio/materials/concrete_material.tres" id="5_musns"]
[ext_resource type="SteamAudioMaterial" uid="uid://oyakg0idhulv" path="res://addons/steamaudio/materials/wood_material.tres" id="6_hlhpg"]
[ext_resource type="SteamAudioMaterial" uid="uid://cexuij8fef5ay" path="res://addons/steamaudio/materials/carpet_material.tres" id="6_ph4pe"]
[ext_resource type="SteamAudioMaterial" uid="uid://oyakg0idhulv" path="res://addons/steamaudio/materials/wood_material.tres" id="6_u8h3j"]

[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_nkwlr"]

Expand Down Expand Up @@ -63,6 +65,12 @@ albedo_color = Color(0.272977, 0.142575, 0.0333709, 1)
[sub_resource type="BoxMesh" id="BoxMesh_g8mi8"]
material = SubResource("StandardMaterial3D_rrqcc")

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gwy3x"]
albedo_color = Color(0.654902, 0.141176, 0.0352941, 1)

[sub_resource type="BoxMesh" id="BoxMesh_doeet"]
material = SubResource("StandardMaterial3D_gwy3x")

[node name="Root" type="Node3D"]

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
Expand All @@ -74,7 +82,6 @@ environment = SubResource("Environment_gdnyc")
camera_attributes = SubResource("CameraAttributesPhysical_v0408")

[node name="SteamAudioConfig" type="SteamAudioConfig" parent="."]
global_log_level = 1

[node name="Ground" type="MeshInstance3D" parent="."]
transform = Transform3D(200, 0, 0, 0, 200, 0, 0, 0, 200, 0, 0, 0)
Expand All @@ -97,6 +104,7 @@ shape = SubResource("CapsuleShape3D_j0ktp")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)

[node name="SteamAudioListener" type="SteamAudioListener" parent="Player"]
reflection_duration = 2.0

[node name="Jukebox" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, -8)
Expand All @@ -108,7 +116,25 @@ mesh = SubResource("BoxMesh_s2rjv")
shape = SubResource("ConcavePolygonShape3D_5534r")

[node name="SteamAudioPlayer" type="SteamAudioPlayer" parent="Jukebox"]
sub_stream = ExtResource("3_sy0jh")
sub_stream = ExtResource("3_0iivb")
loop_sub_stream = true
min_attenuation_distance = 5.0
stream = SubResource("SteamAudioStream_vraar")
autoplay = true

[node name="Jukebox2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18.2, 0.5, -11.5)
mesh = SubResource("BoxMesh_s2rjv")

[node name="StaticBody3D" type="StaticBody3D" parent="Jukebox2"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="Jukebox2/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_5534r")

[node name="SteamAudioPlayer" type="SteamAudioPlayer" parent="Jukebox2"]
sub_stream = ExtResource("3_0iivb")
loop_sub_stream = true
min_attenuation_distance = 5.0
stream = SubResource("SteamAudioStream_vraar")
autoplay = true

Expand Down Expand Up @@ -139,38 +165,164 @@ shape = SubResource("ConcavePolygonShape3D_dx80d")
[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="concrete_wall"]
material = ExtResource("5_musns")

[node name="wood_wall" type="MeshInstance3D" parent="."]
transform = Transform3D(9, 0, 0, 0, 3, 0, 0, 0, 1, 0, 1.5, -3)
[node name="wood_house" type="Node3D" parent="."]
transform = Transform3D(0.819152, 0, 0.573576, 0, 1, 0, -0.573576, 0, 0.819152, 4.1, 0, -1.2)

[node name="wood_wall" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(10, 0, 0, 0, 9, 0, 0, 0, 1, 0.6, 3.5, -3)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_wall"]
[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_wall/StaticBody3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_wall"]
material = ExtResource("6_hlhpg")
[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall"]
material = ExtResource("6_u8h3j")

[node name="wood_wall3" type="MeshInstance3D" parent="."]
transform = Transform3D(9, 0, 0, 0, 3, 0, 0, 0, 1, 0, 1.5, -13)
[node name="wood_wall3" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(10, 0, 0, 0, 9, 0, 0, 0, 1, 0.6, 3.5, -13)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_wall3"]
[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall3"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_wall3/StaticBody3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall3/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_wall3"]
material = ExtResource("6_hlhpg")
[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall3"]
material = ExtResource("6_u8h3j")

[node name="wood_wall2" type="MeshInstance3D" parent="."]
transform = Transform3D(-3.93403e-07, 0, 1, 0, 3, 0, -9, 0, -4.37114e-08, 4, 1.5, -8)
[node name="wood_wall5" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(-1.74846e-07, 0, -1, 0, 9, 0, 4, 0, -4.37114e-08, -4, 3.5, -10.5)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall5"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall5/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall5"]
material = ExtResource("6_u8h3j")

[node name="wood_wall6" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(-1.31134e-07, 0, -1, 0, 9, 0, 3, 0, -4.37114e-08, -4, 3.5, -5)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall6"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall6/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall6"]
material = ExtResource("6_u8h3j")

[node name="wood_wall4" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(10, 0, 0, 0, -3.93403e-07, -1, 0, 9, -4.37114e-08, 1, 8.5, -8)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall4"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall4/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall4"]
material = ExtResource("6_u8h3j")

[node name="wood_wall2" type="MeshInstance3D" parent="wood_house"]
transform = Transform3D(-3.93403e-07, 0, 1, 0, 8, 0, -9, 0, -4.37114e-08, 6, 4, -8)
mesh = SubResource("BoxMesh_g8mi8")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_house/wood_wall2"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_house/wood_wall2/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_house/wood_wall2"]
material = ExtResource("6_u8h3j")

[node name="carpet_house" type="Node3D" parent="."]
transform = Transform3D(-0.866025, 0, 0.5, 0, 1, 0, -0.5, 0, -0.866025, -11.6, 0, -16.8)

[node name="wood_wall" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(10, 0, 0, 0, 9, 0, 0, 0, 1, 0.6, 3.5, -3)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall"]
material = ExtResource("6_ph4pe")

[node name="wood_wall3" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(10, 0, 0, 0, 9, 0, 0, 0, 1, 0.6, 3.5, -13)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall3"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall3/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall3"]
material = ExtResource("6_ph4pe")

[node name="wood_wall5" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(-1.74846e-07, 0, -1, 0, 9, 0, 4, 0, -4.37114e-08, -4, 3.5, -10.5)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall5"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall5/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall5"]
material = ExtResource("6_ph4pe")

[node name="wood_wall6" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(-1.31134e-07, 0, -1, 0, 9, 0, 3, 0, -4.37114e-08, -4, 3.5, -5)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall6"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall6/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall6"]
material = ExtResource("6_ph4pe")

[node name="wood_wall4" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(10, 0, 0, 0, -3.93403e-07, -1, 0, 9, -4.37114e-08, 1, 8.5, -8)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall4"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall4/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall4"]
material = ExtResource("6_ph4pe")

[node name="wood_wall2" type="MeshInstance3D" parent="carpet_house"]
transform = Transform3D(-3.93403e-07, 0, 1, 0, 8, 0, -9, 0, -4.37114e-08, 6, 4, -8)
mesh = SubResource("BoxMesh_doeet")
skeleton = NodePath("../..")

[node name="StaticBody3D" type="StaticBody3D" parent="wood_wall2"]
[node name="StaticBody3D" type="StaticBody3D" parent="carpet_house/wood_wall2"]

[node name="CollisionShape3D" type="CollisionShape3D" parent="wood_wall2/StaticBody3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="carpet_house/wood_wall2/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_dx80d")

[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="wood_wall2"]
material = ExtResource("6_hlhpg")
[node name="SteamAudioGeometry" type="SteamAudioGeometry" parent="carpet_house/wood_wall2"]
material = ExtResource("6_ph4pe")
Binary file added project/sound/2.mp3
Binary file not shown.
19 changes: 19 additions & 0 deletions project/sound/2.mp3.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="mp3"
type="AudioStreamMP3"
uid="uid://badsntcuvwx3t"
path="res://.godot/imported/2.mp3-3055b0866e8cbdb3783e580633ac5a8a.mp3str"

[deps]

source_file="res://sound/2.mp3"
dest_files=["res://.godot/imported/2.mp3-3055b0866e8cbdb3783e580633ac5a8a.mp3str"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
Loading

0 comments on commit 7c6040f

Please sign in to comment.