本文整理匯總了Java中java.nio.FloatBuffer.allocate方法的典型用法代碼示例。如果您正苦於以下問題:Java FloatBuffer.allocate方法的具體用法?Java FloatBuffer.allocate怎麽用?Java FloatBuffer.allocate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.FloatBuffer
的用法示例。
在下文中一共展示了FloatBuffer.allocate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JSBufferedSampleRecorder
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Constructs a JSBufferedSampleRecorder that expects audio in the given AudioFormat and
* which will save to a file with given name.
*
* @param format the AudioFormat you want to record in
* @param name the name of the file to save to (not including the extension)
*/
JSBufferedSampleRecorder(JSMinim sys,
String fileName,
AudioFileFormat.Type fileType,
AudioFormat fileFormat,
int bufferSize)
{
name = fileName;
type = fileType;
format = fileFormat;
buffers = new ArrayList<FloatBuffer>(20);
left = FloatBuffer.allocate(bufferSize*10);
if ( format.getChannels() == Minim.STEREO )
{
right = FloatBuffer.allocate(bufferSize*10);
}
else
{
right = null;
}
system = sys;
}
示例2: clone
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Creates a new FloatBuffer with the same contents as the given
* FloatBuffer. The new FloatBuffer is seperate from the old one and changes
* are not reflected across. If you want to reflect changes, consider using
* Buffer.duplicate().
*
* @param buf
* the FloatBuffer to copy
* @return the copy
*/
public static FloatBuffer clone(FloatBuffer buf) {
if (buf == null) {
return null;
}
buf.rewind();
FloatBuffer copy;
if (isDirect(buf)) {
copy = createFloatBuffer(buf.limit());
} else {
copy = FloatBuffer.allocate(buf.limit());
}
copy.put(buf);
return copy;
}
示例3: toFloatBuffer
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public FloatBuffer toFloatBuffer()
{
FloatBuffer rValue = FloatBuffer.allocate(16);
rValue.put( 0, m00);
rValue.put( 1, m01);
rValue.put( 2, m02);
rValue.put( 3, m03);
rValue.put( 4, m10);
rValue.put( 5, m11);
rValue.put( 6, m12);
rValue.put( 7, m13);
rValue.put( 8, m20);
rValue.put( 9, m21);
rValue.put(10, m22);
rValue.put(11, m23);
rValue.put(12, m30);
rValue.put(13, m31);
rValue.put(14, m32);
rValue.put(15, m33);
return rValue;
}
示例4: resetPixmapGrayLevel
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Sets full pixmap to some gray level. An internal buffer is created if
* needed so that gray level can be set back quickly using System.arraycopy.
*
* @param value the gray level.
*/
private void resetPixmapGrayLevel(float value) {
checkPixmapAllocation();
final int n = 3 * sizeX * sizeY;
boolean madebuffer = false;
if ((grayBuffer == null) || (grayBuffer.capacity() != n)) {
grayBuffer = FloatBuffer.allocate(n); // Buffers.newDirectFloatBuffer(n);
madebuffer = true;
}
if (madebuffer || (value != grayValue)) {
grayBuffer.rewind();
for (int i = 0; i < n; i++) {
grayBuffer.put(value);
}
grayBuffer.rewind();
}
System.arraycopy(grayBuffer.array(), 0, pixmap.array(), 0, n);
pixmap.rewind();
pixmap.limit(n);
}
示例5: resetPixmapGrayLevel
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Resets the pixmap values to a gray level
*
* @param value 0-1 gray value.
*/
protected void resetPixmapGrayLevel(float value) {
checkPixmapAllocation();
if (chip.getNumPixels() == 0) {
log.warning("chip has zero pixels; is the constuctor of Chip2DRenderer called before size of the AEChip is set?");
return;
}
final int n = 3 * chip.getNumPixels();
boolean madebuffer = false;
if ((grayBuffer == null) || (grayBuffer.capacity() != n)) {
grayBuffer = FloatBuffer.allocate(n); // Buffers.newDirectFloatBuffer(n);
madebuffer = true;
}
if (madebuffer || (value != grayValue)) {
grayBuffer.rewind();
for (int i = 0; i < n; i++) {
grayBuffer.put(value);
}
grayBuffer.rewind();
}
System.arraycopy(grayBuffer.array(), 0, pixmap.array(), 0, n);
pixmap.rewind();
pixmap.limit(n);
// pixmapGrayValue = grayValue;
}
示例6: checkPixmapAllocation
import java.nio.FloatBuffer; //導入方法依賴的package包/類
@Override
protected void checkPixmapAllocation() {
if ((sizeX != chip.getSizeX()) || (sizeY != chip.getSizeY())) {
sizeX = chip.getSizeX();
sizeY = chip.getSizeY();
}
textureWidth = AEFrameChipRenderer.ceilingPow2(sizeX);
textureHeight = AEFrameChipRenderer.ceilingPow2(sizeY);
// System.out.println(textureWidth);
// System.out.println(textureHeight);
final int n = 4 * textureWidth * textureHeight;
// System.out.println(n);
if ((pixmap == null) || (pixmap.capacity() < n) || (pixBuffer.capacity() < n) || (onMap.capacity() < n) || (offMap.capacity() < n)
|| (annotateMap.capacity() < n)) {
pixmap = FloatBuffer.allocate(n); // BufferUtil.newFloatBuffer(n);
pixBuffer = FloatBuffer.allocate(n);
onMap = FloatBuffer.allocate(n);
offMap = FloatBuffer.allocate(n);
annotateMap = FloatBuffer.allocate(n);
}
}
示例7: asFloatBuffer
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public FloatBuffer asFloatBuffer()
{
FloatBuffer buffer = FloatBuffer.allocate(4 * 4);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
buffer.put(data[i][j]);
buffer.flip();
return buffer;
}
示例8: asFloatBuffer
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public FloatBuffer asFloatBuffer()
{
// FloatBuffer buffer = BufferUtils.createFloatBuffer(4 * 4);
FloatBuffer buffer = FloatBuffer.allocate(4*4);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
buffer.put(data[i][j]);
buffer.flip();
return buffer;
}
示例9: samples
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public void samples(float[] samp)
{
if ( recording )
{
left.put(samp);
if ( !left.hasRemaining() )
{
buffers.add(left);
left = FloatBuffer.allocate(left.capacity());
}
}
}
示例10: getWorldCoorFromMouse
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public double[] getWorldCoorFromMouse(int mouseX, int mouseY){
// get mouse coordinates and project them onto the 3D space
int[] viewport = new int[4];
//double[] modelview = new double[16];
double[] projection = new double[16];
float winX, winY;
FloatBuffer winZ = FloatBuffer.allocate(4);
double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
//gl.glGetDoublev( GL.GL_MODELVIEW_MATRIX, modelview, 0 );
gl.glGetDoublev( GL.GL_PROJECTION_MATRIX, projection, 0 );
gl.glGetIntegerv( GL.GL_VIEWPORT, viewport, 0 );
//TODO: more precision in XYZ lookup by using doubles instead of floats?
winX = (float)mouseX;
winY = (float)viewport[3] - (float)mouseY;
gl.glReadPixels( mouseX, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, winZ );
glu.gluUnProject((double)winX, (double)winY, (double)(winZ.get()), mouseModelview, 0, projection, 0, viewport, 0, wcoord, 0);
//System.out.println("World coords: (" + wcoord[0] + ", " + wcoord[1] + ", " + wcoord[2] + ")");
//
// Map coord's to snap if snap is enabled
//
if(AvoGlobal.snapEnabled && AvoGlobal.menuet.getCurrentToolMode() == Menuet.MENUET_MODE_SKETCH){
wcoord[0] = Math.floor((wcoord[0]+AvoGlobal.snapSize/2.0)/AvoGlobal.snapSize)*AvoGlobal.snapSize;
wcoord[1] = Math.floor((wcoord[1]+AvoGlobal.snapSize/2.0)/AvoGlobal.snapSize)*AvoGlobal.snapSize;
wcoord[2] = Math.floor((wcoord[2]+AvoGlobal.snapSize/2.0)/AvoGlobal.snapSize)*AvoGlobal.snapSize;
}
if(AvoGlobal.menuet.getCurrentToolMode() == Menuet.MENUET_MODE_SKETCH && wcoord[2] < 0.25 && wcoord[2] > -0.25){
wcoord[2] = 0.0; // tie z-value to zero if close enough to located on the drawing plane.
}
AvoGlobal.glCursor3DPos = wcoord;
AvoGlobal.glViewEventHandler.notifyCursorMoved();
return wcoord;
}
示例11: resetPixmapGrayLevel
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/** Overridden to make gray buffer special for bDVS array */
@Override
protected void resetPixmapGrayLevel(float value) {
checkPixmapAllocation();
final int n = 2 * chip.getNumPixels();
boolean madebuffer = false;
if ((grayBuffer == null) || (grayBuffer.capacity() != n)) {
grayBuffer = FloatBuffer.allocate(n); // BufferUtil.newFloatBuffer(n);
madebuffer = true;
}
if (madebuffer || (value != grayValue)) {
grayBuffer.rewind();
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) {
// if(displayLogIntensityChangeEvents){
// grayBuffer.put(0);
// grayBuffer.put(0);
// grayBuffer.put(0);
// } else {
grayBuffer.put(grayValue);
grayBuffer.put(grayValue);
// grayBuffer.put(grayValue);
// }
}
}
grayBuffer.rewind();
}
System.arraycopy(grayBuffer.array(), 0, pixmap.array(), 0, n);
pixmap.rewind();
pixmap.limit(n);
// pixmapGrayValue = grayValue;
}
示例12: checkPixmapAllocation
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/** Subclasses should call checkPixmapAllocation to
* make sure the pixmap FloatBuffer is allocated before accessing it.
*
*/
public void checkPixmapAllocation() {
final int n = 3 * sizeX * sizeY;
if ((pixmap == null) || (pixmap.capacity() != n)) {
pixmap = FloatBuffer.allocate(n); // Buffers.newDirectFloatBuffer(n);
}
}
示例13: checkPixmapAllocation
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Subclasses should call checkPixmapAllocation to make sure the pixmap
* FloatBuffer is allocated before accessing it.
*
*/
protected void checkPixmapAllocation() {
final int n = 3 * chip.getNumPixels();
if ((pixmap == null) || (pixmap.capacity() < n)) {
pixmap = FloatBuffer.allocate(n); // Buffers.newDirectFloatBuffer(n);
}
}
示例14: generateFloatBuffer
import java.nio.FloatBuffer; //導入方法依賴的package包/類
@Generates private FloatBuffer generateFloatBuffer() {
return FloatBuffer.allocate(generateInt());
}
示例15: testTensorToImgDirect
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/** Tests the img<Type>Direct(Tensor) functions */
@Test
public void testTensorToImgDirect() {
final long[] shape = new long[] { 20, 10, 3 };
final int[] mapping = new int[] { 0, 1, 2 };
final int n = shape.length;
final int size = 600;
// Get some points to mark
List<Point> points = createTestPoints(n);
// Create Tensors of different type and convert them to images
ByteBuffer dataByte = ByteBuffer.allocateDirect(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataByte.put(i, (byte) (int) v));
Tensor tensorByte = Tensor.create(DataType.UINT8, shape, dataByte);
Img<ByteType> imgByte = Tensors.imgByteDirect(tensorByte);
DoubleBuffer dataDouble = DoubleBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataDouble.put(i, v));
Tensor tensorDouble = Tensor.create(shape, dataDouble);
Img<DoubleType> imgDouble = Tensors.imgDoubleDirect(tensorDouble);
FloatBuffer dataFloat = FloatBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataFloat.put(i, v));
Tensor tensorFloat = Tensor.create(shape, dataFloat);
Img<FloatType> imgFloat = Tensors.imgFloatDirect(tensorFloat);
IntBuffer dataInt = IntBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataInt.put(i, v));
Tensor tensorInt = Tensor.create(shape, dataInt);
Img<IntType> imgInt = Tensors.imgIntDirect(tensorInt);
LongBuffer dataLong = LongBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataLong.put(i, v));
Tensor tensorLong = Tensor.create(shape, dataLong);
Img<LongType> imgLong = Tensors.imgLongDirect(tensorLong);
// Check all created images
checkImage(imgByte, n, shape, points);
checkImage(imgDouble, n, shape, points);
checkImage(imgFloat, n, shape, points);
checkImage(imgInt, n, shape, points);
checkImage(imgLong, n, shape, points);
}