/** Returns whether any more input can be provided via {@link #getNextInputBuffer(int)}. */ public boolean hasRemaining() { return buffer.hasRemaining(); } }
/** Returns whether the buffer is full. */ public boolean isFull() { Assertions.checkState(!built); return !buffer.hasRemaining(); }
value.rewind(); int ctr = 0; while (value.hasRemaining()) { ctr++; buf.append(value.get());
public boolean feedEncoder(long timeoutUs) { final boolean hasOverflow = mOverflowBuffer.data != null && mOverflowBuffer.data.hasRemaining(); if (mFilledBuffers.isEmpty() && !hasOverflow) {
@Override public boolean hasNext() { return buffer.hasRemaining(); }
public Long hash() { long hashCode = 1L; long multiplier = 1L; while (data.hasRemaining()) { multiplier *= 31L; hashCode += (data.get() + 27L) * multiplier; } data.rewind(); return hashCode; } }
@Override protected void serialize(final ShortBuffer input, final ArrayNode output) { while (input.hasRemaining()) output.add(input.get()); } }
private void processMonoToStereo(ShortBuffer buffer) throws InterruptedException { while (buffer.hasRemaining()) { short sample = buffer.get(); outputBuffer.put(sample); outputBuffer.put(sample); if (!outputBuffer.hasRemaining()) { outputBuffer.flip(); downstream.process(outputBuffer); outputBuffer.clear(); } } }
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data, ByteOrder order) { ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length); dest.order(ByteOrder.nativeOrder()); ByteBuffer src = ByteBuffer.wrap(audio_bytes); src.order(order); if (two_bytes_data) { ShortBuffer dest_short = dest.asShortBuffer(); ShortBuffer src_short = src.asShortBuffer(); while (src_short.hasRemaining()) dest_short.put(src_short.get()); } else { while (src.hasRemaining()) dest.put(src.get()); } dest.rewind(); return dest; } }
@Override public void appendBuffer(ShortBuffer buffer, ShortBuffer dataToAppend) { short[] temp = new short[Math.min(COPY_BLOCK_SIZE, dataToAppend.remaining())]; while (dataToAppend.hasRemaining()) { int nrObBytes = Math.min(temp.length, dataToAppend.remaining()); dataToAppend.get(temp, 0, nrObBytes); buffer.put(temp, 0, nrObBytes); } }
@Override public void appendBuffer(ShortBuffer buffer, ShortBuffer dataToAppend) { short[] temp = new short[Math.min(COPY_BLOCK_SIZE, dataToAppend.remaining())]; while (dataToAppend.hasRemaining()) { int nrObBytes = Math.min(temp.length, dataToAppend.remaining()); dataToAppend.get(temp, 0, nrObBytes); buffer.put(temp, 0, nrObBytes); } }
@Override String join(TypedArrayObject typedArray, String separator, StrBuilder r) { ShortBuffer data = asShortBuffer(typedArray); if (data.hasRemaining()) { while (true) { r.append(data.get()); if (!data.hasRemaining()) break; r.append(separator); } } return r.toString(); }
@Override public void copy(@Nonnull byte[] from, @Nonnull double[] to) { @Nonnull DoubleBuffer outBuffer = DoubleBuffer.wrap(to); @Nonnull FloatBuffer floatBuffer = ByteBuffer.wrap(from).asFloatBuffer(); double min = floatBuffer.get(); double max = floatBuffer.get(); double center = (max + min) / 2; double radius = (max - min) / 2; @Nonnull ShortBuffer shortBuffer = ByteBuffer.wrap(from).asShortBuffer(); shortBuffer.position(4); while (shortBuffer.hasRemaining()) { short v = shortBuffer.get(); outBuffer.put((v * radius / Short.MAX_VALUE) + center); } }
private void processNormalizer(ShortBuffer buffer) throws InterruptedException { while (buffer.hasRemaining()) { inputSet[inputIndex++] = buffer.get(); if (inputIndex == inputChannels) { outputBuffer.put(inputSet, 0, commonChannels); for (int i = 0; i < channelsToAdd; i++) { outputBuffer.put(inputSet[0]); } if (!outputBuffer.hasRemaining()) { outputBuffer.flip(); downstream.process(outputBuffer); outputBuffer.clear(); } inputIndex = 0; } } }
@Override String join(TypedArrayObject typedArray, String separator, StrBuilder r) { ShortBuffer data = asShortBuffer(typedArray); if (data.hasRemaining()) { while (true) { r.append(Short.toUnsignedInt(data.get())); if (!data.hasRemaining()) break; r.append(separator); } } return r.toString(); }
private void loadTexture(GLDrawContext gl) { try { final DataInputStream in = new DataInputStream(new BufferedInputStream(file)); int i = in.available() / 2; final int height = nextLowerPOT(Math.sqrt(i)); final int width = nextLowerPOT(i / height); // TODO: Use better buffering. final ShortBuffer data = ByteBuffer.allocateDirect(width * height * 2).order(ByteOrder.nativeOrder()).asShortBuffer(); while (data.hasRemaining()) { data.put(in.readShort()); } data.rewind(); textureIndex = gl.generateTexture(width, height, data, name); } catch (final IOException e) { e.printStackTrace(); textureIndex = null; } }
@Override public void process(ShortBuffer buffer) throws InterruptedException { while (buffer.hasRemaining()) { int chunkLength = Math.min(buffer.remaining(), BUFFER_SIZE * channelCount); for (int chunkPosition = 0; chunkPosition < chunkLength; chunkPosition++) { for (int channel = 0; channel < buffers.length; channel++) { buffers[channel][chunkPosition] = floatToShort(buffer.get()); } } downstream.process(buffers, 0, chunkLength); } }
@Override public void process(ShortBuffer buffer) throws InterruptedException { while (buffer.hasRemaining()) { int chunkLength = Math.min(buffer.remaining() / channelCount, BUFFER_SIZE); if (chunkLength == 0) { break; } for (int chunkPosition = 0; chunkPosition < chunkLength; chunkPosition++) { for (int channel = 0; channel < buffers.length; channel++) { buffers[channel][chunkPosition] = shortToFloat(buffer.get()); } } downstream.process(buffers, 0, chunkLength); } }
private void dispatch() throws InterruptedException { if (!frameBuffer.hasRemaining()) { long timecode = timecodeBase + timecodeSampleOffset * 1000 / format.sampleRate; frameBuffer.clear(); for (AudioPostProcessor postProcessor : postProcessors) { postProcessor.process(timecode, frameBuffer); } frameBuffer.clear(); timecodeSampleOffset += format.chunkSampleCount; } } }
private boolean readNearendBuffer(ShortBuffer pcm) { if (!pcm.hasRemaining()) { return true; } int remaining = pcm.remaining(); int i = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { i = mAudioRecoder.read(pcm.array(), pcm.position(), remaining, AudioRecord.READ_NON_BLOCKING); }else{ i = mAudioRecoder.read(pcm.array(), pcm.position(), remaining); } if (i < 0 || t == null) { pcm.clear(); return false; } pcm.position(pcm.position() + i); return !pcm.hasRemaining(); }