本文整理汇总了Java中java.nio.ByteBuffer.asShortBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.asShortBuffer方法的具体用法?Java ByteBuffer.asShortBuffer怎么用?Java ByteBuffer.asShortBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.asShortBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drainDecoderBufferAndQueue
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void drainDecoderBufferAndQueue(final int bufferIndex, final long presentationTimeUs) {
if (mActualDecodedFormat == null) {
throw new RuntimeException("Buffer received before format!");
}
final ByteBuffer data = bufferIndex == BUFFER_INDEX_END_OF_STREAM ? null : MediaUtil.getOutputBuffer(mDecoder, bufferIndex);
AudioBuffer buffer = mEmptyBuffers.poll();
if (buffer == null) {
buffer = new AudioBuffer();
}
buffer.bufferIndex = bufferIndex;
buffer.presentationTimeUs = presentationTimeUs;
buffer.data = data == null ? null : data.asShortBuffer();
if (mOverflowBuffer.data == null) {
mOverflowBuffer.data = ByteBuffer
.allocateDirect(data.capacity())
.order(ByteOrder.nativeOrder())
.asShortBuffer();
mOverflowBuffer.data.clear().flip();
}
mFilledBuffers.add(buffer);
}
示例2: Cube
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public Cube(float width, float height, float depth) {
ByteBuffer vByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
vByteBuffer.order(ByteOrder.nativeOrder());
mVertexBuffer = vByteBuffer.asFloatBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
ByteBuffer iByteBuffer = ByteBuffer.allocateDirect(indices.length * 2);
iByteBuffer.order(ByteOrder.nativeOrder());
mIndexBuffer = iByteBuffer.asShortBuffer();
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
ByteBuffer cByteBuffer = ByteBuffer.allocateDirect(colors.length * 4);
cByteBuffer.order(ByteOrder.nativeOrder());
mColorBuffer = cByteBuffer.asFloatBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);
this.width = width / 2;
this.height = height / 2;
this.depth = depth / 2;
}
示例3: setUpBuffers
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void setUpBuffers() {
indices = new short[6];
indices = new short[]{0, 1, 2, 0, 2, 3};
ByteBuffer dlb = ByteBuffer.allocateDirect(indices.length * 2);
dlb.order(ByteOrder.nativeOrder());
drawListBuffer = dlb.asShortBuffer();
drawListBuffer.put(indices);
drawListBuffer.position(0);
uvs = new float[]{
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f
};
ByteBuffer bb = ByteBuffer.allocateDirect(uvs.length * 4);
bb.order(ByteOrder.nativeOrder());
uvBuffer = bb.asFloatBuffer();
uvBuffer.put(uvs);
uvBuffer.position(0);
}
示例4: convertAudioBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Convert the audio bytes into the stream
*
* @param format The audio format being decoded
* @param audio_bytes The audio byts
* @param two_bytes_data True if we using double byte data
* @return The byte bufer of data
*/
private static ByteBuffer convertAudioBytes(AudioFormat format, byte[] audio_bytes, boolean two_bytes_data) {
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
dest.order(ByteOrder.nativeOrder());
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
src.order(ByteOrder.BIG_ENDIAN);
if (two_bytes_data) {
ShortBuffer dest_short = dest.asShortBuffer();
ShortBuffer src_short = src.asShortBuffer();
while (src_short.hasRemaining())
dest_short.put(src_short.get());
} else {
while (src.hasRemaining()) {
byte b = src.get();
if (format.getEncoding() == Encoding.PCM_SIGNED) {
b = (byte) (b + 127);
}
dest.put(b);
}
}
dest.rewind();
return dest;
}
示例5: convertAudioBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data, ByteOrder order) {
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
dest.order(ByteOrder.nativeOrder());
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
src.order(order);
if (two_bytes_data) {
ShortBuffer dest_short = dest.asShortBuffer();
ShortBuffer src_short = src.asShortBuffer();
while (src_short.hasRemaining())
dest_short.put(src_short.get());
} else {
while (src.hasRemaining())
dest.put(src.get());
}
dest.rewind();
return dest;
}
示例6: Init
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void Init( float x, float y, float z) {
ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
vbb.order(ByteOrder.nativeOrder());
mFVertexBuffer = vbb.asFloatBuffer();
ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
ibb.order(ByteOrder.nativeOrder());
mIndexBuffer = ibb.asShortBuffer();
mZ = z; // planar object
int n = 0;
for (int i=0; i<VERTS; i++) {
mFVertexBuffer.put( COORDS[n++] + x);
mFVertexBuffer.put( COORDS[n++] + y);
mFVertexBuffer.put( COORDS[n++] + z);
}
for(int i = 0; i < VERTS; i++) {
mIndexBuffer.put((short) i);
}
mFVertexBuffer.position(0);
mIndexBuffer.position(0);
}
示例7: Init
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void Init( float w, float h, float x, float y, float z ) {
mWidth = w;
mHeight = h;
ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
vbb.order(ByteOrder.nativeOrder());
mFVertexBuffer = vbb.asFloatBuffer();
ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
ibb.order(ByteOrder.nativeOrder());
mIndexBuffer = ibb.asShortBuffer();
int n = 0;
for (int i=0; i<VERTS; i++) {
mFVertexBuffer.put( COORDS[n++]*mWidth + x);
mFVertexBuffer.put( COORDS[n++]*mHeight + y);
mFVertexBuffer.put( COORDS[n++] + z);
}
for(int i = 0; i < VERTS; i++) {
mIndexBuffer.put((short) i);
}
ByteBuffer cbb = ByteBuffer.allocateDirect(COLORS.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(COLORS);
mFVertexBuffer.position(0);
mIndexBuffer.position(0);
mColorBuffer.position(0);
}
示例8: testGetShortInt
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testGetShortInt() {
ByteBuffer bb = ByteBuffer.allocate(10);
ShortBuffer sb = bb.asShortBuffer();
sb.put((short) 0x1110);
sb.put((short) 0x2220);
sb.put((short) 0x3330);
sb.put((short) 0x4440);
sb.put((short) 0x5550);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
short s = bs.getShort(0);
assertEquals(0x1110, s);
assertEquals(3, bs.position());
s = bs.getShort(2);
assertEquals(0x2220, s);
assertEquals(3, bs.position());
s = bs.getShort(8);
assertEquals(0x5550, s);
assertEquals(3, bs.position());
try {
bs.getShort(9);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
示例9: setStrikethroughMetrics
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例10: TextureRenderer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public TextureRenderer(boolean isOesTexture) {
mOesTexture = isOesTexture;
ByteBuffer bb = ByteBuffer.allocateDirect(squareVertices.length * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(squareVertices);
vertexBuffer.position(0);
ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 2);
dlb.order(ByteOrder.nativeOrder());
drawListBuffer = dlb.asShortBuffer();
drawListBuffer.put(drawOrder);
drawListBuffer.position(0);
ByteBuffer bb2 = ByteBuffer.allocateDirect(textureVertices.length * 4);
bb2.order(ByteOrder.nativeOrder());
textureVerticesBuffer = bb2.asFloatBuffer();
textureVerticesBuffer.put(textureVertices);
textureVerticesBuffer.position(0);
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, mVertexShader);
int fragmentShader;
if (mOesTexture) {
fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, mFragmentShaderOes);
} else {
fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, mFragmentShaderRgba);
}
mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES Program
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
GLES20.glLinkProgram(mProgram);
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
Matrix.setIdentityM(mMVPMatrix, 0);
Matrix.setIdentityM(mSTMatrix, 0);
}
示例11: ShortBufferUtil
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ShortBuffer ShortBufferUtil(short[] arr) {
ByteBuffer dlb = ByteBuffer.allocateDirect(arr.length * 2);
dlb.order(ByteOrder.nativeOrder());
ShortBuffer buffer = dlb.asShortBuffer();
buffer.put(arr);
buffer.position(0);
return buffer;
}
示例12: getStyleMetrics
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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;
}
示例13: setUp
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
float[] normals = {
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f
};
float[] vertices = {
0.0f, 0.0f, 0.0f, // top left
0.0f, -1.0f, 0.0f, // bottom left
1.0f, -1.0f, 0.0f, // bottom right
1.0f, 0.0f, 0.0f // top right
};
short[] indices = {
0, 1, 2, 0, 2, 3
};
ByteBuffer nbb = ByteBuffer.allocateDirect(normals.length * 4);
nbb.order(ByteOrder.nativeOrder());
normalBuffer = nbb.asFloatBuffer();
normalBuffer.put(normals);
normalBuffer.position(0);
ByteBuffer bb = ByteBuffer.allocateDirect(vertices.length * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuffer = bb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer dlb = ByteBuffer.allocateDirect(indices.length * 2);
dlb.order(ByteOrder.nativeOrder());
indexBuffer = dlb.asShortBuffer();
indexBuffer.put(indices);
indexBuffer.position(0);
}
示例14: main
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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();
}
}
示例15: draw
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* same as draw in a Sprite but doesn't render a texture
* @param gl
*/
@Override
public void draw(GL10 gl) {
textureCoordinates = Alignment.getVertices(this, Alignment.LEFT_TOP);
ByteBuffer byteBuf = ByteBuffer.allocateDirect(textureCoordinates.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
mTextureBuffer = byteBuf.asFloatBuffer();
mTextureBuffer.put(textureCoordinates);
mTextureBuffer.position(0);
float vertices[] = Alignment.getVertices(this, Alignment.LEFT_TOP);
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
ibb.order(ByteOrder.nativeOrder());
indexBuffer = ibb.asShortBuffer();
indexBuffer.put(indices);
indexBuffer.position(0);
gl.glEnable(GL_BLEND);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4f(red / 100, green / 100, blue / 100, alpha / 100);
gl.glFrontFace(GL10.GL_CCW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
}