Skip to content

Commit 0c3b535

Browse files
authored
Merge pull request #928 from bjornbytes/phonon-v4
Super Audio Upgrade!
2 parents fc3074f + 2f94933 commit 0c3b535

23 files changed

+2429
-1189
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
[submodule "deps/luau"]
3535
path = deps/luau
3636
url = https://github.com/bjornbytes/luau.git
37+
[submodule "deps/phonon"]
38+
path = deps/phonon
39+
url = https://github.com/bjornbytes/steam-audio

CHANGES.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ dev
4242
- Add support for non-uniform scale in `ConvexShape` and `MeshShape`.
4343
- Add `VertexUV2` builtin vertex attribute and `UV2` shader variable.
4444
- Add support for two sets of UVs in `ModelData`.
45+
- Add `t.audio.debug` and `t.audio.reverb` settings to `lovr.conf`.
46+
- Add `lovr.audio.update`.
47+
- Add `lovr.audio.setHRTF`.
48+
- Add `lovr.audio.get/setReverb`.
49+
- Add `Source:get/setAbsorption`.
50+
- Add `Source:get/setCone`.
51+
- Add `Source:get/setFalloff`.
52+
- Add `Source:get/setOcclusion`.
53+
- Add `Source:get/setReverb`.
54+
- Add `Source:get/setSpatialization`.
55+
- Add support for ambisonic source playback.
56+
- Add `AudioMesh`.
57+
- Add `lovr.audio.getStream`.
58+
- Add `AudioStream`.
59+
- Add `Sound:get/setFrame`.
4560

4661
### Change
4762

@@ -63,6 +78,12 @@ dev
6378
- Change `Mat4` to be a regular object instead of a vector type.
6479
- Change `lovr.graphics.submit` to have better performance when called multiple times per frame.
6580
- Change `Pass:text` and Font methods to also take nested tables of multicolor strings.
81+
- Change `lovr.audio.start` sink parameter to be a `boolean` or an `AudioStream`.
82+
- Change `lovr.audio.start/stop` to return error messages if they fail.
83+
- Change `lovr.audio.newSource` to create non-spatial sources by default.
84+
- Change `lovr.audio.newSource` to also accept and `AudioStream`.
85+
- Change audio device to start when playing a Source for the first time, instead of immediately.
86+
- Change `lovr.data.newSound` to take a channel count instead of a channel layout.
6687

6788
### Fix
6889

@@ -118,6 +139,12 @@ dev
118139
- Remove `Model:getData` (create and keep a `ModelData` around as needed).
119140
- Remove userdata vector types (use tables, and the `vector` and `quaternion` modules).
120141
- Remove `lovr.headset.getHandles` (use FFI).
142+
- Remove `lovr.audio.getSpatializer` (SteamAudio is always active).
143+
- Remove `lovr.audio.setGeometry` (use `AudioMesh`).
144+
- Remove `lovr.audio.get/setAbsorption` (use `Source:get/setAbsorption`).
145+
- Remove `Source:get/setDirectivity` (use `Source:get/setCone`).
146+
- Remove `Source:is/setEffectEnabled` (use new effect getters/setters).
147+
- Remove "stream" `Sound`s, `Sound:getCapacity`, and `Sound:isStream` (use `AudioStream`).
121148

122149
v0.18.0 - 2025-02-14
123150
---

CMakeLists.txt

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ option(LOVR_USE_LUAU "Use Luau instead of Lua" OFF)
2626
option(LOVR_USE_GLSLANG "Use glslang to compile GLSL shaders" ON)
2727
option(LOVR_USE_VULKAN "Use the Vulkan renderer" ON)
2828
option(LOVR_USE_WEBGPU "Use the WebGPU renderer" OFF)
29-
option(LOVR_USE_STEAM_AUDIO "Enable the Steam Audio spatializer (be sure to also set LOVR_STEAM_AUDIO_PATH)" OFF)
29+
option(LOVR_USE_STEAM_AUDIO "Use Steam Audio for audio spatialization" ON)
3030

3131
option(LOVR_SANITIZE "Enable Address Sanitizer" OFF)
3232
option(LOVR_PROFILE "Enable Tracy integration" OFF)
@@ -195,6 +195,29 @@ if(LOVR_ENABLE_PHYSICS)
195195
set(LOVR_JOLT joltc)
196196
endif()
197197

