Search in sources :

Example 1 with StaticSoundData

use of org.terasology.engine.audio.StaticSoundData in project Terasology by MovingBlocks.

the class OggSoundFormat method load.

@Override
public StaticSoundData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (OggReader reader = new OggReader(inputs.get(0).openStream())) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ByteStreams.copy(reader, bos);
        ByteBuffer data = BufferUtils.createByteBuffer(bos.size()).put(bos.toByteArray());
        data.flip();
        return new StaticSoundData(data, reader.getChannels(), reader.getRate(), 16);
    } catch (IOException e) {
        throw new IOException("Failed to load sound: " + e.getMessage(), e);
    }
}
Also used : StaticSoundData(org.terasology.engine.audio.StaticSoundData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 StaticSoundData (org.terasology.engine.audio.StaticSoundData)1