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;
}
}
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();
}
}
}
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;
}
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();
}
}
}
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!");
}
Aggregations