Search in sources :

Example 56 with ShortBuffer

use of java.nio.ShortBuffer in project android_frameworks_base by crdroidandroid.

the class DhcpPacket method checksum.

/**
     * Performs an IP checksum (used in IP header and across UDP
     * payload) on the specified portion of a ByteBuffer.  The seed
     * allows the checksum to commence with a specified value.
     */
private int checksum(ByteBuffer buf, int seed, int start, int end) {
    int sum = seed;
    int bufPosition = buf.position();
    // set position of original ByteBuffer, so that the ShortBuffer
    // will be correctly initialized
    buf.position(start);
    ShortBuffer shortBuf = buf.asShortBuffer();
    // re-set ByteBuffer position
    buf.position(bufPosition);
    short[] shortArray = new short[(end - start) / 2];
    shortBuf.get(shortArray);
    for (short s : shortArray) {
        sum += intAbs(s);
    }
    start += shortArray.length * 2;
    // see if a singleton byte remains
    if (end != start) {
        short b = buf.get(start);
        // make it unsigned
        if (b < 0) {
            b += 256;
        }
        sum += b * 256;
    }
    sum = ((sum >> 16) & 0xFFFF) + (sum & 0xFFFF);
    sum = ((sum + ((sum >> 16) & 0xFFFF)) & 0xFFFF);
    int negated = ~sum;
    return intAbs((short) negated);
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 57 with ShortBuffer

use of java.nio.ShortBuffer in project android_frameworks_base by crdroidandroid.

the class IpUtils method checksum.

/**
     * Performs an IP checksum (used in IP header and across UDP
     * payload) on the specified portion of a ByteBuffer.  The seed
     * allows the checksum to commence with a specified value.
     */
private static int checksum(ByteBuffer buf, int seed, int start, int end) {
    int sum = seed;
    final int bufPosition = buf.position();
    // set position of original ByteBuffer, so that the ShortBuffer
    // will be correctly initialized
    buf.position(start);
    ShortBuffer shortBuf = buf.asShortBuffer();
    // re-set ByteBuffer position
    buf.position(bufPosition);
    final int numShorts = (end - start) / 2;
    for (int i = 0; i < numShorts; i++) {
        sum += intAbs(shortBuf.get(i));
    }
    start += numShorts * 2;
    // see if a singleton byte remains
    if (end != start) {
        short b = buf.get(start);
        // make it unsigned
        if (b < 0) {
            b += 256;
        }
        sum += b * 256;
    }
    sum = ((sum >> 16) & 0xFFFF) + (sum & 0xFFFF);
    sum = ((sum + ((sum >> 16) & 0xFFFF)) & 0xFFFF);
    int negated = ~sum;
    return intAbs((short) negated);
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 58 with ShortBuffer

use of java.nio.ShortBuffer in project jwt by emweb.

the class WServerGLWidget method bufferDataiv.

@Override
public void bufferDataiv(WGLWidget.GLenum target, java.nio.IntBuffer buffer, WGLWidget.GLenum usage, WGLWidget.GLenum type) {
    buffer.rewind();
    ShortBuffer sb = ShortBuffer.allocate(buffer.capacity());
    for (int i = 0; i < buffer.capacity(); i++) {
        sb.put((short) buffer.get(i));
    }
    sb.rewind();
    glCtx_.glBufferData(serverGLenum(target), sb.capacity() * 2, sb, serverGLenum(usage));
    if (debug_)
        System.out.println(glCtx_.glGetError());
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 59 with ShortBuffer

use of java.nio.ShortBuffer in project lavaplayer by sedmelluq.

the class FinalPcmAudioFilter method process.

@Override
public void process(ShortBuffer buffer) throws InterruptedException {
    if (ignoredFrames > 0) {
        long skipped = Math.min(buffer.remaining(), ignoredFrames);
        buffer.position(buffer.position() + (int) skipped);
        ignoredFrames -= skipped;
    }
    ShortBuffer local = buffer.duplicate();
    while (buffer.remaining() > 0) {
        int chunk = Math.min(buffer.remaining(), frameBuffer.remaining());
        local.position(buffer.position());
        local.limit(local.position() + chunk);
        frameBuffer.put(local);
        dispatch();
        buffer.position(buffer.position() + chunk);
    }
}
Also used : ShortBuffer(java.nio.ShortBuffer)

Example 60 with ShortBuffer

use of java.nio.ShortBuffer in project twister2 by DSC-SPIDAL.

the class TestBinaryFileFormatter method main.

public static void main(String[] args) {
    Config.Builder builder = new Config.Builder();
    builder.put("input.file.path", "/home/pulasthi/git/twister2/twister2/" + "data/src/test/resources/2000.bin");
    Config txtFileConf = builder.build();
    Path path = new Path("/home/pulasthi/git/twister2/twister2/data/src/test/resources/2000.bin");
    InputFormat binaryInputFormatter = new BinaryInputFormatter(path, 2000 * Short.BYTES);
    binaryInputFormatter.configure(txtFileConf);
    int minSplits = 8;
    double expectedSum = 1.97973979E8;
    double newSum = 0.0;
    int count = 0;
    Buffer buffer = null;
    try {
        InputSplit[] inputSplits = binaryInputFormatter.createInputSplits(minSplits);
        InputSplitAssigner inputSplitAssigner = binaryInputFormatter.getInputSplitAssigner(inputSplits);
        InputSplit currentSplit;
        byte[] line = new byte[4000];
        ByteBuffer byteBuffer = ByteBuffer.allocate(4000);
        byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
        while ((currentSplit = inputSplitAssigner.getNextInputSplit(null, 0)) != null) {
            binaryInputFormatter.open(currentSplit);
            while (binaryInputFormatter.nextRecord(line) != null) {
                byteBuffer.clear();
                byteBuffer.put(line);
                byteBuffer.flip();
                buffer = byteBuffer.asShortBuffer();
                short[] shortArray = new short[2000];
                ((ShortBuffer) buffer).get(shortArray);
                for (short i : shortArray) {
                    newSum += i;
                    count++;
                }
            }
        }
        System.out.println(newSum);
        System.out.println(count);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Path(edu.iu.dsc.tws.data.fs.Path) Buffer(java.nio.Buffer) ShortBuffer(java.nio.ShortBuffer) ByteBuffer(java.nio.ByteBuffer) InputSplitAssigner(edu.iu.dsc.tws.data.fs.io.InputSplitAssigner) Config(edu.iu.dsc.tws.common.config.Config) ByteBuffer(java.nio.ByteBuffer) BinaryInputFormatter(edu.iu.dsc.tws.data.api.formatters.BinaryInputFormatter) InputFormat(edu.iu.dsc.tws.data.api.InputFormat) InputSplit(edu.iu.dsc.tws.data.fs.io.InputSplit) ShortBuffer(java.nio.ShortBuffer)

Aggregations

ShortBuffer (java.nio.ShortBuffer)227 ByteBuffer (java.nio.ByteBuffer)78 FloatBuffer (java.nio.FloatBuffer)54 IntBuffer (java.nio.IntBuffer)45 DoubleBuffer (java.nio.DoubleBuffer)23 LongBuffer (java.nio.LongBuffer)16 Test (org.junit.Test)14 Buffer (java.nio.Buffer)11 BufferOverflowException (java.nio.BufferOverflowException)11 CharBuffer (java.nio.CharBuffer)11 VertexBuffer (com.jme3.scene.VertexBuffer)8 BufferUnderflowException (java.nio.BufferUnderflowException)7 BytePointer (org.bytedeco.javacpp.BytePointer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 IOException (java.io.IOException)5 Vector3f (com.jme3.math.Vector3f)4 ArrayList (java.util.ArrayList)4 Bitmap (android.graphics.Bitmap)3 Mesh (com.jme3.scene.Mesh)3 InvalidMarkException (java.nio.InvalidMarkException)3