0
0

Does any one have a working vb/c#.net dsp sample for getspectrum

  • You must to post comments
0
0

Yep.[code:dr0c4r1m]
public void spectrumFunc()
{
IntPtr speccy;
int i;
float[] spectrum = new float[512];

FmodManaged.FSOUND.Function.DSP.FSOUND_DSP_SetActive(FmodManaged.FSOUND.Function.DSP.FSOUND_DSP_GetFFTUnit(), true );

        while( true )
        {
            Thread.Sleep( 25 );

            // if the spectrum dialog is not even open, don't bother to calculate the spectrum data
            if( sDialog == null )
                continue;
            if( sDialog != null )
                if( sDialog.Visible == false )
                    continue;

            mediaPlayer player = (mediaPlayer)players[currentPlayer];

            if( player.IsMediaPlaying() == true && player.IsMediaPaused() == false )
            {
                speccy = FmodManaged.FSOUND.Function.DSP.FSOUND_DSP_GetSpectrum();
                unsafe
                {
                    float* fred = (float*)speccy;
                    int yPos = 0;

                    // averge out so we have only 64 bars
                    for( i = 0; i < 256; i += 4 )
                    {
                        spectrum[yPos] = (float)Math.Round(fred[i] * 1000, 0)+(float)Math.Round(fred[i+1] * 1000, 0)+(float)Math.Round(fred[i+2] * 1000, 0)+(float)Math.Round(fred[i+3] * 1000, 0);
                        spectrum[yPos] /= 4;
                        yPos += 1;
                    }

                    if( sDialog != null )
                    {
                        sDialog.data = spectrum;
                        sDialog.UpdateSpectrum();
                    }      
                }
            }
        }
    }

[/code:dr0c4r1m]

The code above is the function for a seperate thread so it can wake up every 25 milliseconds.

The spectrum analyser is on a seperate dialog so it can float… The code in my spectrum dialog class is called UpdateSpectrum which is:

[code:dr0c4r1m]
public void UpdateSpectrum()
{
int yPos;
int i;
int height;

        yPos = 0;
        for( i = 0; i < 64; i++ )
        {
            height = 100 - (int)data[i];
            // draw the coloured part
            if( ( i % 2 ) == 0 )
                spectrumGraphic.DrawLine( redPen, yPos, height, yPos, 100 );
            else
                spectrumGraphic.DrawLine( bluePen, yPos, height, yPos, 100 );
            // draw the black bit at the top to blank out what was there before
            spectrumGraphic.DrawLine( blackPen, yPos, 0, yPos, height + 1 );
            yPos += 4;
        }
        this.spectrumBox.Refresh();

    }

[/code:dr0c4r1m]

spectrumGraphic is just a picture box dialog control which is created thusly:
private Pen redPen;
private Pen bluePen;
private Pen blackPen;
public float[] data = new float[512];
private Bitmap Image;
private Graphics spectrumGraphic;

and the constructor for the spectrum analyser class is:

        redPen = new Pen( Color.Red,4);
        bluePen = new Pen( Color.Blue,4);
        blackPen = new Pen( Color.Black, 4 );
        Image = new Bitmap( 255, 100 );
        this.spectrumBox.Image = Image;
        spectrumGraphic = Graphics.FromImage( spectrumBox.Image );
        SetStyle(ControlStyles.UserPaint, true);
        SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        SetStyle(ControlStyles.DoubleBuffer, true);

Ignore the variable names please, its still work in progress!!!

It all works, and works very well indeed.

  • You must to post comments
0
0

Here is simplest ever spectrum example you will ever see… highly coded and perfect for newbies. Highly editable progressbar & slider ocx is also included.

NOTE:- After Unzipping “SimpleSpectrum.zip” Please Don’t run VB PROJECT1 Right away…. First Put “Slider.ocx and Slider.lic” files into your System32 folder in Windows. Now you can run it without any problem.

Go get your zip here:

http://www.angelfire.com/freak2/sh_kane … ectrum.zip

If any buggs then please dont ignore. Im new comer too.. just inform me of my mistakes right here.. I visit this forum every day.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.