Search in sources :

Example 1 with AudioData

use of com.jme3.audio.AudioData 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 AudioData

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

the class OGGLoader method load.

public Object load(AssetInfo info) throws IOException {
    if (!(info.getKey() instanceof AudioKey)) {
        throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
    }
    AudioKey key = (AudioKey) info.getKey();
    boolean readStream = key.isStream();
    boolean streamCache = key.useStreamCache();
    InputStream in = null;
    try {
        in = info.openStream();
        AudioData data = load(in, readStream, streamCache);
        if (readStream && !streamCache) {
            // we still need the stream in this case ..
            in = null;
        }
        return data;
    } finally {
        if (in != null) {
            in.close();
        }
    }
}
Also used : AudioData(com.jme3.audio.AudioData) InputStream(java.io.InputStream) AudioKey(com.jme3.audio.AudioKey)

Example 3 with AudioData

use of com.jme3.audio.AudioData 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 4 with AudioData

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

the class WAVLoader method load.

public Object load(AssetInfo info) throws IOException {
    AudioData data;
    InputStream inputStream = null;
    try {
        inputStream = info.openStream();
        data = load(info, inputStream, ((AudioKey) info.getKey()).isStream());
        if (data instanceof AudioStream) {
            inputStream = null;
        }
        return data;
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
Also used : AudioStream(com.jme3.audio.AudioStream) AudioData(com.jme3.audio.AudioData) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) AudioKey(com.jme3.audio.AudioKey)

Example 5 with AudioData

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

the class TestAbsoluteLocators method main.

public static void main(String[] args) {
    AssetManager am = JmeSystem.newAssetManager();
    am.registerLoader(AWTLoader.class, "jpg");
    am.registerLoader(WAVLoader.class, "wav");
    // register absolute locator
    am.registerLocator("/", ClasspathLocator.class);
    // find a sound
    AudioData audio = am.loadAudio("Sound/Effects/Gun.wav");
    // find a texture
    Texture tex = am.loadTexture("Textures/Terrain/Pond/Pond.jpg");
    if (audio == null)
        throw new RuntimeException("Cannot find audio!");
    else
        System.out.println("Audio loaded from Sounds/Effects/Gun.wav");
    if (tex == null)
        throw new RuntimeException("Cannot find texture!");
    else
        System.out.println("Texture loaded from Textures/Terrain/Pond/Pond.jpg");
    System.out.println("Success!");
}
Also used : AudioData(com.jme3.audio.AudioData) AssetManager(com.jme3.asset.AssetManager) Texture(com.jme3.texture.Texture)

Aggregations

AudioBuffer (com.jme3.audio.AudioBuffer)3 AudioData (com.jme3.audio.AudioData)3 AudioStream (com.jme3.audio.AudioStream)3 AudioKey (com.jme3.audio.AudioKey)2 InputStream (java.io.InputStream)2 AssetInfo (com.jme3.asset.AssetInfo)1 AssetLoader (com.jme3.asset.AssetLoader)1 AssetManager (com.jme3.asset.AssetManager)1 OGGLoader (com.jme3.audio.plugins.OGGLoader)1 WAVLoader (com.jme3.audio.plugins.WAVLoader)1 Texture (com.jme3.texture.Texture)1 LogicalOggStream (de.jarnbjo.ogg.LogicalOggStream)1 VorbisStream (de.jarnbjo.vorbis.VorbisStream)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 JFileChooser (javax.swing.JFileChooser)1