Java for Audio Processing is it Practical?

JeffV picture JeffV · Jan 2, 2009 · Viewed 14.2k times · Source

Is Java a suitable alternative to C / C++ for realtime audio processing?

I am considering an app with ~100 (at max) tracks of audio with delay lines (30s @ 48khz), filtering (512 point FIR?), and other DSP type operations occurring on each track simultaneously.

The operations would be converted and performed in floating point.

The system would probably be a quad core 3GHz with 4GB RAM, running Ubuntu.

I have seen articles about Java being much faster than it used to be, coming close to C / C++, and now having realtime extensions as well. Is this reality? Does it require hard core coding and tuning to achieve the %50-%100 performance of C some are spec'ing?

I am really looking for a sense if this is possible and a heads up for any gotchas.

Answer

Nils Pipenbrinck picture Nils Pipenbrinck · Jan 2, 2009

For an audio application you often have only very small parts of code where most of the time is spent.

In Java, you can always use the JNI (Java Native interface) and move your computational heavy code into a C-module (or assembly using SSE if you really need the power). So I'd say use Java and get your code working. If it turns out that you don't meet your performance goal use JNI.

90% of the code will most likely be glue code and application stuff anyway. But keep in mind that you loose some of the cross platform features that way. If you can live with that JNI will always leave you the door open for native code performance.