本文整理汇总了Java中java.nio.ShortBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:Java ShortBuffer.put方法的具体用法?Java ShortBuffer.put怎么用?Java ShortBuffer.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ShortBuffer
的用法示例。
在下文中一共展示了ShortBuffer.put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertAudioBytes
import java.nio.ShortBuffer; //导入方法依赖的package包/类
/**
* Convert the audio bytes into the stream
*
* @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(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.LITTLE_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())
dest.put(src.get());
}
dest.rewind();
return dest;
}
示例2: convertAudioBytes
import java.nio.ShortBuffer; //导入方法依赖的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;
}
示例3: drainOverflow
import java.nio.ShortBuffer; //导入方法依赖的package包/类
private long drainOverflow(final ShortBuffer outBuff) {
final ShortBuffer overflowBuff = mOverflowBuffer.data;
final int overflowLimit = overflowBuff.limit();
final int overflowSize = overflowBuff.remaining();
final long beginPresentationTimeUs = mOverflowBuffer.presentationTimeUs + sampleCountToDurationUs(overflowBuff.position(), mInputSampleRate,
mOutputChannelCount);
outBuff.clear();
// Limit overflowBuff to outBuff's capacity
overflowBuff.limit(outBuff.capacity());
// Load overflowBuff onto outBuff
outBuff.put(overflowBuff);
if (overflowSize >= outBuff.capacity()) {
// Overflow fully consumed - Reset
overflowBuff.clear().limit(0);
} else {
// Only partially consumed - Keep position & restore previous limit
overflowBuff.limit(overflowLimit);
}
return beginPresentationTimeUs;
}
示例4: getIndices
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer getIndices( int size ) {
ShortBuffer indices = cache.get(size);
if (indices == null) {
// TODO: Optimize it!
indices = ByteBuffer.
allocateDirect( size * SIZE * Short.SIZE / 8 ).
order( ByteOrder.nativeOrder() ).
asShortBuffer();
short[] values = new short[size * 6];
int pos = 0;
int limit = size * 4;
for (int ofs=0; ofs < limit; ofs += 4) {
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 1);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 3);
}
indices.put( values );
indices.position( 0 );
cache.put(size, indices);
}
return indices;
}
示例5: createShortBufferFromArray
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer createShortBufferFromArray(short[] data) {
if (data == null) {
return null;
}
ShortBuffer buff = createShortBuffer(data.length);
buff.clear();
buff.put(data);
buff.flip();
return buff;
}
示例6: shortToByteArray
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static byte[] shortToByteArray(short inShort) {
byte[] bArray = new byte[2];
ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
ShortBuffer lBuffer = bBuffer.asShortBuffer();
lBuffer.put(inShort);
return bArray;
}
示例7: testGetShortInt
import java.nio.ShortBuffer; //导入方法依赖的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) {
}
}
示例8: getOutput
import java.nio.ShortBuffer; //导入方法依赖的package包/类
/**
* Gets available output, outputting to the start of {@code buffer}. The buffer's position will be
* advanced by the number of bytes written.
*
* @param buffer A {@link ShortBuffer} into which output will be written.
*/
public void getOutput(ShortBuffer buffer) {
int samplesToRead = Math.min(buffer.remaining() / numChannels, numOutputSamples);
buffer.put(outputBuffer, 0, samplesToRead * numChannels);
numOutputSamples -= samplesToRead;
System.arraycopy(outputBuffer, samplesToRead * numChannels, outputBuffer, 0,
numOutputSamples * numChannels);
}
示例9: remix
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@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);
}
}
示例10: write32BitValue
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void write32BitValue(long value, ShortBuffer dest) {
dest.put((short) (value & 0xffff));
dest.put((short) ((value >> 16) & 0xffff));
}
示例11: remix
import java.nio.ShortBuffer; //导入方法依赖的package包/类
@Override
public void remix(final ShortBuffer inSBuff, final ShortBuffer outSBuff) {
// Passthrough
outSBuff.put(inSBuff);
}
示例12: put
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer put(ShortBuffer buf, short[] src) {
buf.put(src);
writeShortBuffer(buf);
return buf;
}
示例13: setIndexData
import java.nio.ShortBuffer; //导入方法依赖的package包/类
private void setIndexData() {
// allocate connectivity
int triCount = 2 * circleSamples * radialSamples;
ShortBuffer sib = BufferUtils.createShortBuffer(3 * triCount);
setIndices(sib);
int i;
// generate connectivity
int connectionStart = 0;
int index = 0;
for (int circleCount = 0; circleCount < circleSamples; circleCount++) {
int i0 = connectionStart;
int i1 = i0 + 1;
connectionStart += radialSamples + 1;
int i2 = connectionStart;
int i3 = i2 + 1;
for (i = 0; i < radialSamples; i++, index += 6) {
// if (true) {
sib.put((short)(i0++));
sib.put((short)(i2));
sib.put((short)(i1));
sib.put((short)(i1++));
sib.put((short)(i2++));
sib.put((short)(i3++));
// getIndexBuffer().put(i0++);
// getIndexBuffer().put(i2);
// getIndexBuffer().put(i1);
// getIndexBuffer().put(i1++);
// getIndexBuffer().put(i2++);
// getIndexBuffer().put(i3++);
// } else {
// getIndexBuffer().put(i0++);
// getIndexBuffer().put(i1);
// getIndexBuffer().put(i2);
// getIndexBuffer().put(i1++);
// getIndexBuffer().put(i3++);
// getIndexBuffer().put(i2++);
// }
}
}
}
示例14: setIndexData
import java.nio.ShortBuffer; //导入方法依赖的package包/类
/**
* sets the indices for rendering the sphere.
*/
private void setIndexData() {
// allocate connectivity
triCount = 2 * (zSamples - 2) * radialSamples;
ShortBuffer idxBuf = BufferUtils.createShortBuffer(3 * triCount);
setIndices(idxBuf);
// generate connectivity
int index = 0;
for (int iZ = 0, iZStart = 0; iZ < (zSamples - 3); iZ++) {
int i0 = iZStart;
int i1 = i0 + 1;
iZStart += (radialSamples + 1);
int i2 = iZStart;
int i3 = i2 + 1;
for (int i = 0; i < radialSamples; i++, index += 6) {
if (!interior) {
idxBuf.put((short) i0++);
idxBuf.put((short) i1);
idxBuf.put((short) i2);
idxBuf.put((short) i1++);
idxBuf.put((short) i3++);
idxBuf.put((short) i2++);
} else { // inside view
idxBuf.put((short) i0++);
idxBuf.put((short) i2);
idxBuf.put((short) i1);
idxBuf.put((short) i1++);
idxBuf.put((short) i2++);
idxBuf.put((short) i3++);
}
}
}
// south pole triangles
for (int i = 0; i < radialSamples; i++, index += 3) {
if (!interior) {
idxBuf.put((short) i);
idxBuf.put((short) (vertCount - 2));
idxBuf.put((short) (i + 1));
} else { // inside view
idxBuf.put((short) i);
idxBuf.put((short) (i + 1));
idxBuf.put((short) (vertCount - 2));
}
}
// north pole triangles
int iOffset = (zSamples - 3) * (radialSamples + 1);
for (int i = 0; i < radialSamples; i++, index += 3) {
if (!interior) {
idxBuf.put((short) (i + iOffset));
idxBuf.put((short) (i + 1 + iOffset));
idxBuf.put((short) (vertCount - 1));
} else { // inside view
idxBuf.put((short) (i + iOffset));
idxBuf.put((short) (vertCount - 1));
idxBuf.put((short) (i + 1 + iOffset));
}
}
}