198+
# Steam Audio (aka phonon)
199+
if(LOVR_USE_STEAM_AUDIO AND LOVR_ENABLE_AUDIO)
200+
set(BUILD_SHARED_LIBS ON)
201+
set(STEAMAUDIO_ENABLE_SERIALIZATION OFF CACHE BOOL "")
202+
set(STEAMAUDIO_ENABLE_DEFAULT_HRTF OFF CACHE BOOL "")
203+
set(STEAMAUDIO_ENABLE_VALIDATION OFF CACHE BOOL "")
204+
set(STEAMAUDIO_BUILD_TESTS OFF CACHE BOOL "")
205+
set(STEAMAUDIO_BUILD_BENCHMARKS OFF CACHE BOOL "")
206+
set(STEAMAUDIO_BUILD_SAMPLES OFF CACHE BOOL "")
207+
set(STEAMAUDIO_BUILD_ITESTS OFF CACHE BOOL "")
208+
set(STEAMAUDIO_BUILD_DOCS OFF CACHE BOOL "")
209+
set(STEAMAUDIO_STATIC_RUNTIME OFF CACHE BOOL "")
210+
set(STEAMAUDIO_ENABLE_IPP OFF CACHE BOOL "")
211+
set(STEAMAUDIO_ENABLE_MKL OFF CACHE BOOL "")
212+
set(STEAMAUDIO_ENABLE_EMBREE OFF CACHE BOOL "")
213+
set(STEAMAUDIO_ENABLE_FFTS OFF CACHE BOOL "")
214+
set(STEAMAUDIO_ENABLE_RADEONRAYS OFF CACHE BOOL "")
215+
set(STEAMAUDIO_ENABLE_TRUEAUDIONEXT OFF CACHE BOOL "")
216+
add_subdirectory(deps/phonon/core phonon)
217+
set(LOVR_PHONON phonon)
218+
set(BUILD_SHARED_LIBS OFF)
219+
endif()
220+
198221
# glslang
199222
if(LOVR_USE_GLSLANG)
200223
set(ENABLE_HLSL OFF CACHE BOOL "")
@@ -239,28 +262,6 @@ if(LOVR_ENABLE_THREAD AND NOT (WIN32 OR EMSCRIPTEN))
239262
set(LOVR_PTHREADS Threads::Threads)
240263
endif()
241264

242-
# Steam Audio (aka Phonon)
243-
if(LOVR_USE_STEAM_AUDIO)
244-
if(NOT LOVR_STEAM_AUDIO_PATH)
245-
message(FATAL_ERROR "LOVR_USE_STEAM_AUDIO requires the LOVR_STEAM_AUDIO_PATH to be set to the location of the Steam Audio folder")
246-
endif()
247-
add_library(Phonon SHARED IMPORTED)
248-
target_include_directories(Phonon INTERFACE "${LOVR_STEAM_AUDIO_PATH}/include")
249-
if(ANDROID)
250-
set_target_properties(Phonon PROPERTIES IMPORTED_LOCATION "${LOVR_STEAM_AUDIO_PATH}/lib/Android/arm64/libphonon.so")
251-
elseif(WIN32)
252-
set_target_properties(Phonon PROPERTIES IMPORTED_IMPLIB "${LOVR_STEAM_AUDIO_PATH}/lib/Windows/x64/phonon.lib")
253-
set_target_properties(Phonon PROPERTIES IMPORTED_LOCATION "${LOVR_STEAM_AUDIO_PATH}/bin/Windows/x64/phonon.dll")
254-
elseif(APPLE)
255-
set_target_properties(Phonon PROPERTIES IMPORTED_LOCATION "${LOVR_STEAM_AUDIO_PATH}/lib/OSX/libphonon.dylib"
256-
IMPORTED_SONAME "@rpath/libphonon.dylib") # It doesn't make sense this line is required, but it is
257-
else() # Assume Linux. Note: This has *not* been tested. FIXME: When is the .so copied?
258-
set_target_properties(Phonon PROPERTIES IMPORTED_LOCATION "${LOVR_STEAM_AUDIO_PATH}/lib/Linux/x64/libphonon.so")
259-
endif()
260-
261-
set(LOVR_PHONON Phonon)
262-
endif()
263-
264265
# LÖVR
265266

