开发者

How can I decode OGG vorbis data from a ByteBuffer?

开发者 https://www.devze.com 2023-01-21 12:53 出处:网络
The libraries I fou开发者_StackOverflownded so far only have methods to decode from a file or InputStream. I have a ByteBuffer with OGG vorbis data and I need it decoded to PCM without having to write

The libraries I fou开发者_StackOverflownded so far only have methods to decode from a file or InputStream. I have a ByteBuffer with OGG vorbis data and I need it decoded to PCM without having to write it to a file first.


There seem to be 2 parts to this problem. 1) Getting Java Sound to deal with OGG Vorbis format. 2) Avoiding the File.

For (1), the Java Sound API allows the addition of extra formats via the Service Provider Interface. The idea is to put an encoder/decoder into a Jar and use a standard path and format of file to identify the class that does the encoding/decoding.

For (2), it is simply a matter of supplying an InputStream and required AudioFormat to the relevant methods of the AudioSystem static functions. E.G. (Pseudo code..)

byte[] b = byteBuffer.array();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
InputStream is = new InputStream(bais);
AudioInputStrream aisOgg = AudioSystem.getAudioInputStream(is);        
AudioInputStrream aisPcm = AudioSystem.
    getAudioInputStream(pcmAudioFormat, aisOgg);


You can use ByteArrayInputStream which is a subclass of InputStream. If your stream is very large you probably will have to write to file.

0

精彩评论

暂无评论...
验证码 换一张
取 消