Init mpv-joc

This commit is contained in:
TheM14 committed 2026-10-18 21:31:38 +08:00
commit 126e2cd233
52 files changed
+11035

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
param(
[string]$JocCoreSource = "",
[string]$Configuration = "Release",
[string]$BuildDir = (Join-Path $PSScriptRoot "..\build")
)
$ErrorActionPreference = 'Stop'
$root = Resolve-Path (Join-Path $PSScriptRoot "..")
function Find-CMake {
$command = Get-Command cmake -ErrorAction SilentlyContinue
if ($command) { return $command.Source }
$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere) {
$install = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($install) {
$candidate = Join-Path $install "Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
if (Test-Path $candidate) { return $candidate }
}
}
throw "cmake not found; install CMake or the Visual Studio C++ tools"
}
$cmake = Find-CMake
$configure = @("-S", $root, "-B", $BuildDir, "-A", "x64")
if (Get-Command ninja -ErrorAction SilentlyContinue) {
$configure = @("-S", $root, "-B", $BuildDir, "-G", "Ninja")
} else {
$configure += @("-G", "Visual Studio 17 2022")
}
if ($JocCoreSource -ne "") {
$configure += "-DJOC_CORE_SOURCE=$JocCoreSource"
}
& $cmake @configure
if ($LASTEXITCODE -ne 0) { throw "cmake configure failed" }
& $cmake --build $BuildDir --config $Configuration
if ($LASTEXITCODE -ne 0) { throw "cmake build failed" }
$dll = Join-Path $BuildDir "$Configuration\joc_mpv.dll"
if (-not (Test-Path $dll)) { $dll = Join-Path $BuildDir "joc_mpv.dll" }
Write-Output ""
Write-Output "plugin: $dll"
if (Test-Path (Join-Path (Split-Path $dll) "joc_core.dll")) {
Write-Output "core: $(Join-Path (Split-Path $dll) 'joc_core.dll')"
} else {
Write-Output "core: not next to the plugin; build with -JocCoreSource <JustOneCacophonyCXX> or copy joc_core.dll there"
}
+39
View File
@@ -0,0 +1,39 @@
import struct, sys, array
def read_wav(path):
raw = open(path, "rb").read()
assert raw[:4] in (b"RIFF", b"RF64"), raw[:4]
position = 12
fmt = None
while position + 8 <= len(raw):
chunk = raw[position:position+4]
size = struct.unpack("<I", raw[position+4:position+8])[0]
body = raw[position+8:position+8+size]
if chunk == b"fmt ":
tag, channels, rate, _, _, bits = struct.unpack("<HHIIHH", body[:16])
fmt = (tag, channels, rate, bits)
elif chunk == b"data":
return fmt, (body if size != 0xFFFFFFFF else raw[position+8:])
position += 8 + size + (size & 1)
raise SystemExit("no data chunk in " + path)
fmt_a, data_a = read_wav(sys.argv[1])
fmt_b, data_b = read_wav(sys.argv[2])
print("A", fmt_a, "bytes", len(data_a))
print("B", fmt_b, "bytes", len(data_b))
count = min(len(data_a), len(data_b))
if fmt_a[1:4] != fmt_b[1:4] or count == 0:
print("FORMAT MISMATCH")
sys.exit(1)
if data_a[:count] == data_b[:count]:
print("BIT-EXACT over", count, "bytes")
else:
left = array.array("f"); left.frombytes(data_a[:count])
right = array.array("f"); right.frombytes(data_b[:count])
if fmt_a[3] == 32:
diff = max(abs(x - y) for x, y in zip(left, right))
else:
diff = max(abs(x - y) for x, y in zip(data_a[:count], data_b[:count]))
different = sum(1 for x, y in zip(data_a[:count], data_b[:count]) if x != y)
print("DIFFERENT", different, "of", count, "bytes, max |diff|", diff)
sys.exit(2)
+12
View File
@@ -0,0 +1,12 @@
import http.client, sys
from urllib.parse import urlparse
url, out = sys.argv[1], sys.argv[2]
p = urlparse(url)
conn = http.client.HTTPConnection(p.hostname, p.port, timeout=120)
conn.request("GET", p.path, headers={"Range": "bytes=0-"})
resp = conn.getresponse()
data = resp.read()
with open(out, "wb") as handle:
handle.write(data)
print("status", resp.status, "bytes", len(data), "content-range", resp.getheader("Content-Range"))
+32
View File
@@ -0,0 +1,32 @@
param(
[Parameter(Mandatory=$true)][string]$MpvDir,
[string]$Hrtf = "",
[string]$BuildDir = (Join-Path $PSScriptRoot "..\build"),
[string]$Configuration = "Release"
)
$ErrorActionPreference = 'Stop'
$mpv = (Resolve-Path $MpvDir).Path
$plugin = Join-Path $BuildDir "$Configuration\joc_mpv.dll"
if (-not (Test-Path $plugin)) { $plugin = Join-Path $BuildDir "joc_mpv.dll" }
if (-not (Test-Path $plugin)) { throw "joc_mpv.dll not found under $BuildDir; run tools/build.ps1 first" }
$core = Join-Path (Split-Path $plugin) "joc_core.dll"
if (-not (Test-Path $core)) { throw "joc_core.dll not found next to the plugin; build with -JocCoreSource or copy it there" }
$scripts = Join-Path $mpv "scripts"
New-Item -ItemType Directory -Force -Path $scripts | Out-Null
Copy-Item $plugin (Join-Path $scripts "joc_mpv.dll") -Force
Copy-Item $core (Join-Path $mpv "joc_core.dll") -Force
Write-Output "installed $(Join-Path $scripts 'joc_mpv.dll')"
Write-Output "installed $(Join-Path $mpv 'joc_core.dll')"
if ($Hrtf -ne "") {
$target = Join-Path $mpv "HRTF"
New-Item -ItemType Directory -Force -Path $target | Out-Null
$name = if ($Hrtf -match "personalized_headphone$") { "binaural.personalized_headphone" } else { "binaural.sofa" }
Copy-Item $Hrtf (Join-Path $target $name) -Force
Write-Output "installed $(Join-Path $target $name)"
}
Write-Output ""
Write-Output "add this line to $(Join-Path $mpv 'mpv.conf'):"
Write-Output " script-opts=joc-output=binaural,joc-hrtf-source=sofa"
+21
View File
@@ -0,0 +1,21 @@
param(
[Parameter(Mandatory=$true)][string]$JocCoreSource
)
$ErrorActionPreference = 'Stop'
$headers = @("joc_core.h", "joc_stream.h", "joc_version.h")
$failures = 0
foreach ($header in $headers) {
$local = Join-Path $PSScriptRoot "..\third_party\joc\include\$header"
$source = Join-Path $JocCoreSource "include\$header"
if (-not (Test-Path $source)) { Write-Output "missing $source"; $failures++; continue }
$a = (Get-FileHash $local -Algorithm SHA256).Hash
$b = (Get-FileHash $source -Algorithm SHA256).Hash
if ($a -eq $b) {
Write-Output "same $header $a"
} else {
Write-Output "DIFFERS $header $a != $b"
$failures++
}
}
if ($failures -ne 0) { throw "$failures header(s) differ from the source checkout" }
Write-Output "public headers are byte-identical to $JocCoreSource"
+70
View File
@@ -0,0 +1,70 @@
param(
[Parameter(Mandatory=$true)][string]$Media,
[Parameter(Mandatory=$true)][string]$MpvDir,
[string]$JocCli = (Join-Path $PSScriptRoot "..\build\joc_core\Release\joc_cli.exe"),
[string]$Plugin = (Join-Path $PSScriptRoot "..\build\Release\joc_mpv.dll"),
[string]$Sofa = "",
[string]$Rosella = "",
[string]$WorkDir = (Join-Path $PSScriptRoot "..\_parity"),
[string]$Python = "python"
)
$ErrorActionPreference = 'Stop'
$mpv = Join-Path $MpvDir "mpv.com"
if (-not (Test-Path $mpv)) { throw "mpv.com not found in $MpvDir" }
if (-not (Test-Path $JocCli)) { throw "joc_cli not found at $JocCli" }
if (-not (Test-Path $Plugin)) { throw "joc_mpv.dll not found at $Plugin" }
New-Item -ItemType Directory -Force -Path $WorkDir | Out-Null
$log = Join-Path (Split-Path $Plugin) "joc_decoder.log"
function Invoke-Capture([string]$options, [string]$output) {
Remove-Item -Force $log -ErrorAction SilentlyContinue
$arguments = @("--no-config", "--ao=null", "--vo=null", "--pause=yes",
"--script=$Plugin", "--script-opts=joc-verbose=yes,joc-attach=no,joc-log=$log,$options",
"--msg-level=all=info", $Media)
Start-Process -FilePath $mpv -ArgumentList $arguments -PassThru -WindowStyle Hidden | Out-Null
$url = $null
for ($i = 0; $i -lt 120; $i++) {
Start-Sleep -Milliseconds 250
if (Test-Path $log) {
$match = Select-String -Path $log -Pattern 'http://127\.0\.0\.1:\d+/joc\.wav' | Select-Object -Last 1
if ($match) { $url = ([regex]::Match($match.Line, 'http://127\.0\.0\.1:\d+/joc\.wav')).Value; break }
}
}
if (-not $url) {
Get-Process mpv -ErrorAction SilentlyContinue | Stop-Process -Force
throw "the plugin did not publish an audio URL"
}
& $Python (Join-Path $PSScriptRoot "fetch.py") $url $output
Get-Process mpv -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Milliseconds 300
}
$failures = 0
if ($Sofa -ne "") {
Write-Output "=== binaural float32 (SOFA) ==="
$reference = Join-Path $WorkDir "reference.binaural.f32.wav"
$actual = Join-Path $WorkDir "plugin.binaural.f32.wav"
& $JocCli $Media --binaural --sofa-hrtf $Sofa --binaural-format float32 --binaural-output $reference | Out-Null
Invoke-Capture "joc-output=binaural,joc-hrtf=$Sofa" $actual
& $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference
if ($LASTEXITCODE -ne 0) { $failures++ }
}
if ($Rosella -ne "") {
Write-Output "=== binaural int24 (Rosella) ==="
$reference = Join-Path $WorkDir "reference.binaural.i24.wav"
$actual = Join-Path $WorkDir "plugin.binaural.i24.wav"
& $JocCli $Media --binaural --personalized-headphone $Rosella --binaural-format int24 --clip-action continue --binaural-output $reference | Out-Null
Invoke-Capture "joc-int24=yes,joc-hrtf-source=rosella,joc-hrtf=$Rosella" $actual
& $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference
if ($LASTEXITCODE -ne 0) { $failures++ }
}
Write-Output "=== speaker 7.1 float32 ==="
$reference = Join-Path $WorkDir "reference.7.1.f32.wav"
$actual = Join-Path $WorkDir "plugin.7.1.f32.wav"
& $JocCli $Media --speaker-layout 7.1 --speaker-format float32 --speaker-output $reference | Out-Null
Invoke-Capture "joc-output=speaker,joc-layout=7.1" $actual
& $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference
if ($LASTEXITCODE -ne 0) { $failures++ }
if ($failures -ne 0) { throw "$failures comparison(s) failed" }
Write-Output "all comparisons passed"