Search code examples
javaaudiofftfrequencysampling

Java frequency analysis performance


I'm working on an application that samples audio and needs to do real time processing (FFT and harmonic product spectrum) of this data.

I need to use a sampling rate of 44100Hz and need a frequency resolution of 0.5Hz, meaning I need 88200 samples pre-FFT. This takes about 2 seconds to capture since it's twice the sampling rate; however, after the first sample, I do improve things significantly by using a circular buffer for the sampling and read only half as many samples from then on.

Unfortunately, the performance is still quite low and there is quite a bit of latency. This is a big problem since the application needs to be responding in a timely manner to input as it happens.

Does anyone have any suggestions for how I might improve the performance of this? I think the main problem lies in the requirement for large samples and it would be good if there was some way I could reduce how much audio is read while still maintaining the same accuracy. Would threading perhaps help here?

EDIT

If it helps to know, I am trying to do real-time F0 estimation from electric guitar input, along with multiple F0 estimation for chord matching. I have methods of doing this that work and are quite accurate, but it's for a uni project and I don't really have enough time left to look too far into other methods than the FFT. Really, I'm just hoping for some kind of way to speed up the sampling process.


Solution

  • Since you need to capture 2s of audio initially, this will set a lower bound on latency. Even with your 50% overlap you will still have a minimum latency of 1s. The FFT and other processing will only add to this, but hopefully not by a significant amount (otherwise use a faster FFT library). The only way you will be able to reduce this latency is by sacrificing frequency resolution.