What should be used in Android when porting C ++ code written using libsndfile?

I am transferring a small (<10 classes) C ++ project in Java. The project manages audio files, and in C ++ it does this with libsndfile . The code includes things like:

const int channels = audioFileInfo.channels; ... sf_readf_double( audioFile, inputBuffer, MAX_ECHO ); ... sf_writef_double( outputAudioFile, &currentAudioBuffer[WINDOW_SIZE * channels], SEGMENTATION_LENGTH ); 

In Java, what's the best way to manipulate audio files at a low level? I'm talking about things like normalization, adding echoes, etc.

Progress Report

After a little digging, I found javax.sound.sampled that looks like it can do the job.

Edit 2 Upon closer inspection, it will not work (or at least not available) since it relies on the com.sun.sound package.

Edit 3 With even more testing and experimentation, the com.sun.sound and sun.misc released under the GNU GPLv2, and I loaded them into my project. Renaming javax.sound.sampled to imp.javax.sound.sampled , the project compiles, and I can create AudioFileFormat objects without exception. I had no chance to play a lot, but I will keep you posted.

Edit 4 Ok, some things work with javax.sound.sampled, others don't. For example, calls such as:

 AudioInputStream stream = AudioSystem.getAudioInputStream(waveFile)); 

doesn't work, however I can get around this by doing:

 WaveFileReader wfr = new WaveFileReader(); AudioInputStream stream = wfr.getAudioInputStream(waveFile); 

In general, calls to things like AudioSystem.getAudioFileTypes() return empty lists. I can delve into the packages and see how it relates to providers, but I don’t understand how to fix it. Having received my stream object, it correctly reports its encoding, etc., which is encouraging.

My biggest problem right now is creating a Clip object. This must be created using the Line object, which usually comes from the AudioSystem. Can anyone think of this?

+4
source share
3 answers

libsndfile can be compiled for Android using the Native Development Kit. Once you have the library compiled for Android, you can use JNI to access it from Java.

+4
source

Why don't you just save this code in C ++ and call it in Java through JNI ?

0
source

If you can port libsndfile using the NDK, why not just use the NDK to directly port the code to C ++ and not worry about porting it to java?

0
source

All Articles