I am trying to use openGL to create a music visualization program. To start with I am just using one VU bar, to test it.
The bar moves to the right position but flickers when it moves. This is the main part of the program:
void Analyse()
{
bool quit = false;
bool playing = true;
bool *playingPtr = &playing;
FMOD::Sound *sound;
result = system01->createStream("/home/djameson/Music/Hurts-Like-Heaven-Cold-Play.mp3", FMOD_SOFTWARE, 0, &sound);
FMODErrorCheck(result);
FMOD::Channel *channel;
result = system01->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
FMODErrorCheck(result);
result = channel->setVolume(0.5f);
FMODErrorCheck(result);
while(quit == false)
{
result = system01->update();
FMODErrorCheck(result);
int sampleSize = 64;
float *specLeft = new float[sampleSize];
float *specRight = new float[sampleSize];
channel->getSpectrum(specLeft, sampleSize, 0, FMOD_DSP_FFT_WINDOW_RECT);
channel->getSpectrum(specRight, sampleSize, 1, FMOD_DSP_FFT_WINDOW_RECT);
float *spec = new float[sampleSize];
for (int i = 0; i < sampleSize; i++)
{
spec[i] = (specLeft[i] + specRight[i]) / 2;
}
float * maxIterator = max_element(&spec[0], &spec[sampleSize]);
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( SCREEN_WIDTH / 2.f, SCREEN_HEIGHT , 0.f );
glBegin( GL_QUADS );
glVertex2f( -21.f, -spec[0] * 500);
glVertex2f( 21.f, -spec[0]*500);
glVertex2f( 21.f, 21.f);
glVertex2f( -21.f, 21.f);
glEnd();
glutSwapBuffers();
channel->isPlaying(playingPtr);
if(*playingPtr == false)
{
quit = true;
}
delete [] spec;
delete [] specLeft;
delete [] specRight;
}
}
I initialize openGL and stuff in other functions, let me know if you need to see them and I will post them. The code obviously needs alot of improving but this is just a test thing. Thanks for your help!
I have v-sync enabled(i think) I did glxgears and got a fps rate of 60, I would post the thread in the fedora forum which I followed to check if I had v-sync enabled but It says there is a limit to the amount of URL’s in a new post.
I am using fedora 20
using freeglut