Add server-side spatial audio with HRTF, occlusion and adaptive quality
Test / test (pull_request) Canceled after 0s
PR Slack Notifier / notify-devs (pull_request) Canceled after 0s

This commit is contained in:
2026-10-05 17:29:30 +03:00
parent 44b791ad50
commit 909e51bc0a
46 changed files with 5255 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# Copyright 2026 Sverse contributors. Licensed under the Apache License, Version 2.0.
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$hrtfRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$hrtfRuntime = Join-Path $hrtfRoot '.spatial-runtime'
$hrtfZip = Join-Path $hrtfRuntime 'steamaudio_4.8.1.zip'
$hrtfSDK = Join-Path $hrtfRuntime 'steam-audio\steamaudio'
New-Item -ItemType Directory -Path $hrtfRuntime -Force | Out-Null
if (!(Test-Path -LiteralPath $hrtfZip)) {
Invoke-WebRequest 'https://github.com/ValveSoftware/steam-audio/releases/download/v4.8.1/steamaudio_4.8.1.zip' -OutFile $hrtfZip
}
if ((Get-FileHash -LiteralPath $hrtfZip -Algorithm SHA256).Hash -ne '4A0AA5EC1176F38F0B0993A37C2259D9E86F27E22D5E24F83EC4C3CB9A1D5449') { throw 'Steam Audio archive checksum mismatch' }
if (!(Test-Path -LiteralPath (Join-Path $hrtfSDK 'include\phonon.h'))) {
Expand-Archive -LiteralPath $hrtfZip -DestinationPath (Join-Path $hrtfRuntime 'steam-audio') -Force
}
$hrtfBuild = Join-Path $hrtfRuntime 'hrtf-build'
& cmake -S (Join-Path $hrtfRoot 'native\hrtf') -B $hrtfBuild -G 'Visual Studio 17 2022' -A x64 "-DSTEAMAUDIO_ROOT=$hrtfSDK"
if ($LASTEXITCODE -ne 0) { throw 'HRTF configuration failed' }
& cmake --build $hrtfBuild --config Release --parallel
if ($LASTEXITCODE -ne 0) { throw 'HRTF build failed' }
Copy-Item -LiteralPath (Join-Path $hrtfSDK 'THIRDPARTY.md') -Destination (Join-Path $hrtfBuild 'Release\STEAMAUDIO-THIRDPARTY.md')
Copy-Item -LiteralPath (Join-Path $hrtfRoot 'docs\third-party\steam-audio-LICENSE.md') -Destination (Join-Path $hrtfBuild 'Release\STEAMAUDIO-LICENSE.md')
Write-Host "HRTF bridge: $hrtfBuild\Release\sverse_hrtf.dll"
+18
View File
@@ -0,0 +1,18 @@
# Copyright 2026 Sverse contributors. Licensed under the Apache License, Version 2.0.
[CmdletBinding()]
param([string]$Generator = 'Visual Studio 17 2022')
$ErrorActionPreference = 'Stop'
$spatialRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$spatialRuntime = Join-Path $spatialRoot '.spatial-runtime'
$spatialSource = Join-Path $spatialRuntime 'opus-src'
$spatialBuild = Join-Path $spatialRuntime 'opus-build'
New-Item -ItemType Directory -Path $spatialRuntime -Force | Out-Null
if (!(Test-Path -LiteralPath $spatialSource)) {
& git clone --depth 1 --branch v1.5.2 https://github.com/xiph/opus.git $spatialSource
if ($LASTEXITCODE -ne 0) { throw 'Opus clone failed' }
}
& cmake -S $spatialSource -B $spatialBuild -G $Generator -A x64 -DBUILD_SHARED_LIBS=ON -DOPUS_BUILD_TESTING=OFF -DOPUS_BUILD_PROGRAMS=OFF
if ($LASTEXITCODE -ne 0) { throw 'Opus configure failed' }
& cmake --build $spatialBuild --config Release --parallel
if ($LASTEXITCODE -ne 0) { throw 'Opus build failed' }
Write-Host "Library: $(Join-Path $spatialBuild 'Release\opus.dll')"
+52
View File
@@ -0,0 +1,52 @@
# Copyright 2026 Sverse contributors. Licensed under the Apache License, Version 2.0.
[CmdletBinding()]
param([switch]$Restart, [switch]$SkipBuild)
$ErrorActionPreference = 'Stop'
$spatialRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$spatialRuntime = Join-Path $spatialRoot '.spatial-runtime'
$spatialOpus = Join-Path $spatialRuntime 'opus-build\Release\opus.dll'
if (!(Test-Path -LiteralPath $spatialOpus)) {
throw "Missing $spatialOpus. Run scripts/build-spatial-opus.ps1 first."
}
$spatialHRTF = Join-Path $spatialRuntime 'hrtf-build\Release\sverse_hrtf.dll'
$spatialSampleConfig = Get-Content -LiteralPath (Join-Path $spatialRoot 'config-sample-spatial.yaml') -Raw
if ($spatialSampleConfig -match '(?m)^ hrtf:\r?\n enabled: true\s*$' -and !(Test-Path -LiteralPath $spatialHRTF)) {
throw "Missing $spatialHRTF. Run scripts/build-spatial-hrtf.ps1 first for the sample HRTF configuration."
}
if ($Restart) { & (Join-Path $PSScriptRoot 'stop-spatial.ps1') }
foreach ($spatialPort in @(7880, 8899)) {
if (Get-NetTCPConnection -State Listen -LocalPort $spatialPort -ErrorAction SilentlyContinue) {
throw "Port $spatialPort is already in use. Use -Restart for this repository's running laboratory."
}
}
New-Item -ItemType Directory -Path $spatialRuntime -Force | Out-Null
Push-Location -LiteralPath $spatialRoot
try {
if (!$SkipBuild) {
& go build -o .spatial-runtime/livekit-server-current.exe ./cmd/server
if ($LASTEXITCODE -ne 0) { throw 'LiveKit build failed' }
& go build -o .spatial-runtime/spatial-test-current.exe ./cmd/spatial-test
if ($LASTEXITCODE -ne 0) { throw 'HTML laboratory build failed' }
}
foreach ($spatialName in @('livekit-server-current.exe', 'spatial-test-current.exe')) {
if (!(Test-Path -LiteralPath (Join-Path $spatialRuntime $spatialName))) { throw "Missing $spatialName" }
}
$spatialServer = Start-Process -FilePath (Join-Path $spatialRuntime 'livekit-server-current.exe') -ArgumentList '--config', 'config-sample-spatial.yaml' -WorkingDirectory $spatialRoot -WindowStyle Hidden -RedirectStandardOutput (Join-Path $spatialRuntime 'server.stdout.log') -RedirectStandardError (Join-Path $spatialRuntime 'server.stderr.log') -PassThru
$spatialPreviousKey = $env:LIVEKIT_API_KEY
$spatialPreviousSecret = $env:LIVEKIT_API_SECRET
try {
# These credentials match the public local development YAML only.
$env:LIVEKIT_API_KEY = 'devkey'
$env:LIVEKIT_API_SECRET = 'spatial-local-development-secret'
$spatialLab = Start-Process -FilePath (Join-Path $spatialRuntime 'spatial-test-current.exe') -WorkingDirectory $spatialRoot -WindowStyle Hidden -RedirectStandardOutput (Join-Path $spatialRuntime 'lab.stdout.log') -RedirectStandardError (Join-Path $spatialRuntime 'lab.stderr.log') -PassThru
} catch {
Stop-Process -Id $spatialServer.Id -ErrorAction SilentlyContinue
throw
} finally {
$env:LIVEKIT_API_KEY = $spatialPreviousKey
$env:LIVEKIT_API_SECRET = $spatialPreviousSecret
}
Write-Host "LiveKit PID: $($spatialServer.Id); HTML PID: $($spatialLab.Id)"
Write-Host 'Open http://127.0.0.1:8899/ in your browser (do not open index.html as a file).'
Write-Host "Logs: $spatialRuntime"
} finally { Pop-Location }
+15
View File
@@ -0,0 +1,15 @@
# Copyright 2026 Sverse contributors. Licensed under the Apache License, Version 2.0.
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$spatialRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$spatialRuntime = [IO.Path]::GetFullPath((Join-Path $spatialRoot '.spatial-runtime')) + [IO.Path]::DirectorySeparatorChar
# Select only this checkout's development binaries; never stop by name alone.
Get-CimInstance Win32_Process | Where-Object {
$_.ExecutablePath -and $_.ExecutablePath.StartsWith($spatialRuntime, [StringComparison]::OrdinalIgnoreCase) -and
([IO.Path]::GetFileName($_.ExecutablePath) -match '^(livekit-server|spatial-test)(-[a-z0-9-]+)?\.exe$')
} | ForEach-Object {
Stop-Process -Id $_.ProcessId
Wait-Process -Id $_.ProcessId -Timeout 10 -ErrorAction SilentlyContinue
Write-Host "Stopped PID $($_.ProcessId)"
}