Skip to content

Commit

Permalink
Initial commit v2.
Browse files Browse the repository at this point in the history
Add direct effects (occlusion, transmission, attenuation).
Add ambisonics.
Add instructions.
Add editor config.
Add sample project.
  • Loading branch information
stechyo committed Dec 29, 2023
1 parent d959407 commit 0169f52
Show file tree
Hide file tree
Showing 48 changed files with 1,773 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
BreakConstructorInitializers: AfterColon
ColumnLimit: 0
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IncludeCategories:
- Regex: '".*"'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1
TabWidth: 4
UseTab: Always
---
Language: Cpp
Standard: c++17
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.os
src/lib/steamaudio
.sconsign.dblite
project/bin/*.so
project/bin/*.dll
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "src/lib/godot-cpp"]
path = src/lib/godot-cpp
url = https://github.com/stechyo/godot-cpp
branch = gdext/steam-audio
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
install-steam-audio:
curl -s https://api.github.com/repos/ValveSoftware/steam-audio/releases/latest \
| grep -E 'browser_download.*steamaudio_[0-9\.]+\.zip' \
| cut -d : -f 2,3 | tr -d \" | wget -O src/lib/steamaudio.zip -i -
unzip src/lib/steamaudio.zip -d src/lib/
rm src/lib/steamaudio.zip
cp src/lib/steamaudio/lib/linux-x64/libphonon.so project/bin
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# godot-steam-audio
SteamAudio extension for Godot
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)

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.

This extension is in an experimental phase, will have bugs and missing polish, and may likely have
crashes.

### Features
- Spatial ambisonics audio
- Occlusion and transmission through geometry
- Distance attenuation

To come:
- More editor configuration
- Reflections (reverb)

### 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 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.

### Project setup
In the `project` folder you have an example setup. Basically, you need:
- A `SteamAudioConfig` object in your scene
- A `SteamAudioListener`, which you probably want to keep inside your `Camera3D`
- `SteamAudioPlayer`s for each sound source that you want to use steam-audio on, each with a set sub_stream
and with a `SteamAudioStream`
- `SteamAudioGeometry` for each `MeshInstance3D` that you want to use for sound occlusion

### 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.

### Acknowledgements
godot-steam-audio uses the Steam® Audio SDK. Steam® is a trademark or registered trademark of Valve
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.
22 changes: 22 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

env = SConscript("src/lib/godot-cpp/SConstruct")

env.Append(CPPPATH=["src/"])
env.AppendUnique(CCFLAGS=("-isystem", "src/lib/steamaudio/include/"))
sources = Glob("src/*.cpp")

if env["platform"] == "linux":
env.Append(LIBPATH=["src/lib/steamaudio/lib/linux-x64"])
env.Append(LIBS=["libphonon.so"])
elif env["platform"] == "windows":
env.Append(LIBPATH=["src/lib/steamaudio/lib/windows-x64"])
env.Append(LIBS=["phonon.dll"])


library = env.SharedLibrary(
"project/bin/godot-steam-audio{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)

Default(library)
2 changes: 2 additions & 0 deletions project/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
2 changes: 2 additions & 0 deletions project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/brick_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://y1bi5skivlsh"]

[resource]
absorption_low = 0.03
absorption_mid = 0.04
absorption_high = 0.07
scattering = 0.05
transmission_low = 0.015
transmission_mid = 0.015
transmission_high = 0.015
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/carpet_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://cexuij8fef5ay"]

[resource]
absorption_low = 0.24
absorption_mid = 0.69
absorption_high = 0.73
scattering = 0.05
transmission_low = 0.02
transmission_mid = 0.005
transmission_high = 0.003
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/ceramic_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://cx5t18v1v5jku"]

[resource]
absorption_low = 0.01
absorption_mid = 0.01
absorption_high = 0.02
scattering = 0.05
transmission_low = 0.06
transmission_mid = 0.044
transmission_high = 0.011
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/concrete_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://bljhgad6g2vnm"]

[resource]
absorption_low = 0.24
absorption_mid = 0.69
absorption_high = 0.73
scattering = 0.05
transmission_low = 0.015
transmission_mid = 0.002
transmission_high = 0.001
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/default_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://cp5pfey82wrv5"]

[resource]
absorption_low = 0.1
absorption_mid = 0.2
absorption_high = 0.3
scattering = 0.05
transmission_low = 0.1
transmission_mid = 0.05
transmission_high = 0.03
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/glass_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://76vceaiftu7i"]

[resource]
absorption_low = 0.06
absorption_mid = 0.03
absorption_high = 0.02
scattering = 0.05
transmission_low = 0.06
transmission_mid = 0.044
transmission_high = 0.011
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/gravel_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://b687m7kh5ru1i"]

[resource]
absorption_low = 0.6
absorption_mid = 0.7
absorption_high = 0.8
scattering = 0.05
transmission_low = 0.031
transmission_mid = 0.012
transmission_high = 0.008
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/metal_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://cqx8833t2v8mo"]

[resource]
absorption_low = 0.2
absorption_mid = 0.07
absorption_high = 0.06
scattering = 0.05
transmission_low = 0.2
transmission_mid = 0.025
transmission_high = 0.01
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/plaster_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://bw0qgilugcj1h"]

[resource]
absorption_low = 0.12
absorption_mid = 0.06
absorption_high = 0.04
scattering = 0.05
transmission_low = 0.056
transmission_mid = 0.056
transmission_high = 0.004
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/rock_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://dbai50r63k346"]

[resource]
absorption_low = 0.13
absorption_mid = 0.2
absorption_high = 0.24
scattering = 0.05
transmission_low = 0.015
transmission_mid = 0.002
transmission_high = 0.001
10 changes: 10 additions & 0 deletions project/addons/steamaudio/materials/wood_material.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="SteamAudioMaterial" format=3 uid="uid://oyakg0idhulv"]

[resource]
absorption_low = 0.11
absorption_mid = 0.07
absorption_high = 0.06
scattering = 0.05
transmission_low = 0.07
transmission_mid = 0.014
transmission_high = 0.005
15 changes: 15 additions & 0 deletions project/bin/libgodot-steam-audio.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[configuration]

entry_symbol = "init_extension"
compatibility_minimum = 4.2

[libraries]

linux.x86_64.debug ="res://bin/libgodot-steam-audio.linux.template_debug.x86_64.so"
linux.x86_64.release = "res://bin/libgodot-steam-audio.linux.template_release.x86_64.so"
linux.debug.arm64 = "res://bin/libgodot-steam-audio.linux.template_debug.arm64.so"
linux.release.arm64 = "res://bin/libgodot-steam-audio.linux.template_release.arm64.so"
windows.x86_64.debug = "res://bin/libgodot-steam-audio.windows.template_debug.x86_64.dll"
windows.x86_64.release = "res://bin/libgodot-steam-audio.windows.template_release.x86_64.dll"
macos.debug = "res://bin/libgodot-steam-audio.macos.template_debug.framework"
macos.release = "res://bin/libgodot-steam-audio.macos.template_release.framework"
1 change: 1 addition & 0 deletions project/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions project/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b3j5jht0474is"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
55 changes: 55 additions & 0 deletions project/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="Godot-SteamAudio Demo"
run/main_scene="res://scenes/demo.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.svg"

[display]

window/size/mode=3

[input]

ui_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
]
}
ui_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
]
}
ui_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
]
}
ui_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
]
}
Loading

0 comments on commit 0169f52

Please sign in to comment.