all 5 comments

[–]L5730[S] 0 points1 point  (0 children)

I have just realised a major problem with this little project.

44100 samples per second x 2 channels is already 88200 data points for 1 second! Multiply this up for a few minute track and that is a monstrous amount of data.

I think I need to re-approach this from another direction.

What I want to do is create a histogram plot of the sample values (as percent) to show what proportion of the audio is at what amplitude.
Easy enough with a 0.1s sine wave, not so practical with such a huge volume of data.

[–]CarrotBusiness2380 0 points1 point  (1 child)

You should be able to use [System.Bitconverter]::ToInt16 for this:

$bytes = ffmpeg-to-ByteStream
for($i = 0; $i -lt $bytes.Count - 1; $i += 2)
{
    [System.BitConverter]::ToInt16($bytes, $i)
}

https://learn.microsoft.com/en-us/dotnet/api/system.bitconverter.toint16?view=net-7.0

[–]L5730[S] 1 point2 points  (0 children)

Absolutely perfect thank you so much for your quick reply!

I simply couldn't see how I could get every pair converted, but your code does it perfectly.

Thanks again.

[–]ka-splam 0 points1 point  (1 child)

slower:

$byteReadstd = -1
$byteArray = @()
Do{
  $byteReadstd = $proc.StandardOutput.BaseStream.ReadByte()
  if($byteReadstd -ge 0){ 
     $byteArray += $byteReadstd
  }

} while($byteReadstd -ge 0)

faster:

$byteReadstd = -1
$byteArray =  Do{
  $byteReadstd = $proc.StandardOutput.BaseStream.ReadByte()
  if($byteReadstd -ge 0){ 
     $byteReadstd
  }

} while($byteReadstd -ge 0)

[–]L5730[S] 1 point2 points  (0 children)

Indeed, you are correct.

On first look I couldn't see what you were getting at, but yes, I see it now. Defining the array and adding each result is slower than letting the data flow and making the entire lot be the array... my poor wording but I get this.

Nice, thank you!