get frequency and amplitude from wave file

12.2k Views Asked by At

I want to get frequency and amplitude from wave file using c#. I tried NAudio and FFT, but result is nothing. can you help me please.

WaveChannel32 wave = new WaveChannel32(new WaveFileReader(open.FileName));
byte[] buffer = new byte[16384];
int read = 0;
double[] _fft;

while (wave.Position < wave.Length)
{
    read = wave.Read(buffer, 0, 16384); 
    _fft = FourierTransform.FFTDb(ref buffer);
}

do not scold if somewhere is wrong. I'm a newbie.

3

There are 3 best solutions below

1
On

You could use Bass Audio Library. It has .NET wrappers and you can get the peak amplitude and sample rate.

4
On

Most convenient for speech: use double fft, that is a cepstrum, fft(logfft(sample))) to find voice pitch

but thats not the reason I submit here.. google still seems to refer here for another question: "how to get the sampling frequency" of a .WAV file.

That is easy. For the record, with NAudio, that question was answered by Mark Heath in 2014.. this is my version, divide the byterate by the sample size in bytes to get sampling frequency,

using var reader = new WaveFileReader(fileName);
var byterate = reader.WaveFormat.AverageBytesPerSecond;

How to read Bit rate of .wav file in C#

0
On

I wrote a GUI in the past using MathNET.Numerics with success.

enter image description here