private static AudioStream loadStream(AssetInfo assetInfo) throws IOException { AndroidAssetInfo aai = (AndroidAssetInfo) assetInfo; AssetFileDescriptor afd = null; NativeVorbisFile file = null; boolean success = false; try { afd = aai.openFileDescriptor(); int fd = afd.getParcelFileDescriptor().getFd(); file = new NativeVorbisFile(fd, afd.getStartOffset(), afd.getLength()); AudioStream stream = new AudioStream(); stream.setupFormat(file.channels, 16, file.sampleRate); stream.updateData(new VorbisInputStream(afd, file), file.duration); success = true; return stream; } finally { if (!success) { if (file != null) { file.close(); } if (afd != null) { afd.close(); } } } }
private boolean fillBuffer(AudioStream stream, int id) { int size = 0; int result; while (size < arrayBuf.length) { result = stream.readSamples(arrayBuf, size, arrayBuf.length - size); if (result > 0) { size += result; } else { break; } } if (size == 0) { return false; } nativeBuf.clear(); nativeBuf.put(arrayBuf, 0, size); nativeBuf.flip(); al.alBufferData(id, convertFormat(stream), nativeBuf, size, stream.getSampleRate()); return true; }
@Override public void resetObject() { id = -1; ids = null; setUpdateNeeded(); }
private void updateAudioStream(AudioStream as) { if (as.getIds() != null) { deleteAudioData(as); } int[] ids = new int[STREAMING_BUFFER_COUNT]; ib.position(0).limit(STREAMING_BUFFER_COUNT); al.alGenBuffers(STREAMING_BUFFER_COUNT, ib); ib.position(0).limit(STREAMING_BUFFER_COUNT); ib.get(ids); // Not registered with object manager. // AudioStreams can be handled without object manager // since their lifecycle is known to the audio renderer. as.setIds(ids); as.clearUpdateNeeded(); }
@Override public NativeObject createDestructableClone() { return new AudioStream(ids); }
private void readDataChunkForStream(int offset, int len) throws IOException { in.setResetOffset(offset); audioStream.updateData(in, duration); }
public void stopSource(AudioSource src) { synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() != Status.Stopped) { int chan = src.getChannel(); assert chan != -1; // if it's not stopped, must have id src.setStatus(Status.Stopped); src.setChannel(-1); clearChannel(chan); freeChannel(chan); if (src.getAudioData() instanceof AudioStream) { // If the stream is seekable, then rewind it. // Otherwise, close it, as it is no longer valid. AudioStream stream = (AudioStream)src.getAudioData(); if (stream.isSeekable()) { stream.setTime(0); } else { stream.close(); } } } } }
public void deleteAudioData(AudioData ad) { synchronized (threadLock) { if (audioDisabled) { return; } if (ad instanceof AudioBuffer) { AudioBuffer ab = (AudioBuffer) ad; int id = ab.getId(); if (id != -1) { ib.put(0, id); ib.position(0).limit(1); al.alDeleteBuffers(1, ib); ab.resetObject(); } } else if (ad instanceof AudioStream) { AudioStream as = (AudioStream) ad; int[] ids = as.getIds(); if (ids != null) { ib.clear(); ib.put(ids).flip(); al.alDeleteBuffers(ids.length, ib); as.resetObject(); } } } } }
/** * Reads samples from the stream. * * @see AudioStream#readSamples(byte[], int, int) * @param buf Buffer where to read the samples * @return number of bytes read. */ public int readSamples(byte[] buf) { return readSamples(buf, 0, buf.length); }
audioStream = new AudioStream(); audioData = audioStream; }else{
private void readDataChunkForStream(int len) throws IOException { audioStream.updateData(in, duration); }
private void updateAudioStream(AudioStream as) { if (as.getIds() != null) { deleteAudioData(as); } int[] ids = new int[STREAMING_BUFFER_COUNT]; ib.position(0).limit(STREAMING_BUFFER_COUNT); al.alGenBuffers(STREAMING_BUFFER_COUNT, ib); ib.position(0).limit(STREAMING_BUFFER_COUNT); ib.get(ids); // Not registered with object manager. // AudioStreams can be handled without object manager // since their lifecycle is known to the audio renderer. as.setIds(ids); as.clearUpdateNeeded(); }
public void stopSource(AudioSource src) { synchronized (threadLock) { if (audioDisabled) { return; } if (src.getStatus() != Status.Stopped) { int chan = src.getChannel(); assert chan != -1; // if it's not stopped, must have id src.setStatus(Status.Stopped); src.setChannel(-1); clearChannel(chan); freeChannel(chan); if (src.getAudioData() instanceof AudioStream) { // If the stream is seekable, then rewind it. // Otherwise, close it, as it is no longer valid. AudioStream stream = (AudioStream)src.getAudioData(); if (stream.isSeekable()) { stream.setTime(0); } else { stream.close(); } } } } }
public void deleteAudioData(AudioData ad) { synchronized (threadLock) { if (audioDisabled) { return; } if (ad instanceof AudioBuffer) { AudioBuffer ab = (AudioBuffer) ad; int id = ab.getId(); if (id != -1) { ib.put(0, id); ib.position(0).limit(1); al.alDeleteBuffers(1, ib); ab.resetObject(); } } else if (ad instanceof AudioStream) { AudioStream as = (AudioStream) ad; int[] ids = as.getIds(); if (ids != null) { ib.clear(); ib.put(ids).flip(); al.alDeleteBuffers(ids.length, ib); as.resetObject(); } } } } }
/** * Reads samples from the stream. * * @see AudioStream#readSamples(byte[], int, int) * @param buf Buffer where to read the samples * @return number of bytes read. */ public int readSamples(byte[] buf){ return readSamples(buf, 0, buf.length); }
return audioBuffer; }else{ AudioStream audioStream = new AudioStream(); audioStream.setupFormat(streamHdr.getChannels(), 16, streamHdr.getSampleRate()); audioStream.updateData(readToStream(oggStream.isSeekable()), streamDuration); return audioStream;
@Override public NativeObject createDestructableClone() { return new AudioStream(ids); }
private void readDataChunkForStream(int offset, int len) throws IOException { in.setResetOffset(offset); audioStream.updateData(in, duration); }