Example usage for java.nio FloatBuffer put

List of usage examples for java.nio FloatBuffer put

Introduction

In this page you can find the example usage for java.nio FloatBuffer put.

Prototype

public FloatBuffer put(float[] src, int off, int len) 

Source Link

Document

Writes floats from the given float array, starting from the specified offset, to the current position and increases the position by the number of floats written.

Usage

From source file:Main.java

public static void main(String[] args) {
    FloatBuffer floatBuffer = FloatBuffer.allocate(10);

    floatBuffer.put(new float[] { 1.23F, 2.13F, 3.13F, 2.13F, }, 0, 2);

    System.out.println(Arrays.toString(floatBuffer.array()));

}

From source file:Main.java

/**
 * Copy with JNI for devices prior GINGERBREAD(api 9), put for newer versions(HTC Sensation has faster put(float[]) )  
 *///from  w  w w .jav  a  2  s .c om
public static void copyFloats(float[] src, int srcOffset, FloatBuffer dst, int numElements) {
    if (Build.VERSION.SDK_INT >= 9) {
        dst.put(src, srcOffset, numElements);
    } else {
        //com.badlogic.gdx.utils.BufferUtils.copy(src, srcOffset, dst, numElements);

    }
}

From source file:Main.java

public static FloatBuffer replaceFloats(int destPos, FloatBuffer dest, int srcPos, float... src) {
    dest.position(destPos);//w ww. ja  v a  2 s .c  om
    dest.put(src, srcPos, src.length - srcPos);
    dest.position(0);
    return dest;
}

From source file:BufferTest.java

private long bulkPut(float[] data, int elements, FloatBuffer target, int testTime) {
    long start = System.currentTimeMillis();
    long elapsed = 0;
    int reps = 0;

    target.clear();/*from   ww  w.  ja v a 2s.com*/

    do {
        target.put(data, 0, elements);
        target.flip();

        reps++;
        elapsed = System.currentTimeMillis() - start;
    } while (elapsed < testTime);

    long bytes = (long) elements * (long) reps * 4;

    return bytes / elapsed / 1024;
}

From source file:InterleavedNIOBuffer.java

void createInterleavedBuffers() {
    int size;/*from w  w w. ja  v a2  s .  c  o  m*/
    ByteOrder order = ByteOrder.nativeOrder();

    size = (2 + 2 + 3 + 3) * 3 * 4;
    FloatBuffer vertex = ByteBuffer.allocateDirect(size * 4).order(order).asFloatBuffer();
    vertex.put(interleaved, 0, size);
    interleavedBuffer = new J3DBuffer(vertex);

    size = (2 + 2 + 3 + 3) * 4;
    FloatBuffer indexedVertex = ByteBuffer.allocateDirect(size * 4).order(order).asFloatBuffer();
    indexedVertex.put(indexedInterleaved, 0, size);
    indexedInterleavedBuffer = new J3DBuffer(indexedVertex);
}

From source file:GeometryByReferenceNIOBuffer.java

void createJ3DBuffers() {
    int i;//from w  w  w  .j av a 2 s.  co  m
    ByteOrder order = ByteOrder.nativeOrder();

    FloatBuffer coord = ByteBuffer.allocateDirect(36 * 4).order(order).asFloatBuffer();
    coord.put(floatVerts, 0, 36);
    floatBufferCoord = new J3DBuffer(coord);

    FloatBuffer color = ByteBuffer.allocateDirect(36 * 4).order(order).asFloatBuffer();
    color.put(floatClrs, 0, 36);
    floatBufferColor = new J3DBuffer(color);

    FloatBuffer indexedCoord = ByteBuffer.allocateDirect(12 * 4).order(order).asFloatBuffer();
    indexedCoord.put(indexedFloatVerts, 0, 12);
    indexedFloatBufferCoord = new J3DBuffer(indexedCoord);

    FloatBuffer indexedColor = ByteBuffer.allocateDirect(12 * 4).order(order).asFloatBuffer();
    indexedColor.put(indexedFloatClrs, 0, 12);
    indexedFloatBufferColor = new J3DBuffer(indexedColor);
}

From source file:uk.co.modularaudio.service.jnajackaudioprovider.JNAJackAppRenderingSession.java

private void masterOutBuffersCopyOver(final int numFrames, final int numConsumersUsed) {
    int cac = 0;/* ww w .j  a v a  2  s  . c  o  m*/
    for (; cac < numConsumersUsed; ++cac) {
        final JackPort pp = consumerAudioPorts[cac];
        final FloatBuffer fb = pp.getFloatBuffer();
        final MadChannelBuffer aucb = masterOutBuffers.audioBuffers[cac];
        fb.put(aucb.floatBuffer, 0, numFrames);
    }
    // Make sure any remaining output channels are silenced
    for (int r = cac; r < numConsumerAudioPorts; ++r) {
        final JackPort pp = consumerAudioPorts[r];
        final FloatBuffer fb = pp.getFloatBuffer();
        fb.put(emptyFloatBuffer.floatBuffer, 0, numFrames);
    }
}