May 3, 2015 at 8:20 PM
Edited May 3, 2015 at 9:25 PM

An FFT (Fast Fourier Transform) takes a block of raw Audio samples with a power of 2, to transform it into a Frequency and Amplitude representation.
Just imagine, any Signal can be displayed as an overlap of many many Sinus curves:
This is exactly, what FFT does. It splits the block into many Sinus curves and assumes them periodic. This Sinus calculation is done by vectors. To represent any possible vector, this is done with complex numbers. The power of 2 is just for algorithm optimization,
to be a "fast" Fourier transform.
So basically in practice your approach is e.g. like this:
Take 1024 raw Audio samples (from a MeteringSampleProvider ) > FFT (in a SampleAggregator) > Complex Array with 2048 samples > Loop through first (or second, as values are mirrored around zero) 1024 of them like this (blue part in Image above, second
part is cut off as it is mirrored):
'NOTE: this Event is fired by the SampleAggregator class.
Public Sub FftCalculated(ByVal sender As Object, ByVal e As FftEventArgs)
For i = 0 To e.Result.Length / 2  1
Dim Amplitude As Double = Math.Sqrt(e.Result(i).X ^ 2 + e.Result(i).Y ^ 2)
Dim Frequency As Double = i * 44100 / e.Result.Length
'TODO: Paint Frequency and Amplitude here on a control, Bitmap...
'Some side notes:
'Max Frequency is half SampleRate. In this case 22050.
'If you want to get real human reconized values, apply Logarithm on Amplitude and Frequency.
Next
End Sub
NOTE: I assumed a SampleRate of 44100 in above Example.
The above Event is fired by the SampleAggregator class, that you can find in a NAudio example. To feed the SampleAggregator I used a
MeteringSampleProvider with the StreamVolume Event (where you can also feed a WaveformPainter, etc.):
'NOTE: This Event is fired by MeteringSampleProvider class.
Private Sub m_SampleProvider_StreamVolume(ByVal sender As Object, ByVal e As NAudio.Wave.SampleProviders.StreamVolumeEventArgs)
Dim left As Single = 0
Dim right As Single = 0
If e.MaxSampleValues.Length > 0 Then left = e.MaxSampleValues(0)
'Is not mono Stream?
If e.MaxSampleValues.Length > 1 Then right = e.MaxSampleValues(1)
SampleAggregator.Add(0.5 * (left + right))
'WaveformPainter1.AddMax((left + right) / 2)
End Sub
Just add the MeteringSampleProvider in your Signal chain to access the raw Audio sample data.
I hope this Points you into the right direction, without confusing you too much with Details.
Kind regards
Freefall
PS: I created a StereoWaveformPainter some time ago based on the WaveformPainter class. Perhaps you want to incorporate it in a future release Mark.
