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; }
@Override public String toString(){ return getClass().getSimpleName() + "[id="+id+", ch="+channels+", bits="+bitsPerSample + ", rate="+sampleRate+", duration="+getDuration()+"]"; }
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(); } } } } }
private void updateAudioBuffer(AudioBuffer ab) { int id = ab.getId(); if (ab.getId() == -1) { ib.position(0).limit(1); al.alGenBuffers(1, ib); id = ib.get(0); ab.setId(id); objManager.registerObject(ab); } ab.getData().clear(); al.alBufferData(id, convertFormat(ab), ab.getData(), ab.getData().capacity(), ab.getSampleRate()); ab.clearUpdateNeeded(); }
audioBuffer = new AudioBuffer(); audioNode = new AudioNode(audioBuffer, new AudioKey("Speaker-" + device.getName(), true, true)); audioNode.setName("Speaker-" + device.getName()); } else { audioBuffer.resetObject(); audioBuffer.setupFormat(1, 16, 16000); audioBuffer.updateData(readToBuffer(audioInputStream)); serverAppState.runCommand(new AddSpatialCommand(audioNode, device)); } catch (IOException ex) {
@Override public NativeObject createDestructableClone() { return new AudioBuffer(id); }
private void readDataChunkForBuffer(int len) throws IOException { ByteBuffer data = BufferUtils.createByteBuffer(len); byte[] buf = new byte[512]; int read = 0; while ( (read = in.read(buf)) > 0){ data.put(buf, 0, Math.min(read, data.remaining()) ); } data.flip(); audioBuffer.updateData(data); in.close(); }
public void resetObject() { id = -1; setUpdateNeeded(); }
audioData = audioStream; }else{ audioBuffer = new AudioBuffer(); audioData = audioBuffer;
private void readDataChunkForBuffer(Decoder decoder) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int length; while ((length = decoder.read(buffer)) > -1) { baos.write(buffer, 0, length); } audioBuffer.updateData(BufferUtils.createByteBuffer(baos.toByteArray())); }
private void updateAudioBuffer(AudioBuffer ab) { int id = ab.getId(); if (ab.getId() == -1) { ib.position(0).limit(1); al.alGenBuffers(1, ib); id = ib.get(0); ab.setId(id); objManager.registerObject(ab); } ab.getData().clear(); al.alBufferData(id, convertFormat(ab), ab.getData(), ab.getData().capacity(), ab.getSampleRate()); ab.clearUpdateNeeded(); }
public void resetObject() { id = -1; setUpdateNeeded(); }
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(); } } }
@Override public NativeObject createDestructableClone() { return new AudioBuffer(id); }
private void readDataChunkForBuffer(int len) throws IOException { ByteBuffer data = BufferUtils.createByteBuffer(len); byte[] buf = new byte[512]; int read = 0; while ( (read = in.read(buf)) > 0){ data.put(buf, 0, Math.min(read, data.remaining()) ); } data.flip(); audioBuffer.updateData(data); in.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(); } } } } }
@Override public String toString(){ return getClass().getSimpleName() + "[id="+id+", ch="+channels+", bits="+bitsPerSample + ", rate="+sampleRate+", duration="+getDuration()+"]"; }
public void resetObject() { id = -1; setUpdateNeeded(); }
AudioBuffer audioBuffer = new AudioBuffer(); audioBuffer.setupFormat(streamHdr.getChannels(), 16, streamHdr.getSampleRate()); audioBuffer.updateData(readToBuffer()); return audioBuffer; }else{
@Override public NativeObject createDestructableClone() { return new AudioBuffer(id); }