Java Code Examples for java.nio.ShortBuffer#get()

The following examples show how to use java.nio.ShortBuffer#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteBufferViews.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "shortViewProvider")
public void testShortGet(String desc, IntFunction<ByteBuffer> fbb,
                         Function<ByteBuffer, ShortBuffer> fbi) {
    ByteBuffer bb = allocate(fbb);
    ShortBuffer vb = fbi.apply(bb);
    int o = bb.position();

    for (int i = 0; i < vb.limit(); i++) {
        short fromBytes = getShortFromBytes(bb, o + i * 2);
        short fromMethodView = bb.getShort(o + i * 2);
        assertValues(i, fromBytes, fromMethodView, bb);

        short fromBufferView = vb.get(i);
        assertValues(i, fromMethodView, fromBufferView, bb, vb);
    }

    for (int i = 0; i < vb.limit(); i++) {
        short v = getShortFromBytes(bb, o + i * 2);
        short a = bb.getShort();
        assertValues(i, v, a, bb);

        short b = vb.get();
        assertValues(i, a, b, bb, vb);
    }

}
 
Example 2
Source File: Mesh.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3) {
	VertexBuffer pb = getBuffer(Type.Position);
	VertexBuffer ib = getBuffer(Type.Index);

	if (pb.getFormat() == Format.Float) {
		FloatBuffer fpb = (FloatBuffer) pb.getData();

		if (ib.getFormat() == Format.UnsignedShort) {
			// accepted format for buffers
			ShortBuffer sib = (ShortBuffer) ib.getData();

			// aquire triangle's vertex indices
			int vertIndex = index * 3;
			int vert1 = sib.get(vertIndex);
			int vert2 = sib.get(vertIndex + 1);
			int vert3 = sib.get(vertIndex + 2);

			BufferUtils.populateFromBuffer(v1, fpb, vert1);
			BufferUtils.populateFromBuffer(v2, fpb, vert2);
			BufferUtils.populateFromBuffer(v3, fpb, vert3);
		}
	}
}
 
Example 3
Source File: TrueTypeFont.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
    if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
        stSize = .05f;
        stPos = -.4f;
        return;
    }
    ShortBuffer sb = os_2Table.asShortBuffer();
    stSize = sb.get(13) / (float)upem;
    stPos = -sb.get(14) / (float)upem;
}
 
Example 4
Source File: TrueTypeFont.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {

    if (ulSize == 0f && ulPos == 0f) {

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
            if (upem < 16 || upem > 16384) {
                upem = 2048;
            }
        }

        ByteBuffer os2_Table = getTableBuffer(os_2Tag);
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
    }

    metrics[offset] = stPos * pointSize;
    metrics[offset+1] = stSize * pointSize;

    metrics[offset+2] = ulPos * pointSize;
    metrics[offset+3] = ulSize * pointSize;
}
 
Example 5
Source File: TrueTypeFont.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setUnderlineMetrics(ByteBuffer postTable, int upem) {
    if (postTable == null || postTable.capacity() < 12 || upem < 0) {
        ulSize = .05f;
        ulPos = .1f;
        return;
    }
    ShortBuffer sb = postTable.asShortBuffer();
    ulSize = sb.get(5) / (float)upem;
    ulPos = -sb.get(4) / (float)upem;
}
 
Example 6
Source File: Sonic.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: AudioRemixer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void remix(final ShortBuffer inSBuff, final ShortBuffer outSBuff) {
    // Down-mix stereo to mono
    // Viktor Toth's algorithm -
    // See: http://www.vttoth.com/CMS/index.php/technical-notes/68
    //      http://stackoverflow.com/a/25102339
    final int inRemaining = inSBuff.remaining() / 2;
    final int outSpace = outSBuff.remaining();

    final int samplesToBeProcessed = Math.min(inRemaining, outSpace);
    for (int i = 0; i < samplesToBeProcessed; ++i) {
        // Convert to unsigned
        final int a = inSBuff.get() + SIGNED_SHORT_LIMIT;
        final int b = inSBuff.get() + SIGNED_SHORT_LIMIT;
        int m;
        // Pick the equation
        if ((a < SIGNED_SHORT_LIMIT) || (b < SIGNED_SHORT_LIMIT)) {
            // Viktor's first equation when both sources are "quiet"
            // (i.e. less than middle of the dynamic range)
            m = a * b / SIGNED_SHORT_LIMIT;
        } else {
            // Viktor's second equation when one or both sources are loud
            m = 2 * (a + b) - (a * b) / SIGNED_SHORT_LIMIT - UNSIGNED_SHORT_MAX;
        }
        // Convert output back to signed short
        if (m == UNSIGNED_SHORT_MAX + 1) m = UNSIGNED_SHORT_MAX;
        outSBuff.put((short) (m - SIGNED_SHORT_LIMIT));
    }
}
 
