Learn more and download free source...
Application uses fmod sound library to play sound and to get sound info from mp3 files. Visualization was made with use of OpenGL and GLUT library. It was compiled and testes on both Linux and Windows operated computers. Application also uses libpng to save rendered frames.
Most important part of code is fmod initialization
void initFMOD(char * path) { System_Create(&fmodsys); fmodsys->init(1,FMOD_INIT_NORMAL,0); cout << "\nfile: " << path << endl; fmodsys->createSound(path, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &fmodsnd); fmodsys->playSound(FMOD_CHANNEL_FREE,fmodsnd,true,&fmodchn); specL = (float*)malloc(SPECLEN*sizeof(float)); specR = (float*)malloc(SPECLEN*sizeof(float)); //tmp unsigned int len; fmodchn->setVolume(1); fmodsnd->getLength( &len, FMOD_TIMEUNIT_MS ); fmodchn->setPosition( (int)(len*0.0), FMOD_TIMEUNIT_MS ); };
Variables specL and specR will be used to store FFT sound spectrum. We get FFT spectrum we need to use fmod Channel object method
fmodchn->getSpectrum( specL, SPECLEN, 0, FMOD_DSP_FFT_WINDOW_BLACKMAN ); fmodchn->getSpectrum( specR, SPECLEN, 1, FMOD_DSP_FFT_WINDOW_BLACKMAN );
And... thats all You need to create simple sound equalizer :)
Some people asked for code, and now it can be downloaded here. My code can be quite easily customized, spheres behavior can be tuned with two functions.
double spherePeek( double value) double sphereScaler( double value )First one controls how high peeks go out of the sphere. Second one controls sphere scaling.
Next some customization can be made where call to sphere rendering function is made.
void uglSphere( GLdouble radius, GLint slices, GLint stacks, GLboolean half = 0, GLdouble tang = PI, GLdouble pang = 2*PI)Seting different parameters of this function one can get sphere ( tang=PI, pang=2*PI ) or ring (tang=PI/2, pang=2*PI) and so on. For example in next video we can see 'rings' instead of spheres.
Forgive the music, i needed more bass :)
almost forgot
source file is HERE
1 comment
Hi, thank you very much for this little piece of code. I was looking for a way to incorporate sound analysis with games and this was a life saver. Perhaps in the future you could explore more advanced topics, such as Beat Detection. Or perhaps if I succeed in my research I can provide you with samples from my code. Thanks a lot once again!