0
0

Hi everybody, i tried out the c# example about spectrum analysis. But i cant figure out how to split the whole spectrum into parts, so that i can display an 8-band equalizer. Can anybody help me?

Thx Felix

  • You must to post comments
0
0

Do you mean you have a C# issue? Or do you not understand the spectrum. The array of values represents a frequency range. If there are 256 values, then each value represents nyquist / 256, or at 44khz output it would be 22khz / 256 for each entry.
you would just split the array into 8 sections (use average or max of each 32 floats in this case) if you want to display 8 bands.

  • You must to post comments
0
0

I have an problem with the spectrum… Somehow it does not change the spectrum at me. I did it the following:

These are the size of the spectrum and the count of the bands I will use
[code:a4m9l88i]
private const int SPECTRUMSIZE = 512;
private const int BANDS = 8;
[/code:a4m9l88i]

I init everything like in the spectrum example. Here I get the spectrum:

[code:a4m9l88i]
private void getSpectrum()
{
//Get left spectrum
system.getSpectrum(spectrum_left, SPECTRUMSIZE, 0, FMOD.DSP_FFT_WINDOW.TRIANGLE);

            //Get right spectrum
            system.getSpectrum(spectrum_right, SPECTRUMSIZE, 1, FMOD.DSP_FFT_WINDOW.TRIANGLE);

            for(int i = 0; i < SPECTRUMSIZE; i++)
                spectrum_center[i] = (spectrum_left[i] + spectrum_right[i]) / 2;
    }

[/code:a4m9l88i]

And here I try to convert the spectrum to my 8-Band equalizer:

[code:a4m9l88i]
private void UpdateAll(Graphics g)
{
if (system != null)
{
float max = 0;

            //Get the spectrum
            getSpectrum();

            //Divide spectrum into 8 parts
            for (int i = 0; i < BANDS; i++)
            {
                equalizer[i] = 0;   //reset equalizer

                for (int j = 0; j < (SPECTRUMSIZE / BANDS); j++)
                    equalizer[i] += spectrum_center[j + i * (int)(SPECTRUMSIZE / BANDS)];

                equalizer[i] /= (SPECTRUMSIZE / BANDS);
            }

            //Get max of the 8 bands
            for (int i = 0; i < BANDS; i++)
                max = Math.Max(max, equalizer[i]);

            //bands contains spectrum values in %
            int[] bands = new int[8];
            for (int i = 0; i < BANDS; i++)
                bands[i] = (int)(equalizer[i] / max) * 100;

            for (int i = 0; i < BANDS; i++)
                g.DrawString(bands[i].ToString(), new Font("Arial", 14), new SolidBrush(Color.Red), new PointF(10, (i * 20) + 5));
        }
    }

    private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
    {
        UpdateAll(e.Graphics);
    }

[/code:a4m9l88i]

I dont know what I’m doing wrong… I also tried to display the first 8 original values from the spectrum, but nothing changes…

  • You must to post comments
0
0

equalizer[i] /= (SPECTRUMSIZE / BANDS); ??

so all your values are tinyvalue/512/8??? = very tiny value

pcode

//init
const MAXENTRIES = 64;
const NUMEQ = 8;
float left[MAXENTRIES];
float right[MAXENTRIES];
float eqs[NUMEQ];
float norm = 0;

//main loop
memset left and right to 0 sizeof float * MAXENTRIES
memset eqs to 0 sizeof float * NUMEQ
norm = 0;

getSpectrum left
getSpectrum right

int eqI = 0;
for (int i=0; i<MAXENTRIES; i++)
{
eqI = floor(i/MAXENTRIES * NUMEQ);
eqs[eqI] = max(eqs[eqI],left[i],right[i])
norm = max(norm,eqs[eqI] )
}

//normalize according to doc and draw
if(norm>0)
for (int i=0; i<MAXEQ; i++)
{
eqs[i] /= norm;

//drawRect(x,y,x2,y2)
drawEq(i10,300,i10+8,300-(100*eqs[i]))

}

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.