I'm trying to visualize the FFT of a sound while listening to it using the TarsosDSP library. However, when listening to it, there is a loud clicking noise that's being played and I can't seem to understand where this is coming from. This is happening on a PC.
With all things staying the same in my code, I've narrowed it down to the FFT.forwardTransform() function.
Here's the essential wiring of my application:
Application.java:
InputStream audioStreasm = getClass().getResourceAsStream(selectedSound);
InputStream bufferedIn = new BufferedInputStream(audioStreasm);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bufferedIn);
JVMAudioInputStream audioStream = new JVMAudioInputStream(audioInputStream);
// create a new dispatcher
dispatcher = new AudioDispatcher(audioStream, bufferSize, overlap);
dispatcher.addAudioProcessor(new FFTProcessor(fftSize, sampleRate));
dispatcher.addAudioProcessor(new AudioPlayer(audioStream.getFormat()));
// run the dispatcher (on a new thread).
new Thread(dispatcher, "Audio dispatching").start();
The file is a 1.85Mb wav file. bufferSize is 1536 sampleRate is 44100
And FFTProcessor.java essentially looks like this:
public class FFTProcessor implements AudioProcessor {
private int sampleRate;
private FFT fft;
private float[] amplitudes;
public FFTProcessor(int fftSize, int sampleRate) {
this.sampleRate = sampleRate;
fft = new FFT(fftSize);
amplitudes = new float[fftSize];
}
@Override
public boolean process(AudioEvent audioEvent) {
float[] audioBuffer = audioEvent.getFloatBuffer();
fft.forwardTransform(audioBuffer);
fft.modulus(audioBuffer, amplitudes);
return true;
}
}
I've tried limiting executions by introducing a form of throttling, thinking it might help. I also tried not using buffered input, in case there's a buffer underrun.
But the problem is still present and I'm starting to run out of ideas on what to try next.
Appreciate any pointers, thanks!