Add dense harmonic active probe loop
This commit is contained in:
parent
b29b04a7ea
commit
e7a4bff764
8 changed files with 245 additions and 5 deletions
66
scripts/start-live-audio-phase-field.ps1
Normal file
66
scripts/start-live-audio-phase-field.ps1
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
param(
|
||||
[string]$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path,
|
||||
[string]$Python = ".\.venv\Scripts\python.exe",
|
||||
[string]$Field = ".\calibration\runs\audio-program-live-20260518-180226\field-program-cleaned.wav",
|
||||
[string]$Reference = ".\calibration\runs\audio-program-live-20260518-180226\ground_truth_loopback.wav",
|
||||
[string]$Cache = ".\calibration\runs\audio-phase-field.msgpack",
|
||||
[string]$ProbeDir = ".\calibration\runs\active-probes",
|
||||
[double]$TargetConfidence = 0.72,
|
||||
[double]$TriggerConfidence = 0.45,
|
||||
[int]$MinProbeIntervalFrames = 1,
|
||||
[double]$ProbeLevelDbfs = -24.0,
|
||||
[double]$ProbeSeconds = 0.08,
|
||||
[double]$HarmonicRootHz = 440.0,
|
||||
[int]$HarmonicVoices = 48,
|
||||
[switch]$NoPlayback
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Set-Location -LiteralPath $Root
|
||||
|
||||
$logDir = Join-Path $Root "logs"
|
||||
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
|
||||
|
||||
$resolvedPython = if ([System.IO.Path]::IsPathRooted($Python)) { $Python } else { Join-Path $Root $Python }
|
||||
$stdout = Join-Path $logDir "audio-phase-field.stdout.log"
|
||||
$stderr = Join-Path $logDir "audio-phase-field.stderr.log"
|
||||
$pidPath = Join-Path $logDir "audio-phase-field.pid"
|
||||
|
||||
$arguments = @(
|
||||
".\scripts\stream_phase_field.py",
|
||||
"--field", $Field,
|
||||
"--reference", $Reference,
|
||||
"--cache", $Cache,
|
||||
"--source-id", "host-focusrite",
|
||||
"--source-id", "co-streamer-focusrite",
|
||||
"--source-id", "kiyo-0",
|
||||
"--source-id", "kiyo-1",
|
||||
"--source-id", "ps-eye-0",
|
||||
"--source-id", "ps-eye-1",
|
||||
"--loop",
|
||||
"--realtime",
|
||||
"--maintain-confidence",
|
||||
"--cram-harmonic-probes",
|
||||
"--probe-output-dir", $ProbeDir,
|
||||
"--probe-unmasked",
|
||||
"--target-confidence", ([string]$TargetConfidence),
|
||||
"--trigger-confidence", ([string]$TriggerConfidence),
|
||||
"--min-probe-interval-frames", ([string]$MinProbeIntervalFrames),
|
||||
"--probe-level-dbfs", ([string]$ProbeLevelDbfs),
|
||||
"--probe-seconds", ([string]$ProbeSeconds),
|
||||
"--harmonic-root-hz", ([string]$HarmonicRootHz),
|
||||
"--harmonic-voices", ([string]$HarmonicVoices)
|
||||
)
|
||||
|
||||
if (-not $NoPlayback) {
|
||||
$arguments += "--play-probes"
|
||||
}
|
||||
|
||||
$process = Start-Process -FilePath $resolvedPython -ArgumentList $arguments -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru -WindowStyle Hidden
|
||||
Set-Content -Path $pidPath -Value ([string]$process.Id) -Encoding ASCII
|
||||
|
||||
Write-Host "Started live audio phase-field confidence loop PID $($process.Id)"
|
||||
Write-Host "stdout: $stdout"
|
||||
Write-Host "stderr: $stderr"
|
||||
Write-Host "pid: $pidPath"
|
||||
30
scripts/stop-live-audio-phase-field.ps1
Normal file
30
scripts/stop-live-audio-phase-field.ps1
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
param(
|
||||
[string]$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Set-Location -LiteralPath $Root
|
||||
|
||||
$pidPath = Join-Path $Root "logs\audio-phase-field.pid"
|
||||
if (-not (Test-Path -LiteralPath $pidPath)) {
|
||||
Write-Host "No live audio phase-field PID file found."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$pidText = (Get-Content -LiteralPath $pidPath -Raw).Trim()
|
||||
if ($pidText.Length -eq 0) {
|
||||
Remove-Item -LiteralPath $pidPath -Force
|
||||
Write-Host "Empty PID file removed."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$process = Get-Process -Id ([int]$pidText) -ErrorAction SilentlyContinue
|
||||
if ($null -ne $process) {
|
||||
Stop-Process -Id $process.Id -Force
|
||||
Write-Host "Stopped live audio phase-field PID $($process.Id)"
|
||||
} else {
|
||||
Write-Host "Live audio phase-field PID $pidText is not running."
|
||||
}
|
||||
|
||||
Remove-Item -LiteralPath $pidPath -Force
|
||||
|
|
@ -85,6 +85,10 @@ def main() -> None:
|
|||
parser.add_argument("--probe-seconds", type=float, default=0.03)
|
||||
parser.add_argument("--probe-band", default="1800:9000")
|
||||
parser.add_argument("--ultrasonic-probes", action="store_true", help="Use a near-ultrasonic probe band below Nyquist.")
|
||||
parser.add_argument("--probe-pattern", choices=["single", "harmonic-dense"], default="single")
|
||||
parser.add_argument("--cram-harmonic-probes", action="store_true", help="Shortcut for dense near-ultrasonic harmonic probes.")
|
||||
parser.add_argument("--harmonic-root-hz", type=float, default=440.0)
|
||||
parser.add_argument("--harmonic-voices", type=int, default=36)
|
||||
parser.add_argument("--probe-channel", type=int, default=0)
|
||||
parser.add_argument("--probe-output-channels", type=int, default=2)
|
||||
parser.add_argument("--probe-unmasked", action="store_true", help="Allow probes even when the reference block is not masking them.")
|
||||
|
|
@ -105,7 +109,9 @@ def main() -> None:
|
|||
)
|
||||
maintainer = None
|
||||
if args.maintain_confidence:
|
||||
band_start, band_end = ultrasonic_probe_band(sample_rate) if args.ultrasonic_probes else parse_probe_band(args.probe_band)
|
||||
use_ultrasonic = args.ultrasonic_probes or args.cram_harmonic_probes
|
||||
probe_pattern = "harmonic-dense" if args.cram_harmonic_probes else args.probe_pattern
|
||||
band_start, band_end = ultrasonic_probe_band(sample_rate) if use_ultrasonic else parse_probe_band(args.probe_band)
|
||||
maintainer = ActiveConfidenceMaintainer(
|
||||
ActiveProbeOptimizer(
|
||||
ProbePolicy(
|
||||
|
|
@ -123,6 +129,9 @@ def main() -> None:
|
|||
end_hz=band_end,
|
||||
channels=args.probe_output_channels,
|
||||
channel=args.probe_channel,
|
||||
pattern=probe_pattern,
|
||||
harmonic_root_hz=args.harmonic_root_hz,
|
||||
harmonic_voices=args.harmonic_voices,
|
||||
)
|
||||
|
||||
start_monotonic = time.monotonic()
|
||||
|
|
|
|||
Loading…
Reference in a new issue