266267
set(LOVR_SRC
@@ -309,6 +310,7 @@ target_link_libraries(lovr
309310
${LOVR_LUA}
310311
${LOVR_MSDF}
311312
${LOVR_JOLT}
313+
${LOVR_PHONON}
312314
${LOVR_GLSLANG}
313315
${LOVR_OPENXR}
314316
${LOVR_PTHREADS}
@@ -341,25 +343,19 @@ if(LOVR_USE_LUAU)
341343
target_compile_definitions(lovr PRIVATE LOVR_USE_LUAU)
342344
endif()
343345

344-
if(LOVR_ENABLE_AUDIO OR LOVR_ENABLE_DATA)
345-
target_sources(lovr PRIVATE
346-
src/lib/miniaudio/miniaudio.c
347-
)
348-
endif()
349-
350346
if(LOVR_ENABLE_AUDIO)
351347
target_sources(lovr PRIVATE
352348
src/modules/audio/audio.c
353-
src/modules/audio/spatializer_simple.c
354349
src/api/l_audio.c
355350
src/api/l_audio_source.c
351+
src/api/l_audio_audioMesh.c
352+
src/lib/miniaudio/miniaudio.c
356353
)
357354

358355
if(LOVR_USE_STEAM_AUDIO)
359-
target_compile_definitions(lovr PRIVATE LOVR_ENABLE_PHONON_SPATIALIZER)
360-
target_sources(lovr PRIVATE src/modules/audio/spatializer_phonon.c)
361-
# Dynamically linked at runtime, so this is not otherwise a dependency
362-
add_dependencies(lovr ${LOVR_PHONON})
356+
target_include_directories(lovr PRIVATE deps/phonon/core/src/core)
357+
target_include_directories(lovr PRIVATE "${PROJECT_BINARY_DIR}/phonon/src/core")
358+
target_compile_definitions(lovr PRIVATE LOVR_USE_PHONON)
363359
endif()
364360
else()
365361
target_compile_definitions(lovr PRIVATE LOVR_DISABLE_AUDIO)
@@ -376,6 +372,7 @@ if(LOVR_ENABLE_DATA)
376372
src/modules/data/rasterizer.c
377373
src/modules/data/sound.c
378374
src/api/l_data.c
375+
src/api/l_data_audioStream.c
379376
src/api/l_data_blob.c
380377
src/api/l_data_image.c
381378
src/api/l_data_modelData.c
@@ -771,6 +768,7 @@ elseif(ANDROID)
771768
${LOVR_MSDF}
772769
${LOVR_LUA}
773770
${LOVR_GLSLANG}
771+
${LOVR_PHONON}
774772
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/raw/lib/${ANDROID_ABI}"
775773
)
776774

@@ -792,11 +790,6 @@ elseif(ANDROID)
792790

793791
configure_file("${ANDROID_NDK}/toolchains/llvm/prebuilt/${ANDROID_HOST_TAG}/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so" "raw/lib/${ANDROID_ABI}/libc++_shared.so" COPYONLY)
794792

795-
if(LOVR_USE_STEAM_AUDIO)
796-
get_target_property(PHONON_LIB ${LOVR_PHONON} IMPORTED_LOCATION)
797-
file(COPY ${PHONON_LIB} DESTINATION raw/lib/${ANDROID_ABI})
798-
endif()
799-
800793
# Make an apk
801794
add_custom_target(
802795
buildAPK ALL
@@ -896,6 +889,7 @@ elseif(UNIX)
896889
move_lib(${LOVR_JOLT})
897890
move_lib(${LOVR_GLSLANG})
898891
move_lib(${LOVR_OPENXR})
892+
move_lib(${LOVR_PHONON})
899893
foreach(target ${ALL_PLUGIN_TARGETS})
900894
move_lib(${target})
901895
endforeach()

deps/phonon

Submodule phonon added at ff3db59

etc/boot.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ local conf = {
1919
timer = true
2020
},
2121
audio = {
22+
debug = false,
2223
start = true,
23-
spatializer = nil
24+
reverb = {
25+
type = 'convolution',
26+
rays = 4096,
27+
bounces = 16,
28+
duration = 2,
29+
rate = .1
30+
}
2431
},
2532
graphics = {
2633
debug = false,
@@ -195,6 +202,7 @@ function lovr.run()
195202
if not lovr.headset.isActive() then lovr.simulate(dt) end
196203
end
197204
if lovr.update then lovr.update(dt) end
205+
if lovr.audio then lovr.audio.update(dt) end
198206
if lovr.graphics then
199207
local window = lovr.graphics.getWindowPass()
200208
local headset = lovr.headset and lovr.headset.getPass()

etc/nogame/arg.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function lovr.arg(arg)
7272

7373
return function(conf)
7474
if arg.debug then
75+
conf.audio.debug = true
7576
conf.graphics.debug = true
7677
conf.headset.debug = true
7778
end

src/api/api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ void luax_vlog(void* context, int level, const char* tag, const char* format, va
344344
lua_pushstring(L, levels[level]);
345345
lua_pushstring(L, tag);
346346
lua_call(L, 3, 0);
347+
} else {
348+
lua_pop(L, 1);
347349
}
348350
lua_pop(L, 1);
349351
}

src/api/api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ extern StringEntry lovrOpenMode[];
5757
extern StringEntry lovrOriginType[];
5858
extern StringEntry lovrPassType[];
5959
extern StringEntry lovrPermission[];
60+
extern StringEntry lovrReverbMode[];
61+
extern StringEntry lovrReverbType[];
6062
extern StringEntry lovrSampleFormat[];
6163
extern StringEntry lovrShaderStage[];
6264
extern StringEntry lovrShaderType[];

0 commit comments

Comments
 (0)