Go to file
Vincent Pizzo f9553444b9
Merge pull request #32 from hannesa2/AndroidStudio-3.4.2
Introduce Travis and Android Studio 3.4.2
2019-07-27 22:22:53 -07:00
gradle/wrapper Android Studio 3.4.2 2019-07-28 06:45:06 +02:00
jni build arm64-v8a 2019-05-13 21:37:54 +02:00
libs build arm64-v8a 2019-05-13 21:37:54 +02:00
res -Expanding demo application to allow quick customization, adding bitrate target option, and changing how exception handling works 2013-04-12 11:05:56 -05:00
src ogg stream 2019-05-13 21:06:33 +02:00
.gitignore Android Studio 3.4 2019-05-13 19:31:06 +02:00
.travis.yml Travis 2019-07-28 06:51:48 +02:00
AndroidManifest.xml Android Studio 3.4 2019-05-13 19:31:06 +02:00
README.md -Updating readme to coincide with most recent changes 2013-04-12 11:14:22 -05:00
build.gradle Android Studio 3.4.2 2019-07-28 06:45:06 +02:00
build_jni.sh -Adding small performance tweaks 2013-04-11 15:29:35 -05:00
default.properties -Initial commit 2013-04-01 12:00:07 -05:00
gradlew Travis 2019-07-28 06:51:48 +02:00
gradlew.bat Android Studio 3.4 2019-05-13 19:31:06 +02:00
proguard_libvorbis-libogg.cfg [BUILD] update to gradle build tools 3.0.1 2019-05-13 19:31:06 +02: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, recordHandler);

//Start recording with a sample rate of 44KHz, 2 channels (stereo), at 0.2 quality
vorbisRecorder.start(44100, 2, 0.2f);

//or
//Start recording with a sample rate of 44KHz, 2 channels (stereo), at 128 bitrate
vorbisRecorder.start(44100, 2, 128000);
  • 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 stopEncoding() {
                 //The encoder should wrap up until the native encoder calls stop()
             }

             @Override
             public void start() {
                 //The native encoder has started
             }
         };
VorbisRecorder vorbisRecorder = new VorbisRecorder(encodeFeed, recordHandler);
vorbisRecorder.start(...);
  • Decoder
  • Decode from file
VorbisPlayer vorbisPlayer = new VorbisPlayer(fileToPlay, playerHandler);
vorbisPlayer.start();
  • 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