Refine search
public static ShortBuffer newShortBuffer (int numShorts) { ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2); buffer.order(ByteOrder.nativeOrder()); return buffer.asShortBuffer(); }
public static ShortBuffer newShortBuffer (int numShorts) { ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2); buffer.order(ByteOrder.nativeOrder()); return buffer.asShortBuffer(); }
byte[] bytes = {}; short[] shorts = new short[bytes.length/2]; // to turn bytes to shorts as either big endian or little endian. ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts); // to turn shorts back to bytes. byte[] bytes2 = new byte[shortsA.length * 2]; ByteBuffer.wrap(bytes2).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(shortsA);
void setup (byte[] pcm, int channels, int sampleRate) { int bytes = pcm.length - (pcm.length % (channels > 1 ? 4 : 2)); int samples = bytes / (2 * channels); duration = samples / (float)sampleRate; ByteBuffer buffer = ByteBuffer.allocateDirect(bytes); buffer.order(ByteOrder.nativeOrder()); buffer.put(pcm, 0, bytes); buffer.flip(); if (bufferID == -1) { bufferID = alGenBuffers(); alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate); } }
void setup (byte[] pcm, int channels, int sampleRate) { int bytes = pcm.length - (pcm.length % (channels > 1 ? 4 : 2)); int samples = bytes / (2 * channels); duration = samples / (float)sampleRate; ByteBuffer buffer = ByteBuffer.allocateDirect(bytes); buffer.order(ByteOrder.nativeOrder()); buffer.put(pcm, 0, bytes); buffer.flip(); if (bufferID == -1) { bufferID = alGenBuffers(); alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate); } }
void setup (byte[] pcm, int channels, int sampleRate) { int bytes = pcm.length - (pcm.length % (channels > 1 ? 4 : 2)); int samples = bytes / (2 * channels); duration = samples / (float)sampleRate; ByteBuffer buffer = ByteBuffer.allocateDirect(bytes); buffer.order(ByteOrder.nativeOrder()); buffer.put(pcm, 0, bytes); buffer.flip(); if (bufferID == -1) { bufferID = alGenBuffers(); alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate); } }
void setup (byte[] pcm, int channels, int sampleRate) { int bytes = pcm.length - (pcm.length % (channels > 1 ? 4 : 2)); int samples = bytes / (2 * channels); duration = samples / (float)sampleRate; ByteBuffer buffer = ByteBuffer.allocateDirect(bytes); buffer.order(ByteOrder.nativeOrder()); buffer.put(pcm, 0, bytes); buffer.flip(); if (bufferID == -1) { bufferID = alGenBuffers(); alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate); } }
@MarshalsArray public static ShortBuffer toShortBuffer(Class<?> cls, long handle, long flags, int d1) { return VM.newDirectByteBuffer(handle, d1 << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); } @MarshalsArray
/** * Returns a {@link ShortBuffer} which reads and writes to the same memory * location pointed to by this {@link ShortPtr}. * * @param n the maximum number of shorts the {@link ShortBuffer} can * read/write. This will be the {@link ShortBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public ShortBuffer asShortBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); }
@Override public void queueInput(ByteBuffer inputBuffer) { Assertions.checkState(sonic != null); if (inputBuffer.hasRemaining()) { ShortBuffer shortBuffer = inputBuffer.asShortBuffer(); int inputSize = inputBuffer.remaining(); inputBytes += inputSize; sonic.queueInput(shortBuffer); inputBuffer.position(inputBuffer.position() + inputSize); } int outputSize = sonic.getFramesAvailable() * channelCount * 2; if (outputSize > 0) { if (buffer.capacity() < outputSize) { buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder()); shortBuffer = buffer.asShortBuffer(); } else { buffer.clear(); shortBuffer.clear(); } sonic.getOutput(shortBuffer); outputBytes += outputSize; buffer.limit(outputSize); outputBuffer = buffer; } }
/** * Create a new ShortBuffer of the specified size. * * @param size * required number of shorts to store. * @return the new ShortBuffer */ public static ShortBuffer createShortBuffer(int size) { ShortBuffer buf = allocator.allocate(2 * size).order(ByteOrder.nativeOrder()).asShortBuffer(); buf.clear(); onBufferAllocated(buf); return buf; }
@SuppressWarnings("unchecked") public <T extends Buffer> T getAudioDataAsBuffer(Class<T> bufferType) { long dataPointer = getDataPointer(); if (bufferType == ByteBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize()); } else if (bufferType == ShortBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); } else if (bufferType == IntBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); } else if (bufferType == FloatBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getAudioDataByteSize() << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); } else { throw new UnsupportedOperationException("Buffer type not supported: " + bufferType); } }
@SuppressWarnings("unchecked") public <T extends Buffer> T getDataAsBuffer(Class<T> bufferType) { long dataPointer = getDataPointer(); if (bufferType == ByteBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getDataByteSize()); } else if (bufferType == ShortBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getDataByteSize() << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); } else if (bufferType == IntBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getDataByteSize() << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); } else if (bufferType == FloatBuffer.class) { return (T) VM.newDirectByteBuffer(dataPointer, getDataByteSize() << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); } else { throw new UnsupportedOperationException("Buffer type not supported: " + bufferType); } }
/** Returns the next buffer with size up to {@code sizeBytes}. */ public ByteBuffer getNextInputBuffer(int sizeBytes) { ByteBuffer inputBuffer = ByteBuffer.allocate(sizeBytes).order(ByteOrder.nativeOrder()); ShortBuffer inputBufferAsShortBuffer = inputBuffer.asShortBuffer(); int limit = buffer.limit(); buffer.limit(Math.min(buffer.position() + sizeBytes / 2, limit)); inputBufferAsShortBuffer.put(buffer); buffer.limit(limit); inputBuffer.limit(inputBufferAsShortBuffer.position() * 2); return inputBuffer; }
@Override public MappeableContainer getContainerAtIndex(int i) { ByteBuffer tmp = buffer.duplicate();// sad but ByteBuffer is not thread-safe so it is either a // duplicate or a lock // note that tmp will indeed be garbage-collected some time after the end of this function tmp.order(buffer.order()); tmp.position(getOffsetContainer(i)); boolean hasrun = hasRunCompression(); if (isRunContainer(i, hasrun)) { // first, we have a short giving the number of runs int nbrruns = BufferUtil.toIntUnsigned(tmp.getShort()); final ShortBuffer shortArray = tmp.asShortBuffer(); shortArray.limit(2 * nbrruns); return new MappeableRunContainer(shortArray, nbrruns); } int cardinality = getCardinality(i); final boolean isBitmap = cardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE; // if not a // runcontainer if (isBitmap) { final LongBuffer bitmapArray = tmp.asLongBuffer(); bitmapArray.limit(MappeableBitmapContainer.MAX_CAPACITY / 64); return new MappeableBitmapContainer(bitmapArray, cardinality); } else { final ShortBuffer shortArray = tmp.asShortBuffer(); shortArray.limit(cardinality); return new MappeableArrayContainer(shortArray, cardinality); } }
switch (_dtype) { case DOUBLE: { val db = bb.order(_order).asDoubleBuffer(); for (int e = 0; e < prod; e++) doubles[e] = db.get(e); val fb = bb.order(_order).asFloatBuffer(); for (int e = 0; e < prod; e++) doubles[e] = (double) fb.get(e); val sb = bb.order(_order).asShortBuffer(); for (int e = 0; e < prod; e++) doubles[e] = (double) HalfIndexer.toFloat((int) sb.get(e));
@Test public void testUpdateShortArray() throws Exception { for (int i = 0; i < 16; i++) { ByteBuffer byteBuffer = prepareByteBufferLE(i, 16); byteBuffer.put(INPUT16); long expected = getHash(byteBuffer); prepareMurmur3aChecksum(i); short[] array = new short[8]; ByteBuffer.wrap(INPUT16).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(array); murmur3a.updateShort(array); Assert.assertEquals("Alignment " + i, expected, murmur3a.getValue()); } }
public static byte[] shortToByteArray(short inShort) { byte[] bArray = new byte[2]; ByteBuffer bBuffer = ByteBuffer.wrap(bArray); bBuffer.order(ByteOrder.LITTLE_ENDIAN); ShortBuffer lBuffer = bBuffer.asShortBuffer(); lBuffer.put(inShort); return bArray; }
private void initIndices() { short[] indices = new short[(POINTS_PER_WAVE + ADDITIONAL_POINTS - 2) * COORDS_PER_VERTEX]; for (int i = 0; i < indices.length / COORDS_PER_VERTEX; i++) { indices[COORDS_PER_VERTEX * i] = 0; indices[COORDS_PER_VERTEX * i + 1] = (short) (i + 1); indices[COORDS_PER_VERTEX * i + 2] = (short) (i + 2); } ByteBuffer indicesByteBuffer = ByteBuffer.allocateDirect(indices.length * SIZE_OF_SHORT); indicesByteBuffer.order(ByteOrder.nativeOrder()); shortBuffer = indicesByteBuffer.asShortBuffer(); shortBuffer.put(indices); shortBuffer.position(0); }
private void initData(){ ByteBuffer a=ByteBuffer.allocateDirect(cubePositions.length*4); a.order(ByteOrder.nativeOrder()); vertexBuf=a.asFloatBuffer(); vertexBuf.put(cubePositions); vertexBuf.position(0); ByteBuffer b=ByteBuffer.allocateDirect(color.length*4); b.order(ByteOrder.nativeOrder()); colorBuf=b.asFloatBuffer(); colorBuf.put(color); colorBuf.position(0); ByteBuffer c=ByteBuffer.allocateDirect(index.length*2); c.order(ByteOrder.nativeOrder()); indexBuf=c.asShortBuffer(); indexBuf.put(index); indexBuf.position(0); }