1

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.

unknown6656
  • 2,765
  • 2
  • 36
  • 52
Farid
  • 89
  • 1
  • 1
  • 7

3 Answers3

1

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#

unknown6656
  • 2,765
  • 2
  • 36
  • 52
Goodies
  • 1,951
  • 21
  • 26
  • @unknown6656 thanks for the edit. Long time ago ! by the way I propose to leave out the using. Or else put the curly brackets back ;) wish you happy modding.. grtz – Goodies Mar 02 '22 at 21:32
  • 1
    Ah, you would? putting back the curly brackets would not change the meaning of this statement due to the `using declaration`-statements introduced in C#8 (see https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#using-declarations). I removed the curly brackets to reduce the number of code lines and enhance readability.... – unknown6656 Mar 07 '22 at 08:15
  • Really ? In the above statement (in 2017) reader would be deallocated at the semicolon.. at least in v7 it does.. good to know there's been a change.. – Goodies Mar 07 '22 at 17:01
  • Yes, that is still true, if you use `using (var x = new Reader()) ;`. The semicolon would represent an empty expression statement. However, if you use `using var x = new Reader();`, the variable `x` will only be deallocated and disposed at the end of its lifetime and/or scope. – unknown6656 Mar 07 '22 at 23:50
0

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

Alexandru C.
  • 3,337
  • 1
  • 25
  • 27
0

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

enter image description here

David Filler
  • 198
  • 7