According to this article I'm able to capture FFT Result of a wave in sound file. My sampleRate is given by
using (var reader = new WaveFileReader(soundFile))
using (wc = new WaveChannel32(reader) { PadWithZeroes = false })
using (audioOutput = new DirectSoundOut())
{
wc.Volume = 100;
sampleRate = reader.WaveFormat.SampleRate; //<== sampleRate
averageBytePerSecond = waveIn.WaveFormat.AverageBytesPerSecond;
audioOutput.Init(wc);
try
{
audioOutput.Play();
while (audioOutput.PlaybackState != PlaybackState.Stopped)
{
Thread.Sleep(20);
}
audioOutput.Stop();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
I Use the method below to detect the main frequency of my sample (FftLenth is fixed to 8192):
void FftCalculated(object sender, FftEventArgs e)
{
float maxVal = 0;
int maxIndex = -1;
for (int i = 0; i < FftLenth / 2; i++)
{
float v = e.Result[i].X * e.Result[i].X + e.Result[i].Y * e.Result[i].Y;
if (v > maxVal)
{
maxVal = v;
maxIndex = i;
}
}
var frequency = maxIndex * (sampleRate / FftLenth);
}
Now I have my frequency, but how can I find the duration of this frequency? (How long the frequency is played.)