/** Compare the remaining shorts of this buffer to another short buffer's remaining shorts. * * @param otherBuffer another short buffer. * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value * if this is greater than {@code otherBuffer}. * @exception ClassCastException if {@code otherBuffer} is not a short buffer. * @since Android 1.0 */ public int compareTo (ShortBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; short thisByte, otherByte; while (compareRemaining > 0) { thisByte = get(thisPos); otherByte = otherBuffer.get(otherPos); if (thisByte != otherByte) { return thisByte < otherByte ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } return remaining() - otherBuffer.remaining(); }
/** Compare the remaining shorts of this buffer to another short buffer's remaining shorts. * * @param otherBuffer another short buffer. * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value * if this is greater than {@code otherBuffer}. * @exception ClassCastException if {@code otherBuffer} is not a short buffer. * @since Android 1.0 */ public int compareTo (ShortBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; short thisByte, otherByte; while (compareRemaining > 0) { thisByte = get(thisPos); otherByte = otherBuffer.get(otherPos); if (thisByte != otherByte) { return thisByte < otherByte ? -1 : 1; } thisPos++; otherPos++; compareRemaining--; } return remaining() - otherBuffer.remaining(); }
/** Checks whether this short buffer is equal to another object. * <p> * If {@code other} is not a short buffer then {@code false} is returned. Two short buffers are equal if and only if their * remaining shorts are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this short buffer. * @return {@code true} if this short buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof ShortBuffer)) { return false; } ShortBuffer otherBuffer = (ShortBuffer)other; if (remaining() != otherBuffer.remaining()) { return false; } int myPosition = position; int otherPosition = otherBuffer.position; boolean equalSoFar = true; while (equalSoFar && (myPosition < limit)) { equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); } return equalSoFar; }
/** Checks whether this short buffer is equal to another object. * <p> * If {@code other} is not a short buffer then {@code false} is returned. Two short buffers are equal if and only if their * remaining shorts are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this short buffer. * @return {@code true} if this short buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof ShortBuffer)) { return false; } ShortBuffer otherBuffer = (ShortBuffer)other; if (remaining() != otherBuffer.remaining()) { return false; } int myPosition = position; int otherPosition = otherBuffer.position; boolean equalSoFar = true; while (equalSoFar && (myPosition < limit)) { equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); } return equalSoFar; }
/** * Take all of the remaining shorts from the buffer and return them in an array. * * @param buffer the buffer to read * @return the shorts */ public static short[] take(ShortBuffer buffer) { final short[] shorts = new short[buffer.remaining()]; buffer.get(shorts); return shorts; }
/** Writes all the remaining shorts of the {@code src} short buffer to this buffer's current position, and increases both * buffers' position by the number of shorts copied. * * @param src the source short buffer. * @return this buffer. * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}. * @exception IllegalArgumentException if {@code src} is this buffer. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (ShortBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } short[] contents = new short[src.remaining()]; src.get(contents); put(contents); return this; }
/** Writes all the remaining shorts of the {@code src} short buffer to this buffer's current position, and increases both * buffers' position by the number of shorts copied. * * @param src the source short buffer. * @return this buffer. * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}. * @exception IllegalArgumentException if {@code src} is this buffer. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (ShortBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } short[] contents = new short[src.remaining()]; src.get(contents); put(contents); return this; }
/** * Gets available output, outputting to the start of {@code buffer}. The buffer's position will be * advanced by the number of bytes written. * * @param buffer A {@link ShortBuffer} into which output will be written. */ public void getOutput(ShortBuffer buffer) { int framesToRead = Math.min(buffer.remaining() / channelCount, outputFrameCount); buffer.put(outputBuffer, 0, framesToRead * channelCount); outputFrameCount -= framesToRead; System.arraycopy( outputBuffer, framesToRead * channelCount, outputBuffer, 0, outputFrameCount * channelCount); }
/** Writes shorts from the given short array, starting from the specified offset, to the current position and increases the * position by the number of shorts written. * * @param src the source short array. * @param off the offset of short array, must not be negative and not greater than {@code src.length}. * @param len the number of shorts to write, must be no less than zero and not greater than {@code src.length - off}. * @return this buffer. * @exception BufferOverflowException if {@code remaining()} is less than {@code len}. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (short[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } for (int i = off; i < off + len; i++) { put(src[i]); } return this; }
/** Reads shorts from the current position into the specified short array, starting from the specified offset, and increases the * position by the number of shorts read. * * @param dest the target short array. * @param off the offset of the short array, must not be negative and not greater than {@code dest.length}. * @param len the number of shorts to read, must be no less than zero and not greater than {@code dest.length - off}. * @return this buffer. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
/** Reads shorts from the current position into the specified short array, starting from the specified offset, and increases the * position by the number of shorts read. * * @param dest the target short array. * @param off the offset of the short array, must not be negative and not greater than {@code dest.length}. * @param len the number of shorts to read, must be no less than zero and not greater than {@code dest.length - off}. * @return this buffer. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}. * @since Android 1.0 */ public ShortBuffer get (short[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = off; i < off + len; i++) { dest[i] = get(); } return this; }
/** Writes shorts from the given short array, starting from the specified offset, to the current position and increases the * position by the number of shorts written. * * @param src the source short array. * @param off the offset of short array, must not be negative and not greater than {@code src.length}. * @param len the number of shorts to write, must be no less than zero and not greater than {@code src.length - off}. * @return this buffer. * @exception BufferOverflowException if {@code remaining()} is less than {@code len}. * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public ShortBuffer put (short[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } for (int i = off; i < off + len; i++) { put(src[i]); } return this; }
/** * Queues remaining data from {@code buffer}, and advances its position by the number of bytes * consumed. * * @param buffer A {@link ShortBuffer} containing input data between its position and limit. */ public void queueInput(ShortBuffer buffer) { int framesToWrite = buffer.remaining() / channelCount; int bytesToWrite = framesToWrite * channelCount * 2; inputBuffer = ensureSpaceForAdditionalFrames(inputBuffer, inputFrameCount, framesToWrite); buffer.get(inputBuffer, inputFrameCount * channelCount, bytesToWrite / 2); inputFrameCount += framesToWrite; processStreamInput(); }
public void setIndices (ShortBuffer indices) { int pos = indices.position(); buffer.clear(); buffer.limit(indices.remaining()); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); }
public void setIndices (ShortBuffer indices) { int pos = indices.position(); buffer.clear(); buffer.limit(indices.remaining()); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); }
public short[] getA2( ) { _arys++; int len = getInt(); if( len == -1 ) return null; short[] buf = MemoryManager.malloc2(len); int sofar = 0; while( sofar < buf.length ) { ShortBuffer as = _bb.asShortBuffer(); int more = Math.min(as.remaining(), len - sofar); as.get(buf, sofar, more); sofar += more; _bb.position(_bb.position() + as.position()*2); if( sofar < len ) getSp(Math.min(_bb.capacity()-1, (len-sofar)*2)); } return buf; }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }