Advertisement

FMOD FSOUND_DSP_GetSpectrum() returning all 0's.

Started by January 29, 2005 02:54 AM
3 comments, last by Drew_Benton 19 years, 9 months ago
I'm doing: FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), true); float *spectrumData=FSOUND_DSP_GetSpectrum(); When I process the cells in spectrumData later on , I get 0's. The music is playing fine.I feel as if there's something missing that I need like DSP_Create, but I thought the getFFTUnit was an fmod dsp unit and could use it without further adjustment. Any suggestions would be appreciated.
you guys suck ;)
Advertisement
Well I don't have FMOD or have ever used it but hopefully this can help. On this page here there is source for some library. They use the same dsp function you are using. Also listed is their init code, so make sure you are doing somthing along these lines:

int NumSpectrumBars = 0;float *SpectrumArray;...void Init(){    FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);    NumSpectrumBars = 64;    SpectrumArray = new float[NumSpectrumBars];    memset(SpectrumArray, 0, NumSpectrumBars * sizeof(float));}...float *GetSpectrum(){    float *FSOUNDSpectrum = FSOUND_DSP_GetSpectrum();    int ctr = 0;    int FreqPerBand =  448 / NumSpectrumBars;    for (int i = 0; i < NumSpectrumBars; i++)    {        SpectrumArray = 0.0f;        for (int j = 0; j < FreqPerBand; j++)            SpectrumArray += FSOUNDSpectrum[ctr++];        SpectrumArray = SpectrumArray / 1.5f;        if (SpectrumArray > 1.0f)            SpectrumArray = 1.0f;    }    return SpectrumArray;}


Make a call to GetSpectrum when you want to access the elements. ie. GetSpectrum()[0]; will return the first element in the array.

I think that should take care of the problems you are having. Let me know. Note how they had to allocate new memory for the spectrum, so the results are saved for later use, as you are doing.

- Drew
Well here's what I have, using fmod and opengl to display the spectrum bars. I still get no response from the music playing.


float *SpectrumArray;void loadAudio(){FSOUND_STREAM* song;FSOUND_SetBufferSize(1000);FSOUND_Init(44100,64,0);song = FSOUND_Stream_Open("a.mp3", FSOUND_NORMAL | FSOUND_MPEGACCURATE, 0, NULL);FSOUND_Stream_Play(FSOUND_FREE,song);FSOUND_DSP_GetClearUnit();FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), true);FSOUND_DSP_SetPriority(FSOUND_DSP_GetFFTUnit(), 150); SpectrumArray = new float[256];memset(SpectrumArray, 0, 256 * sizeof(float));}float *GetSpectrum(){    float *FSOUNDSpectrum = FSOUND_DSP_GetSpectrum();	int ctr = 0;    int FreqPerBand =  448 / 256;    for (int i = 0; i < 256; i++)    {        SpectrumArray = 0.0f;        for (int j = 0; j < FreqPerBand; j++)            SpectrumArray += FSOUNDSpectrum[ctr++];        SpectrumArray = SpectrumArray / 1.5f;        if (SpectrumArray > 1.0f)            SpectrumArray = 1.0f;    }    return SpectrumArray;}void displaySpectrum(){if(rotateSwitch)  glRotatef(.003,0,0,1);glPushMatrix();  glTranslatef(0,-200,0);  int x=-750;  for(int i=0;i<256;i++){	float y= GetSpectrum();	glBegin(GL_POLYGON);	 glColor4f(0,1,1,1);     glVertex2f(x, 0);          glVertex2f((x+3),0);	 if(i%2==0)      glColor4f(1,0,0,1);	  else 	   glColor4f(1,0.5,0,1);     	 glVertex2f((x+3) , y+1*10);	 glVertex2f( x   ,  y+1*10);      	glEnd();	x+=6;	}glPopMatrix();}
Here's another link that shows some use of this function. I noticed that you do not have a call to
FSOUND_DSP_Create


From that page it says:
Quote:
Now its your turn

You may be thinking, well this sounds like a good place if I wanted to create my own effects such as reverb or a low pass filter for example, or maybe you just want to read the data that comes in so you can graphically plot it! Well you're right this is the place to do it.
Just call FSOUND_DSP_Create, and give it a callback, and a priority. Set it active with FSOUND_DSP_SetActive and immediately your DSP unit will be ticking.


I'd say give that a try before you use the othe DSP functions to make sure you have a valid DSP unit.

- Drew

This topic is closed to new replies.

Advertisement