Files
lddc/tools/capture-features.ps1
2026-11-04 14:13:04 +01:00

69 lines
2.6 KiB
PowerShell

<#
.SYNOPSIS
Registra le feature del classificatore di genere su audio reale.
.DESCRIPTION
Avvia bin\LoopbackCapture.exe con --dump-features, lascia girare la cattura
per N secondi (durante i quali riproduci i brani da analizzare) e chiude.
Registra una riga al secondo con feature grezze, feature normalizzate e
punteggi grezzi di ogni classe. Serve alla taratura: senza questi numeri
ogni modifica alle costanti e' un'ipotesi.
.PARAMETER Out
File CSV di destinazione. Un file per genere e' la scelta piu' comoda:
rock.csv, hiphop.csv, ...
.PARAMETER Seconds
Durata della cattura. Lascia almeno 20 s per brano: il primo 10-15% e'
warm-up (4 battute) e viene scartato in analisi.
.PARAMETER Port
Porta di lavoro. Non usare 4242 se il gioco e' in esecuzione.
.EXAMPLE
powershell -ExecutionPolicy Bypass -File tools\capture-features.ps1 -Out C:\temp\rock.csv -Seconds 120
#>
param(
[Parameter(Mandatory = $true)][string]$Out,
[int]$Seconds = 90,
[int]$Port = 4340
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
$exe = Join-Path $root "bin\LoopbackCapture.exe"
if (-not (Test-Path $exe)) { throw "non trovato: $exe" }
$Out = [IO.Path]::GetFullPath($Out)
$dir = Split-Path -Parent $Out
if ($dir -and -not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
if (Test-Path $Out) { Remove-Item $Out -Force }
$proc = Start-Process -FilePath $exe -ArgumentList "$Port", "0", "--dump-features=$Out" -PassThru -WindowStyle Hidden
Start-Sleep -Milliseconds 800
if ($proc.HasExited) { throw "il bridge e' uscito subito (exit $($proc.ExitCode)). Controlla la porta $Port." }
Write-Host ""
Write-Host " Registrazione avviata. Riproduci ORA i brani." -ForegroundColor Green
Write-Host " Durata: $Seconds s. Finestra: $Out"
Write-Host ""
$sw = [Diagnostics.Stopwatch]::StartNew()
while ($sw.Elapsed.TotalSeconds -lt $Seconds) {
$left = [int]($Seconds - $sw.Elapsed.TotalSeconds)
Write-Host ("`r {0,3} s rimanenti " -f $left) -NoNewline
Start-Sleep -Milliseconds 500
if ($proc.HasExited) { Write-Host ""; Write-Host " il bridge e' terminato in anticipo (exit $($proc.ExitCode))" -ForegroundColor Yellow; break }
}
Write-Host ""
if (-not $proc.HasExited) { Stop-Process -Id $proc.Id -Force }
Start-Sleep -Milliseconds 400
if (-not (Test-Path $Out)) { throw "nessun file prodotto: $Out" }
$rows = (Get-Content $Out | Measure-Object -Line).Lines - 1
Write-Host (" Righe raccolte: {0}" -f $rows) -ForegroundColor Green
Write-Host (" File: {0}" -f $Out)
if ($rows -lt 10) { Write-Host " Poche righe: l'audio era fermo o troppo basso?" -ForegroundColor Yellow }