For some reason, it’s really had to encode audio in Android. Is it the patents? Is it that the Android developers didn’t think it was important? I didn’t think I would ever have to write C code at Astrid, much less native code for Android.
Oh well.
Introducing the Android AAC Encoder project on github.
The API’s pretty simple:
File dir = getFilesDir(); String output = dir.toString() + "/audio.aac"; AACEncoder encoder = new AACEncoder(); // bitrate, channels, sample rate, bits per sample, output file name encoder.init(64000, 1, 16000, 16, output); // pass in some audio data byte[] input = new byte[16000]; for(int i = 0; i < input.length; i++) input[i] = (byte) Math.round(255 * Math.sin(i * 1.0 / 10)); // can be called as many times as you want encoder.encode(input); encoder.uninit(); |
Good times. I actually thought JNI was pretty well done, for the most part. Android’s Android.mk make files are pretty confusing though, but I was able to muddle through that by shoving all of my .c files in one folder and .h files in another. All in a day’s work here in Astridville.
Speaking of Astridville, we recently invented a new variant on ping pong. That’s Andrew and Sam playing “well pong”:

Could you help me?
ndk-build failed in Centos6.3 with NDK:r8e and r4b ( i hava not try r7c.)
The only one error is about Radix4FFT_v5.s.
Oh,Sorry,exactly NDK:r8e is success.Thanks
Your lib encode raw stream to aac stream.
Could i use mediarecorder?
Thanks
I think you could only start creating AAC files in recent versions of Android, I could be wrong.