Search in sources :

Example 1 with AudioBuffer

use of com.jme3.audio.AudioBuffer in project jmonkeyengine by jMonkeyEngine.

the class OGGLoader method load.

private AudioData load(InputStream in, boolean readStream, boolean streamCache) throws IOException {
    if (readStream && streamCache) {
        oggStream = new CachedOggStream(in);
    } else {
        oggStream = new UncachedOggStream(in);
    }
    Collection<LogicalOggStream> streams = oggStream.getLogicalStreams();
    loStream = streams.iterator().next();
    //        if (loStream == null){
    //            throw new IOException("OGG File does not contain vorbis audio stream");
    //        }
    vorbisStream = new VorbisStream(loStream);
    streamHdr = vorbisStream.getIdentificationHeader();
    if (!readStream) {
        AudioBuffer audioBuffer = new AudioBuffer();
        audioBuffer.setupFormat(streamHdr.getChannels(), 16, streamHdr.getSampleRate());
        audioBuffer.updateData(readToBuffer());
        return audioBuffer;
    } else {
        AudioStream audioStream = new AudioStream();
        audioStream.setupFormat(streamHdr.getChannels(), 16, streamHdr.getSampleRate());
        // might return -1 if unknown
        float streamDuration = computeStreamDuration();
        audioStream.updateData(readToStream(oggStream.isSeekable()), streamDuration);
        return audioStream;
    }
}
Also used : AudioStream(com.jme3.audio.AudioStream) LogicalOggStream(de.jarnbjo.ogg.LogicalOggStream) VorbisStream(de.jarnbjo.vorbis.VorbisStream) AudioBuffer(com.jme3.audio.AudioBuffer)

Example 2 with AudioBuffer

use of com.jme3.audio.AudioBuffer in project jmonkeyengine by jMonkeyEngine.

the class PlaceholderAssets method getPlaceholderAudio.

public static AudioData getPlaceholderAudio() {
    AudioBuffer audioBuf = new AudioBuffer();
    audioBuf.setupFormat(1, 8, 44100);
    ByteBuffer bb = BufferUtils.createByteBuffer(1);
    bb.put((byte) 0).flip();
    audioBuf.updateData(bb);
    return audioBuf;
}
Also used : AudioBuffer(com.jme3.audio.AudioBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 3 with AudioBuffer

use of com.jme3.audio.AudioBuffer in project jmonkeyengine by jMonkeyEngine.

the class NativeVorbisLoader method loadBuffer.

private static AudioBuffer loadBuffer(AssetInfo assetInfo) throws IOException {
    AndroidAssetInfo aai = (AndroidAssetInfo) assetInfo;
    AssetFileDescriptor afd = null;
    NativeVorbisFile file = null;
    try {
        afd = aai.openFileDescriptor();
        int fd = afd.getParcelFileDescriptor().getFd();
        file = new NativeVorbisFile(fd, afd.getStartOffset(), afd.getLength());
        ByteBuffer data = BufferUtils.createByteBuffer(file.totalBytes);
        file.readFully(data);
        AudioBuffer ab = new AudioBuffer();
        ab.setupFormat(file.channels, 16, file.sampleRate);
        ab.updateData(data);
        return ab;
    } finally {
        if (file != null) {
            file.close();
        }
        if (afd != null) {
            afd.close();
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) AudioBuffer(com.jme3.audio.AudioBuffer) AndroidAssetInfo(com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo) ByteBuffer(java.nio.ByteBuffer)

Example 4 with AudioBuffer

use of com.jme3.audio.AudioBuffer in project jmonkeyengine by jMonkeyEngine.

the class WAVLoader method load.

private AudioData load(AssetInfo info, InputStream inputStream, boolean stream) throws IOException {
    this.in = new ResettableInputStream(info, inputStream);
    inOffset = 0;
    int sig = in.readInt();
    if (sig != i_RIFF)
        throw new IOException("File is not a WAVE file");
    // skip size
    in.readInt();
    if (in.readInt() != i_WAVE)
        throw new IOException("WAVE File does not contain audio");
    inOffset += 4 * 3;
    readStream = stream;
    if (readStream) {
        audioStream = new AudioStream();
        audioData = audioStream;
    } else {
        audioBuffer = new AudioBuffer();
        audioData = audioBuffer;
    }
    while (true) {
        int type = in.readInt();
        int len = in.readInt();
        inOffset += 4 * 2;
        switch(type) {
            case i_fmt:
                readFormatChunk(len);
                inOffset += len;
                break;
            case i_data:
                // Compute duration based on data chunk size
                duration = (float) (len / bytesPerSec);
                if (readStream) {
                    readDataChunkForStream(inOffset, len);
                } else {
                    readDataChunkForBuffer(len);
                }
                return audioData;
            default:
                int skipped = in.skipBytes(len);
                if (skipped <= 0) {
                    return null;
                }
                inOffset += skipped;
                break;
        }
    }
}
Also used : AudioStream(com.jme3.audio.AudioStream) IOException(java.io.IOException) AudioBuffer(com.jme3.audio.AudioBuffer)

Aggregations

AudioBuffer (com.jme3.audio.AudioBuffer)4 AudioStream (com.jme3.audio.AudioStream)2 ByteBuffer (java.nio.ByteBuffer)2 AssetFileDescriptor (android.content.res.AssetFileDescriptor)1 AndroidAssetInfo (com.jme3.asset.plugins.AndroidLocator.AndroidAssetInfo)1 LogicalOggStream (de.jarnbjo.ogg.LogicalOggStream)1 VorbisStream (de.jarnbjo.vorbis.VorbisStream)1 IOException (java.io.IOException)1