FMOD: Improved Spectrum Analyser?

BlitzMax Forums/BlitzMax Programming/FMOD: Improved Spectrum Analyser?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks everyone. Slowly getting there. Still looking for the winamp fading effect when the bars are displayed.

'Grisu's little & crappy Spectrum analyser using fmod 3.5

Graphics 800,600,0

FSOUND_Init(44100, 32,FSOUND_INIT_ACCURATEVULEVELS)
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), True)

Function Refresh_Spectrum2(xpos:Int, ypos:Int)
Local spec:Byte Ptr= FSOUND_DSP_GetSpectrum()
Local bnk:TBank    = CreateStaticBank(spec,32)

 'SetBlend Alphablend
 'SetAlpha 1.0
 SetColor 0,0,0
 DrawRect xpos-2,ypos+1,53,-28

 SetColor 105,105,105
 DrawLine xpos-1,ypos+1,xpos-1+51,ypos+1

			For Local x:Int=0 To 32 Step 2
					Local output:Float=(PeekFloat(bnk,x*8)*100)

                    output=output*(100/CurrentVolume)  					
                 
                    If output > 1 Then 
                      SetColor 210,50,10
                      DrawRect xpos+x,ypos-1,2,2 
 
                    If output > 2 Then 
                       SetColor 215,95,0       
                       DrawRect xpos+x,ypos-4,2,2 

                    If output > 3 Then 
                       SetColor 215,110,0
                       DrawRect xpos+x,ypos-7,2,2 

                    If output > 4 Then 
                       SetColor 202,130,10
                       DrawRect xpos+x,ypos-10,2,2 
    	         
                    If output > 5 Then 
    	               SetColor 220,170,30
                       DrawRect xpos+x,ypos-13,2,2 

                    If output > 6 Then 
                       SetColor 200,205,40
                       DrawRect xpos+x,ypos-16,2,2 

                    If output > 7 Then 
                       SetColor 150,220,30
                       DrawRect xpos+x,ypos-19,2,2 

                    If output > 8 Then 
                       SetColor 45,200,20
                       DrawRect xpos+x,ypos-22,2,2 

                    If output > 9 Then 
                       SetColor 55,185,15
                       DrawRect xpos+x,ypos-25,2,2 
    
                    If output = 10 Then 
                       SetColor 0,255,0                    
                       DrawRect xpos+x,ypos-28,2,2 

                    EndIf      ' = 10

                    EndIf      ' > 9
    
                    EndIf      ' > 8
                
                    EndIf      ' > 7
 
                    EndIf      ' > 6
 
                    EndIf      ' > 5

                    EndIf      ' > 4

                    EndIf      ' > 3

                    EndIf      ' > 2

                    EndIf      ' > 1
   
                    xpos=xpos+1
			Next
End Function  

Global CurrentVolume:Int=100 '50%

Music=FSOUND_Stream_Open("trailer_120.ogg",FSOUND_LOOP,0,0) ' <- Insert a tune here!
FSOUND_SetSFXMasterVolume(CurrentVolume)
FSOUND_Stream_Play(FSOUND_FREE,music)


Repeat

    SetClsColor 50,50,50
    Cls 

    Refresh_Spectrum2(40,40)	
	
	Flip()
	
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

FSOUND_Stream_Close(music)
Fsound_Close()

End