android解码ogg pcm,GitHub - vincentjames501/libvorbis-libogg-android: JNI Android wrapper for encoding...

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值