'NAudio frequency band intensity
I have an audio player using NAudio and I would like to display a real time intensity for each frequency band.
I have an event triggered for each block of 1024 samples:
public void Update(Complex[] fftResults)
{
// ??
}
What i would like to have is an array of numbers indicating the intensity of each frequency band. Lets say I would like to divide the window into 16 bands.
For example when there are more bass frequencies it could look like this:
░░░░░░░░░░░░░░░░
▓▓▓░░░░░░░░░░░░░
▓▓▓░░░░░░░░░░░░░
▓▓▓▓░░░░░░░░░░░░
▓▓▓▓▓░░░░░░░░░░░
▓▓▓▓▓▓▓▓░░░▓░░▓░
What should I put into that event handler if this is possible with that data?
Data coming (Complex[]) has already been transformed with the FFT. It is a stereo stream.
First try:
double[] bandIntensity = new double[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public void Update(Complex[] fftResults)
{
// using half fftResults because the others are just mirrored
int band = 0;
for (int n = 0; n < fftResults.Length/2; n++)
{
band = (int)(.5 * n / fftResults.Length * bandIntensity.Length);
bandIntensity[band] += Math.Sqrt(fftResults[n].X * fftResults[n].X + fftResults[n].Y * fftResults[n].Y);
bandIntensity[band] /= 2;
}
}
The above is doing something but I think too much goes into the first two bands, and I'm playing shakira which does not have that much bass.
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
