Hi. I am working on a project rendering scenes to music. I have an audioInput class that basically stores information about audio in real time (both the spectrum and amplitudes at various frequencies).
I render the spectrum as follows:
public void display(GLDrawable gLDrawable)
{
signal = audiocapt.getSignal();
spectrum = audiocapt.getSpectrum();
float offset = 100f/(signal.length-1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0, 0,-100.0f);
gl.glRotatef(rotate,1.0f,2.0f,3.0f);
gl.glLineWidth(2.0f);
gl.glBegin(GL.GL_LINE_STRIP);
for(int i = 0; i<(signal.length) ;i++)
{
float red = signal[i]/80f;
float blue = 1.0f-signal[i]/80f;
float green = 0.0f;
gl.glColor3f(red,green,blue);
gl.glVertex2f(-50f+offset*i, signal[i]/5f);
gl.glLoadIdentity();
}
gl.glEnd();
gl.glFinish();
rotate += (spectrum[2]+spectrum[1])/30;
}
I know this might not be the best style I am basically hacking it together and worrying about making it nice later. The main problem I have is it seems to be updating too fast!! (maybe a good problem to have lol), such that it looks like there are 2 or 3 spectrums drawn onto the screen when I only want one. Even if I make the renderer into a thread and put sleeps in it looks like this unless the sleeps are over about 80 milli-seconds. Althernatively I can slow down the rate at which the audio information is gathered but still a big big sleep is needed.
is this normal?? My monitor is supposedly refreshing at 85Hz, but sleeps of 80m/s theoretically limits the spectrum changing shape to 12 times a second.
Any ideas on why this is happening/how it can be stopped? Is it just that the monitor isnt fast enough? If I print screen only 1 trace shows up. Are there any easy ways to stop this??
Lagz