Example 8
Source File: FloatingPoint.java    From jhdf with MIT License 5 votes vote down vote up
private static void fillData(Object data, int[] dims, ShortBuffer buffer) {
    if (dims.length > 1) {
        for (int i = 0; i < dims[0]; i++) {
            Object newArray = Array.get(data, i);
            fillData(newArray, stripLeadingIndex(dims), buffer);
        }
    } else {
        float[] floatData = (float[]) data;
        for (int i = 0; i < dims[0]; i++) {
            short element = buffer.get();
            floatData[i] = toFloat(element);
        }
    }
}
 
Example 9
Source File: TrueTypeFont.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {

    if (ulSize == 0f && ulPos == 0f) {

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
            if (upem < 16 || upem > 16384) {
                upem = 2048;
            }
        }

        ByteBuffer os2_Table = getTableBuffer(os_2Tag);
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
    }

    metrics[offset] = stPos * pointSize;
    metrics[offset+1] = stSize * pointSize;

    metrics[offset+2] = ulPos * pointSize;
    metrics[offset+3] = ulSize * pointSize;
}
 
Example 10
Source File: TrueTypeFont.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {

    if (ulSize == 0f && ulPos == 0f) {

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
            if (upem < 16 || upem > 16384) {
                upem = 2048;
            }
        }

        ByteBuffer os2_Table = getTableBuffer(os_2Tag);
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
    }

    metrics[offset] = stPos * pointSize;
    metrics[offset+1] = stSize * pointSize;

    metrics[offset+2] = ulPos * pointSize;
    metrics[offset+3] = ulSize * pointSize;
}
 
Example 11
Source File: FixedPoint.java    From jhdf with MIT License 5 votes vote down vote up
private static void fillData(Object data, int[] dims, ShortBuffer buffer) {
	if (dims.length > 1) {
		for (int i = 0; i < dims[0]; i++) {
			Object newArray = Array.get(data, i);
			fillData(newArray, stripLeadingIndex(dims), buffer);
		}
	} else {
		buffer.get((short[]) data);
	}
}
 
Example 12
Source File: TrueTypeFont.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setUnderlineMetrics(ByteBuffer postTable, int upem) {
    if (postTable == null || postTable.capacity() < 12 || upem < 0) {
        ulSize = .05f;
        ulPos = .1f;
        return;
    }
    ShortBuffer sb = postTable.asShortBuffer();
    ulSize = sb.get(5) / (float)upem;
    ulPos = -sb.get(4) / (float)upem;
}
 
Example 13
Source File: Sonic.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 14
Source File: TrueTypeFont.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void initAllNames(int requestedID, HashSet names) {

        byte[] name = new byte[256];
        ByteBuffer buffer = getTableBuffer(nameTag);

        if (buffer != null) {
            ShortBuffer sbuffer = buffer.asShortBuffer();
            sbuffer.get(); // format - not needed.
            short numRecords = sbuffer.get();

            /* The name table uses unsigned shorts. Many of these
             * are known small values that fit in a short.
             * The values that are sizes or offsets into the table could be
             * greater than 32767, so read and store those as ints
             */
            int stringPtr = ((int) sbuffer.get()) & 0xffff;
            for (int i=0; i<numRecords; i++) {
                short platformID = sbuffer.get();
                if (platformID != MS_PLATFORM_ID) {
                    sbuffer.position(sbuffer.position()+5);
                    continue; // skip over this record.
                }
                short encodingID = sbuffer.get();
                short langID     = sbuffer.get();
                short nameID     = sbuffer.get();
                int   nameLen    = ((int) sbuffer.get()) & 0xffff;
                int   namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;

                if (nameID == requestedID) {
                    buffer.position(namePtr);
                    buffer.get(name, 0, nameLen);
                    names.add(makeString(name, nameLen, encodingID));
                }
            }
        }
    }
 
