Force neighbor loopback routing

This commit is contained in:
Meta Vens 2026-05-18 19:29:21 +01:00
commit 4e3cc946c3
7 changed files with 146 additions and 5 deletions

View file

@ -0,0 +1,110 @@
param(
[string]$VoicemeeterExe = "C:\Program Files (x86)\VB\Voicemeeter\voicemeeter_x64.exe",
[string]$VoicemeeterRemoteDll = "C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll",
[int[]]$CandidateStrips = @(7, 5, 6, 3, 4),
[int[]]$CandidateBuses = @(7, 6, 5, 4, 3, 2, 1, 0),
[string]$LogPath = "C:\Meta\LocalCastBridge\logs\voicemeeter-routing.log",
[switch]$AlsoMonitorA1
)
$ErrorActionPreference = "Stop"
New-Item -ItemType Directory -Force (Split-Path -Parent $LogPath) | Out-Null
"$(Get-Date -Format o) configuring Voicemeeter routing" | Set-Content -LiteralPath $LogPath -Encoding UTF8
function Log-Line {
param([string]$Line)
$Line | Tee-Object -FilePath $LogPath -Append
}
if (-not (Test-Path -LiteralPath $VoicemeeterRemoteDll)) {
throw "Voicemeeter Remote DLL not found: $VoicemeeterRemoteDll"
}
if (-not (Get-Process -Name "voicemeeter_x64" -ErrorAction SilentlyContinue)) {
if (-not (Test-Path -LiteralPath $VoicemeeterExe)) {
throw "Voicemeeter executable not found: $VoicemeeterExe"
}
Start-Process -FilePath $VoicemeeterExe
Start-Sleep -Seconds 3
}
$escapedDll = $VoicemeeterRemoteDll.Replace("\", "\\")
$source = @"
using System;
using System.Runtime.InteropServices;
public static class LocalCastVoicemeeterRemote {
[DllImport("$escapedDll", CallingConvention = CallingConvention.StdCall)]
public static extern int VBVMR_Login();
[DllImport("$escapedDll", CallingConvention = CallingConvention.StdCall)]
public static extern int VBVMR_Logout();
[DllImport("$escapedDll", CallingConvention = CallingConvention.StdCall)]
public static extern int VBVMR_SetParameterFloat(
[MarshalAs(UnmanagedType.LPStr)] string name,
float value
);
[DllImport("$escapedDll", CallingConvention = CallingConvention.StdCall)]
public static extern int VBVMR_GetVoicemeeterType(ref int voicemeeterType);
}
"@
Add-Type -TypeDefinition $source
function Set-VMFloat {
param(
[string]$Name,
[float]$Value
)
return [LocalCastVoicemeeterRemote]::VBVMR_SetParameterFloat($Name, $Value)
}
$login = [LocalCastVoicemeeterRemote]::VBVMR_Login()
try {
if ($login -lt 0) {
throw "Voicemeeter Remote login failed with code $login"
}
Start-Sleep -Milliseconds 250
$voicemeeterType = 0
[void][LocalCastVoicemeeterRemote]::VBVMR_GetVoicemeeterType([ref]$voicemeeterType)
Log-Line "Voicemeeter type: $voicemeeterType"
$routed = @()
foreach ($strip in $CandidateStrips) {
$b3 = Set-VMFloat -Name "Strip[$strip].B3" -Value 1.0
$mute = Set-VMFloat -Name "Strip[$strip].Mute" -Value 0.0
Log-Line "Strip[$strip].B3 -> $b3"
Log-Line "Strip[$strip].Mute -> $mute"
if ($b3 -ge 0) {
$routed += "Strip[$strip].B3"
}
if ($AlsoMonitorA1) {
$a1 = Set-VMFloat -Name "Strip[$strip].A1" -Value 1.0
Log-Line "Strip[$strip].A1 -> $a1"
}
if ($mute -ge 0) {
$gain = Set-VMFloat -Name "Strip[$strip].Gain" -Value 0.0
Log-Line "Strip[$strip].Gain -> $gain"
}
}
foreach ($bus in $CandidateBuses) {
$mute = Set-VMFloat -Name "Bus[$bus].Mute" -Value 0.0
$gain = Set-VMFloat -Name "Bus[$bus].Gain" -Value 0.0
Log-Line "Bus[$bus].Mute -> $mute"
Log-Line "Bus[$bus].Gain -> $gain"
}
if ($routed.Count -eq 0) {
throw "No candidate Voicemeeter strips accepted B3 routing"
}
Log-Line "Voicemeeter B3 routing enabled: $($routed -join ', ')"
}
finally {
[void][LocalCastVoicemeeterRemote]::VBVMR_Logout()
}

View file

@ -93,6 +93,8 @@ def build_stems(run: Path, stem_dir: Path) -> dict[str, Any]:
channel_fallback=np.zeros((frame_count, 2), dtype=np.float32),
placeholder_status="placeholder-silence-until-neighbor-loopback-is-captured-and-aligned",
synced_status="synced-from-neighbor-loopback-surface",
low_signal_status="captured-but-low-confidence-neighbor-loopback-is-near-silent",
min_rms=1e-4,
)
stems = [
@ -342,15 +344,24 @@ def load_co_streamer_surface(
channel_fallback: np.ndarray,
placeholder_status: str,
synced_status: str,
low_signal_status: str | None = None,
min_rms: float = 0.0,
) -> tuple[np.ndarray, str]:
if not path.exists():
return channel_fallback, placeholder_status
loaded = load_optional_program_audio(path, sample_rate, frame_count)
if np.asarray(channel_fallback).ndim == 1 and loaded.ndim == 2:
loaded = np.mean(loaded, axis=1, dtype=np.float32)
if min_rms > 0.0 and rms(loaded) < float(min_rms):
return loaded, low_signal_status or placeholder_status
return loaded, synced_status
def rms(samples: np.ndarray) -> float:
samples = np.asarray(samples, dtype=np.float32)
return float(np.sqrt(np.mean(samples * samples))) if samples.size else 0.0
def limit_peak(samples: np.ndarray, target: float = 0.98) -> np.ndarray:
peak = float(np.max(np.abs(samples))) if samples.size else 0.0
if peak <= target or peak <= 1e-9:

View file

@ -6,11 +6,13 @@ $soundVolumeView = "C:\Users\Madman's Lullaby\AppData\Local\Microsoft\WinGet\Lin
$ffmpeg = "C:\Users\Madman's Lullaby\AppData\Local\Microsoft\WinGet\Links\ffmpeg.exe"
$config = Join-Path $root "config\localcast.json"
$senderStart = Join-Path $root "scripts\sender-start.ps1"
$voicemeeterRouting = Join-Path $root "scripts\configure-voicemeeter-routing.ps1"
Set-Location $root
if (Test-Path -LiteralPath $voicemeeter) {
Start-Process -FilePath $voicemeeter
Start-Sleep -Seconds 2
} else {
Write-Warning "Voicemeeter was not found at $voicemeeter"
}
@ -24,5 +26,10 @@ if (Test-Path -LiteralPath $soundVolumeView) {
Write-Warning "SoundVolumeView was not found at $soundVolumeView"
}
& $senderStart -Config $config -FfmpegPath $ffmpeg
if (Test-Path -LiteralPath $voicemeeterRouting) {
& $voicemeeterRouting
} else {
Write-Warning "Voicemeeter routing script was not found at $voicemeeterRouting"
}
& $senderStart -Config $config -FfmpegPath $ffmpeg