Search code examples
javaaudiocodec

Pure Java G.722 Implementation


I'm creating a VoIP softphone written in Java, and currently I have the G.711 codec implemented (all through Java, no native code).

I want to expand the codecs available, though everywhere I look, such as with projects like Jitsi, instead of writing the algorithm in Java, it's written in C and JNI is used to call it. I know very little about C and nothing about JNI, so I'm not too anxious to have to learn them. Additionally, I like the idea of a pure Java implementation that doesn't rely on native code to run.

My question is this: I'm sure there's a very good reason I haven't been able to find a Java implementation, but I don't know enough about the codecs to know what that reason is. So, how come there aren't any Java implementations of G.722 when another codec like G.711 works so well?

Additionally, if native code is the only way to go, where would be a good place to start? I've tried translating the G.722.c code from ITU-T into Java, but I stopped after a bit of a headache (also since my G.711 translation was working). I've looked into Xuggle, but building the project is a nightmare and I can't use the GPL version (also no handy Javadoc).

FFMpeg looks promising for all the codecs it offers, but I'm not sure about writing my own JNI wrapper, and the ones I've looked at have either been difficult to implement (Xuggle) or seem to be out of date (FMJ).

Bottom line: I'd like to implement new codecs, but I'd like to pick and choose which ones. I don't need an entire AV library when I only want to have 2 or 3 audio codecs. Small footprint, and as pure Java as it can get.


Solution

  • Codecs tend to be performance critical and have real-time requirements - both of which are more difficult to achieve in a virtual machine based runtime.

    When implemented natively, a codec is able to take advantage of CPU-specific hardware acceleration which a general purpose VM cannot. Obvious examples being the use of SIMD instructions for implementing filters and FFTs, and instructions specifically designed for accelerating bit-stream handling (e.g. locating first 1 or 0 bit in a register).

    This is a really big deal on ARMv7 CPUs used in most tablets and mobile phones where there's a huge difference in performance between the performance of the FPU and NEON (SIMD) units for floating point operations.