Example 15
Source File: AudioRemixer.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
@Override
public void remix(final ShortBuffer inSBuff, final ShortBuffer outSBuff) {
    // Up-mix mono to stereo
    final int inRemaining = inSBuff.remaining();
    final int outSpace = outSBuff.remaining() / 2;

    final int samplesToBeProcessed = Math.min(inRemaining, outSpace);
    for (int i = 0; i < samplesToBeProcessed; ++i) {
        final short inSample = inSBuff.get();
        outSBuff.put(inSample);
        outSBuff.put(inSample);
    }
}
 
Example 16
Source File: ChannelCountPcmAudioFilter.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private void processMonoToStereo(ShortBuffer buffer) throws InterruptedException {
  while (buffer.hasRemaining()) {
    short sample = buffer.get();
    outputBuffer.put(sample);
    outputBuffer.put(sample);

    if (!outputBuffer.hasRemaining()) {
      outputBuffer.flip();
      downstream.process(outputBuffer);
      outputBuffer.clear();
    }
  }
}
 
Example 17
Source File: PcmVolumeProcessor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private void unapplyCurrentVolume(ShortBuffer buffer) {
  if (integerMultiplier == 0) {
    return;
  }

  int endOffset = buffer.limit();

  for (int i = buffer.position(); i < endOffset; i++) {
    int value = buffer.get(i) * 10000 / integerMultiplier;
    buffer.put(i, (short) Math.max(-32767, Math.min(32767, value)));
  }
}
 
Example 18
Source File: Sonic.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 19
Source File: TrueTypeFont.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected String lookupName(short findLocaleID, int findNameID) {
    String foundName = null;
    byte[] name = new byte[1024];

    ByteBuffer buffer = getTableBuffer(nameTag);
    if (buffer != null) {
        ShortBuffer sbuffer = buffer.asShortBuffer();
        sbuffer.get(); // format - not needed.
        short numRecords = sbuffer.get();

        /* The name table uses unsigned shorts. Many of these
         * are known small values that fit in a short.
         * The values that are sizes or offsets into the table could be
         * greater than 32767, so read and store those as ints
         */
        int stringPtr = ((int) sbuffer.get()) & 0xffff;

        for (int i=0; i<numRecords; i++) {
            short platformID = sbuffer.get();
            if (platformID != MS_PLATFORM_ID) {
                sbuffer.position(sbuffer.position()+5);
                continue; // skip over this record.
            }
            short encodingID = sbuffer.get();
            short langID     = sbuffer.get();
            short nameID     = sbuffer.get();
            int   nameLen    = ((int) sbuffer.get()) & 0xffff;
            int   namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;
            if (nameID == findNameID &&
                ((foundName == null && langID == ENGLISH_LOCALE_ID)
                 || langID == findLocaleID)) {
                buffer.position(namePtr);
                buffer.get(name, 0, nameLen);
                foundName = makeString(name, nameLen, encodingID);
                if (langID == findLocaleID) {
                    return foundName;
                }
            }
        }
    }
    return foundName;
}
 
Example 20
Source File: TrueTypeFont.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
protected String lookupName(short findLocaleID, int findNameID) {
    String foundName = null;
    byte[] name = new byte[1024];

    ByteBuffer buffer = getTableBuffer(nameTag);
    if (buffer != null) {
        ShortBuffer sbuffer = buffer.asShortBuffer();
        sbuffer.get(); // format - not needed.
        short numRecords = sbuffer.get();

        /* The name table uses unsigned shorts. Many of these
         * are known small values that fit in a short.
         * The values that are sizes or offsets into the table could be
         * greater than 32767, so read and store those as ints
         */
        int stringPtr = ((int) sbuffer.get()) & 0xffff;

        for (int i=0; i<numRecords; i++) {
            short platformID = sbuffer.get();
            if (platformID != MS_PLATFORM_ID) {
                sbuffer.position(sbuffer.position()+5);
                continue; // skip over this record.
            }
            short encodingID = sbuffer.get();
            short langID     = sbuffer.get();
            short nameID     = sbuffer.get();
            int   nameLen    = ((int) sbuffer.get()) & 0xffff;
            int   namePtr    = (((int) sbuffer.get()) & 0xffff) + stringPtr;
            if (nameID == findNameID &&
                ((foundName == null && langID == ENGLISH_LOCALE_ID)
                 || langID == findLocaleID)) {
                buffer.position(namePtr);
                buffer.get(name, 0, nameLen);
                foundName = makeString(name, nameLen, platformID, encodingID);
                if (langID == findLocaleID) {
                    return foundName;
                }
            }
        }
    }
    return foundName;
}