public static ByteBuffer newByteBuffer (int numBytes) { ByteBuffer buffer = ByteBuffer.allocateDirect(numBytes); buffer.order(ByteOrder.nativeOrder()); return buffer; }
public static FloatBuffer newFloatBuffer (int numFloats) { ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4); buffer.order(ByteOrder.nativeOrder()); return buffer.asFloatBuffer(); }
private void putNativeOrderLong(List<byte[]> initializationData, int samples) { long ns = (samples * C.NANOS_PER_SECOND) / SAMPLE_RATE; byte[] array = ByteBuffer.allocate(8).order(ByteOrder.nativeOrder()).putLong(ns).array(); initializationData.add(array); }
@MarshalsArray public static FloatBuffer toFloatBuffer(Class<?> cls, long handle, long flags, int d1) { return VM.newDirectByteBuffer(handle, d1 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); } @MarshalsArray
public static ByteBuffer newByteBuffer (int numBytes) { ByteBuffer buffer = ByteBuffer.allocateDirect(numBytes); buffer.order(ByteOrder.nativeOrder()); return buffer; }
public static FloatBuffer newFloatBuffer (int numFloats) { ByteBuffer buffer = ByteBuffer.allocateDirect(numFloats * 4); buffer.order(ByteOrder.nativeOrder()); return buffer.asFloatBuffer(); }
ByteBuffer getBuffer() { if (buffer == null) { buffer = ByteBuffer.wrap(array).order(ByteOrder.nativeOrder()); } return buffer; }
/** * Returns a {@link FloatBuffer} which reads and writes to the same memory * location pointed to by this {@link FloatPtr}. * * @param n the maximum number of floats the {@link FloatBuffer} can * read/write. This will be the {@link FloatBuffer}'s * <code>capacity</code>. * @return the {@link FloatBuffer}. */ public FloatBuffer asFloatBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); }
public static ShortBuffer newShortBuffer (int numShorts) { ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2); buffer.order(ByteOrder.nativeOrder()); return buffer.asShortBuffer(); }
/** Allocates a FloatBuffer with the given data. */ public static FloatBuffer createBuffer(float[] data) { ByteBuffer bb = ByteBuffer.allocateDirect(data.length * C.BYTES_PER_FLOAT); bb.order(ByteOrder.nativeOrder()); FloatBuffer buffer = bb.asFloatBuffer(); buffer.put(data); buffer.position(0); return buffer; }
/** * @param currTail Current tail. * @param newTail New tail. * @param wrapPnt Wrap point. */ private WriteSegment(long currTail, long newTail, long wrapPnt) { super(allocate((int)(newTail - currTail)), newTail); this.seg.order(ByteOrder.nativeOrder()); this.currTail = currTail; this.wrapPnt = wrapPnt; }
/** * Create a new FloatBuffer of the specified size. * * @param size * required number of floats to store. * @return the new FloatBuffer */ public static FloatBuffer createFloatBuffer(int size) { FloatBuffer buf = allocator.allocate(4 * size).order(ByteOrder.nativeOrder()).asFloatBuffer(); buf.clear(); onBufferAllocated(buf); return buf; }
public static IntBuffer newIntBuffer (int numInts) { ByteBuffer buffer = ByteBuffer.allocateDirect(numInts * 4); buffer.order(ByteOrder.nativeOrder()); return buffer.asIntBuffer(); }
static FloatBuffer allocateDirect(int size) { return ByteBuffer.allocateDirect(size * Float.BYTES) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); } }
/** Write to an ever-expanding byte[]. Instead of calling {@link #close()}, * call {@link #buf()} to retrieve the final byte[]. */ public AutoBuffer( ) { _bb = ByteBuffer.wrap(new byte[16]).order(ByteOrder.nativeOrder()); _chan = null; _h2o = null; _read = false; _firstPage = true; _persist = 0; // No persistance }
fromView.order(ByteOrder.nativeOrder()); toView.order(ByteOrder.nativeOrder()); switch (bufferType) { case INT: FloatBuffer fromFloat = fromView.asFloatBuffer(); FloatBuffer toFloat = toView.asFloatBuffer(); for (int i = 0; i < n; i++) { float put = fromFloat.get(fromOffset + i * fromStride);
public static LongBuffer newLongBuffer (int numLongs) { ByteBuffer buffer = ByteBuffer.allocateDirect(numLongs * 8); buffer.order(ByteOrder.nativeOrder()); return buffer.asLongBuffer(); }
private static FloatBuffer nativeFloatBuffer(float... array) { FloatBuffer buffer = ByteBuffer.allocateDirect(array.length * 4).order( ByteOrder.nativeOrder()).asFloatBuffer(); buffer.put(array); buffer.flip(); return buffer; }
/** Read from a fixed byte[]; should not be closed. */ AutoBuffer( byte[] buf, int off ) { assert buf != null : "null fed to ByteBuffer.wrap"; _bb = ByteBuffer.wrap(buf).order(ByteOrder.nativeOrder()); _bb.position(off); _chan = null; _h2o = null; _read = true; _firstPage = true; _persist = 0; // No persistance }
@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); } }