12 lines
1.1 KiB
PowerShell
12 lines
1.1 KiB
PowerShell
param([Parameter(Mandatory)][string]$CapturedPath,[Parameter(Mandatory)][string]$OutputPath)
|
|
$ErrorActionPreference='Stop'
|
|
$bytes=[IO.File]::ReadAllBytes((Resolve-Path $CapturedPath).Path)
|
|
$rate=[BitConverter]::ToInt32($bytes,24);$count=($bytes.Length-44)/2
|
|
if([BitConverter]::ToInt16($bytes,20)-ne1-or[BitConverter]::ToInt16($bytes,22)-ne1-or[BitConverter]::ToInt16($bytes,34)-ne16-or[Text.Encoding]::ASCII.GetString($bytes,36,4)-ne'data'){throw 'Canonical actual monoPCM16 required'}
|
|
$startEnergy=0.0;$tailEnergy=0.0;$tailSamples=0;$frontSamples=0
|
|
for($i=0;$i-lt$count;$i++){$v=[double][BitConverter]::ToInt16($bytes,44+$i*2);if($i-lt$rate*3){$startEnergy+=$v*$v;$frontSamples++};if($i-ge$count-$rate*3){$tailEnergy+=$v*$v;$tailSamples++}}
|
|
$frontRms=[Math]::Sqrt($startEnergy/$frontSamples);$tailRms=[Math]::Sqrt($tailEnergy/$tailSamples)
|
|
$passed=$count/$rate-ge8-and$frontRms-gt32-and$tailRms-le32
|
|
@{passed=$passed;duration=$count/$rate;first3secondsRms=$frontRms;last3secondsRms=$tailRms;thresholdRms=32;capturedSha256=(Get-FileHash $CapturedPath).Hash}|ConvertTo-Json|Set-Content -LiteralPath $OutputPath
|
|
if(!$passed){exit 1};exit 0
|