5

Possible Duplicate:
Fast fourier transform in c#

I am looking for an example of performing a real time FFT (Fast Fourier Transform) of line in or mic audio data in C#. My goal is to determine in real time if a particular note is present in the audio data. Any examples appreciated.

Community
  • 1
  • 1
Phil
  • 231
  • 1
  • 3
  • 7
  • Duplicate: http://stackoverflow.com/questions/170394/fast-fourier-transform-in-c – Robert Greiner Oct 06 '10 at 14:48
  • 3
    Actually, this question does NOT cover exactly the same ground, as determining if a musical note in present in audio data may involve significant post processing of FFT results, or even the use of a completely different method of note pitch estimation (autocorrelation, wavelets, etc.). Note pitch != FFT peak frequency bin – hotpaw2 Oct 07 '10 at 18:35

1 Answers1

8

AForge.NET is an open-source library with Fast Fourier Transform support.
ExocortexDSP is also another option.

ExocortexDSP example would look something like this:

   Exocortex.DSP.ComplexF[] complexData = new Exocortex.DSP.ComplexF[512];
   for (int i = 0; i < 512; ++i)
   {
      // Fill the complex data
      complexData[i].Re = 1; // Add your real part here
      complexData[i].Im = 2; // Add your imaginary part here
   }

   // FFT the time domain data to get frequency domain data
   Exocortex.DSP.Fourier.FFT(complexData, Exocortex.DSP.FourierDirection.Forward);

   float[] mag_dat_buffer = new float[complexData.Length];
   // Loop through FFT'ed data and do something with it
   for (int i = 0; i < complexData.Length; ++i)
   {
      // Calculate magnitude or do something with the new complex data
      mag_data_buffer[i] = ImaginaryNumberMagnitude(complexData[i].Im, complexData[i].Re);
   }
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
  • Thank you for the library links. I am after examples :) – Phil Oct 06 '10 at 15:24
  • Updated with an ExocortexDSP example. AForge will look similar. – SwDevMan81 Oct 06 '10 at 15:49
  • Thank you, as in the original question, I am after examples of pulling said data from mic or line in. Would I need a second library for that? Thank you. – Phil Oct 06 '10 at 16:40
  • Correct. There is no built in functionality for sound. You would need something like this: codeproject.com/KB/audio-video/cswavrec.aspx – SwDevMan81 Oct 06 '10 at 17:32
  • is this "512 length array" means . 512 consecutive audio sample pieces ? if yes , i got it . – bh_earth0 Nov 16 '16 at 14:02