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