Go to file
Vincent Pizzo 9cc9a7330b -Initial commit 2013-04-01 12:00:07 -05:00
jni -Initial commit 2013-04-01 12:00:07 -05:00
libs/armeabi -Initial commit 2013-04-01 12:00:07 -05:00
res -Initial commit 2013-04-01 12:00:07 -05:00
src -Initial commit 2013-04-01 12:00:07 -05:00
AndroidManifest.xml -Initial commit 2013-04-01 12:00:07 -05:00
README.md -Initial commit 2013-04-01 12:00:07 -05:00
build_jni.sh -Initial commit 2013-04-01 12:00:07 -05:00
default.properties -Initial commit 2013-04-01 12:00:07 -05:00
proguard.cfg -Initial commit 2013-04-01 12:00:07 -05:00
project.properties -Initial commit 2013-04-01 12:00:07 -05:00

README.md

libvorbis - Vorbis Encoder/Decoder example for Android/JNI

libvorbis - Vorbis Encoder/Decoder example for Android/JNI.

Purpose

  • The purpose of this project is to demonstrate how Android can use a JNI wrapper around the libvorbis library to both encode PCM data, and decode a ogg/vorbis bitstream

Usage

  • Press the "Start Recording" button to start recording, then press the "Stop Recording" button to stop recording.
  • Recorded content is saved saveTo.ogg on the external storage location.
  • Press the "Start Playing" button to start playing the recorded data, then press the "Stop Playing" button to stop playing or simply wait for the playback to finish on its own.
  • Content is played form saveTo.ogg on the external storage location

To Build

  • Verify the ndk-build tool is in your path and simply execute ./build_jni.sh from your terminal

Library Usage

  • Encoder
  • To record to a file
VorbisRecorder vorbisRecorder = new VorbisRecorder(fileToSaveTo);

//Start recording with a sample rate of 44KHz, 2 channels (stereo), at 0.2 quality
vorbisRecorder.start(44100, 2, 0.2f);
  • To read from other input, create a custom EncodeFeed
EncodeFeed encodeFeed = new EncodeFeed() {
                                                     @Override
                                                     public long readPCMData(byte[] pcmDataBuffer, int amountToWrite) {
                                                         //Read data from pcm data source
                                                     }

                                                     @Override
                                                     public int writeVorbisData(byte[] vorbisData, int amountToRead) {
                                                         //write encoded data to where ever
                                                     }

                                                     @Override
                                                     public void stop() {
                                                         //The native encoder has finished
                                                     }

                                                     @Override
                                                     public void start() {
                                                         //The native encoder has started
                                                     }
                                                 };
VorbisRecorder vorbisRecorder = new VorbisRecorder(encodeFeed);
vorbisRecorder.start(...);
  • Decoder
  • Decode from file
VorbisPlayer vorbisPlayer = new VorbisPlayer(fileToPlay);
//extract wave header information here, for example 44KHz stereo wav file
vorbisPlayer.start(44100, 2);
  • To write to custom output, create a custom DecodeFeed
DecodeFeed decodeFeed = new DecodeFeed() {
                                                         @Override
                                                         public int readVorbisData(byte[] buffer, int amountToWrite) {
                                                             //Read from vorbis data source
                                                         }

                                                         @Override
                                                         public void writePCMData(short[] pcmData, int amountToRead) {
                                                             //Write encoded pcm data
                                                         }

                                                         @Override
                                                         public void stop() {
                                                             //Stop called from the native decoder
                                                         }

                                                         @Override
                                                         public void startReadingHeader() {
                                                             //Called from the native decoder to read header information first
                                                         }

                                                         @Override
                                                         public void start(DecodeStreamInfo decodeStreamInfo) {
                                                             //Called from the native decoder that we're ready and have processed the header information
                                                         }
                                                     }
VorbisPlayer vorbisPlayer = new VorbisPlayer(decodeFeed);
...

License

  • For simplicity sake, this code is licensed under the same license as the libvorbis library from (http://xiph.org/vorbis/)

Others

  • Tested and working under the Nexus 4, feedback for other devices are welcome
  • Pull requests welcome