start.psm1

enum ChannelType
{
  Mono
  Stereo
  Other
  None
}

class DlAudioFileInfo
{
  [string]$Name
  [double]$SizeKB
  [string]$Codec
  [string]$CodecDisplayName
  [int]$Streams
  [int]$Channels
  [ChannelType]$ChannelType
  [double]$Duration
  [string]$SamplingFormat
  [int]$SampleRate
  [int]$BitsPerSample
  [int]$BitRate
  [string]$Status
  [string]$FullName
  [System.Io.FileInfo]$File
      
  static [string] $ffprobeExecutable = (Join-Path $env:temp -ChildPath ffprobe | Join-Path -ChildPath ffprobe.exe)
    
      
  DlAudioFileInfo([System.Io.FileInfo]$File)
  {
    $this.File = $File
    $this.Initialize()
  }
      
  DlAudioFileInfo([string]$Path)
  {
    $this.File = Get-Item -LiteralPath $Path
    $this.Initialize()
  }
      
  [void] Initialize()
  {
        
        
    $this.Name = $this.File.Name
    $this.FullName = $this.File.FullName
    $this.SizeKB = [Math]::Round( ($this.File.Length/1KB), 1)
        
    & {
      $ErrorActionPreference = 'Stop'
      try
      {
            
        $executable = [DlAudioFileInfo]::GetExecutablePath()
            
        $audioInfo = & $executable  -v error -select_streams a:0 -show_entries stream=codec_name,codec_long_name,sample_fmt,bits_per_sample,sample_rate,channels,duration,bit_rate -of json $this.File.FullName | ConvertFrom-Json
        $this.Streams = $audioInfo.streams.Count
        if ($this.Streams -eq 0)
        {
          $this.Status = 'File contains no audio streams. Is it a valid audio file?'
          $this.ChannelType = [ChannelType]::None
          return
        }
        elseif ($this.Streams -gt 1)
        {
          $this.Status = 'File contains {0} audio streams. Only first stream is examined.' -f $this.Streams
        }
        
        $this.Codec = $audioInfo.streams[0].codec_name
        $this.CodecDisplayName = $audioInfo.streams[0].codec_long_name
        $this.Channels = $audioInfo.streams[0].channels
        $this.ChannelType = switch ($this.Channels) {
          1  { [ChannelType]::Mono }
          2  { [ChannelType]::Stereo }
          default { [ChannelType]::Other }
              
        }
        $this.Duration = $audioInfo.streams[0].duration
        $this.SamplingFormat = $audioInfo.streams[0].sample_fmt
        $this.SampleRate = $audioInfo.streams[0].sample_rate
        $this.BitsPerSample = $audioInfo.streams[0].bits_per_sample
        $this.BitRate = $audioInfo.streams[0].bit_rate
        $this.Status = 'OK'
      }
      catch {
        $this.Status = $_.Exception.Message
      }
    }
  }
      
  static [string] GetExecutablePath()
  {
    $exists = Test-Path -Path ([DlAudioFileInfo]::ffprobeExecutable)
    if (!$exists)
    {
      throw "ffprobe.exe not found: $([DlAudioFileInfo]::ffprobeExecutable) does not exist. Download from https://ffbinaries.com/downloads."
    }
        
    return [DlAudioFileInfo]::ffprobeExecutable
  }
}

. $PSScriptRoot\Get-LedResistor.ps1
. $PSScriptRoot\Show-Fat32Converter.ps1
. $PSScriptRoot\Get-LedStripFramerateInfo.ps1
. $PSScriptRoot\Get-AntennaLength.ps1
. $PSScriptRoot\Get-ComPortInfo.ps1
. $PSScriptRoot\Find-NetworkDevice.ps1
. $PSScriptRoot\Assert-FfmpegIsPresent.ps1
. $PSScriptRoot\Assert-FfprobeIsPresent.ps1
. $PSScriptRoot\Convert-AudioWavFile.ps1
. $PSScriptRoot\Get-AudioFileInfo.ps1
. $PSScriptRoot\Test-IsWindows.ps1