FMOD: Improved Spectrum Analyser?

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

For my game (http://www.nicholaskingsley.co.uk/FightTune), I use the following code :

int FMOD_Spectrograph5(int channel,int difficultyLevel,char *storeSpec,int SPECHEIGHT,int BANDS,
			 int NIGHTMARE)
{
register int b0,x,sc,b1,loop;
register char y;
float fft[3][FFT_SIZE];
float sum;
int	result;

	result=0;
	if (FMOD_Channel_GetSpectrum((FMOD_CHANNEL *) channel,&fft[0][0],FFT_SIZE,0,FMOD_DSP_FFT_WINDOW_TRIANGLE)==FMOD_OK &&
		FMOD_Channel_GetSpectrum((FMOD_CHANNEL *) channel,&fft[1][0],FFT_SIZE,1,FMOD_DSP_FFT_WINDOW_TRIANGLE)==FMOD_OK)
	{
		for (x=0; x<FFT_SIZE; x++)
		{
			fft[2][x]=(fft[0][x]+fft[1][x])/2.0;
		}

		b0=0;
		for (x=0;x<BANDS;x++) 
		{
			sum=0.0;
			
			b1=pow(2,x*10.0/(BANDS-1));
			if (b1>=FFT_SIZE) 
			{
				b1=FFT_SIZE-1;
			}
			
			if (b1<=b0) 
			{
				b1=b0+1; // make sure it uses at least 1 FFT bin
			}
			
			sc=10+b1-b0;
			for (;b0<b1;b0++) 
			{
				sum+=fft[2][1+b0];
			}
			
			y=(char) ((sqrt(sum/log10(sc))*1.7*SPECHEIGHT)-4.0); // scale it
			y=(y>SPECHEIGHT ? SPECHEIGHT : \
				y<0 ? 0 : y); 
			
			*(storeSpec+x)=(char) y;
			
			if (diff[x]!=y)
			{
				diff[x]=y;
				result=(x==0 ? result | LEFT_BIT : \
						x==1 ? result | UP_BIT : \
						x==2 ? result | RIGHT_BIT : result | DOWN_BIT);
			}
		}
     }


Which produces 4 bars

For waveform, I used :

void FMOD_Spectrograph1(int channel,int SPECWIDTH,int SPECHEIGHT,char *specBuff)
{
register int c,x,v,y,loop;
int channels;
float *buf;
float fft[FFT_SIZE];

	if (specBuff==NULL)	return;

	memset(specBuff,(char) 0,SPECWIDTH*SPECHEIGHT);
	if (FMOD_System_GetSoftwareFormat(FMODSystem,NULL,NULL,&channels,NULL,NULL,NULL)==FMOD_OK)
	{
		for (loop=0; loop<2; loop++)
		{
			if (FMOD_System_GetWaveData(FMODSystem,&fft,FFT_SIZE,loop)==FMOD_OK)
			{
				for (x=0; x<SPECWIDTH; x++)
				{
					v=(1-fft[x])*SPECHEIGHT/2;

					if (v<0)
					{
						v=0;
					}
					else
					if (v>SPECHEIGHT)
					{
						v=SPECHEIGHT;
					}

					if (!x) 
					{
						y=v;
					}
					
					do { // draw line from previous sample...
						if (y<v) 
						{
							y++;
						}
						else 
						if (y>v) 
						{
							y--;
						}
							
						specBuff[y*SPECWIDTH+x]=(loop==0 ? 127 : 1); 
					} while (y!=v);
				}
			}
		}
	}
}


However, this will only work with the latest version of FMOD