コード例 #1
0
ファイル: ChannelSplit.java プロジェクト: 2php/jcodec
  @Override
  public void filter(FloatBuffer[] _in, long[] inPos, FloatBuffer[] out) {
    if (_in.length != 1) {
      throw new IllegalArgumentException("Channel split invoked on more then one input");
    }
    if (out.length != format.getChannels()) {
      throw new IllegalArgumentException(
          "Channel split must be supplied with "
              + format.getChannels()
              + " output buffers to hold the channels.");
    }

    FloatBuffer in0 = _in[0];

    int outSampleCount = in0.remaining() / out.length;
    for (int i = 0; i < out.length; i++) {
      if (out[i].remaining() < outSampleCount)
        throw new IllegalArgumentException(
            "Supplied buffer for "
                + i
                + "th channel doesn't have sufficient space to put the samples ( required: "
                + outSampleCount
                + ", actual: "
                + out[i].remaining()
                + ")");
    }

    while (in0.remaining() >= format.getChannels()) {
      for (int i = 0; i < out.length; i++) {
        out[i].put(in0.get());
      }
    }
  }
コード例 #2
0
 /**
  * Receive as many items as possible from the given byte buffer to this buffer.
  *
  * <p>The <TT>receiveItems()</TT> method must not block the calling thread; if it does, all
  * message I/O in MP will be blocked.
  *
  * @param i Index of first item to receive, in the range 0 .. <TT>length</TT>-1.
  * @param num Maximum number of items to receive.
  * @param buffer Byte buffer.
  * @return Number of items received.
  */
 protected int receiveItems(int i, int num, ByteBuffer buffer) {
   FloatBuffer floatbuffer = buffer.asFloatBuffer();
   int n = 0;
   int r = i / myColCount;
   int row = r + myLowerRow;
   int c = i % myColCount;
   int col = c + myLowerCol;
   int ncols = Math.min(myColCount - c, floatbuffer.remaining());
   while (r < myRowCount && ncols > 0) {
     float[] myMatrix_row = myMatrix[row];
     while (c < ncols) {
       myMatrix_row[col] = myOp.op(myMatrix_row[col], floatbuffer.get());
       ++c;
       ++col;
     }
     n += ncols;
     ++r;
     ++row;
     c = 0;
     col = myLowerCol;
     ncols = Math.min(myColCount, floatbuffer.remaining());
   }
   buffer.position(buffer.position() + 4 * n);
   return n;
 }
コード例 #3
0
ファイル: GwtGL20.java プロジェクト: moly/libgdx
 public Float32Array copy(FloatBuffer buffer) {
   if (GWT.isProdMode()) {
     return ((Float32Array) ((HasArrayBufferView) buffer).getTypedArray())
         .subarray(buffer.position(), buffer.remaining());
   } else {
     ensureCapacity(buffer);
     for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) {
       floatBuffer.set(j, buffer.get(i));
     }
     return floatBuffer.subarray(0, buffer.remaining());
   }
 }
コード例 #4
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
 private static void checkSlice(FloatBuffer b, FloatBuffer slice) {
   ck(slice, 0, slice.position());
   ck(slice, b.remaining(), slice.limit());
   ck(slice, b.remaining(), slice.capacity());
   if (b.isDirect() != slice.isDirect()) fail("Lost direction", slice);
   if (b.isReadOnly() != slice.isReadOnly()) fail("Lost read-only", slice);
 }
コード例 #5
0
 public static void glWeightARB(FloatBuffer pWeights) {
   ContextCapabilities caps = GLContext.getCapabilities();
   long function_pointer = caps.glWeightfvARB;
   BufferChecks.checkFunctionAddress(function_pointer);
   BufferChecks.checkDirect(pWeights);
   nglWeightfvARB(pWeights.remaining(), MemoryUtil.getAddress(pWeights), function_pointer);
 }
コード例 #6
0
 /*     */ public static void glUniform4ARB(int location, FloatBuffer values) {
   /* 269 */ ContextCapabilities caps = GLContext.getCapabilities();
   /* 270 */ long function_pointer = caps.glUniform4fvARB;
   /* 271 */ BufferChecks.checkFunctionAddress(function_pointer);
   /* 272 */ BufferChecks.checkDirect(values);
   /* 273 */ nglUniform4fvARB(
       location, values.remaining() >> 2, MemoryUtil.getAddress(values), function_pointer);
   /*     */ }
コード例 #7
0
 private void checkSize(final int count) {
   while (buffer.remaining() < count) {
     final FloatBuffer newBuffer = BufferUtils.createFloatBuffer(buffer.capacity() << 1);
     buffer.flip();
     newBuffer.put(buffer);
     buffer = newBuffer;
   }
 }
コード例 #8
0
ファイル: Vector3d.java プロジェクト: ElsewhereGames/Math
  /**
   * Stores the x, y, and z components of this vector (in that order) in the specified <code>
   * destination</code> buffer.
   *
   * @param destination The buffer in which the components are stored. The position of the buffer
   *     after this operation lies after the last component added.
   * @throws IllegalArgumentException If the <code>destination</code> buffer contains less than
   *     three elements.
   */
  public final void getComponents(FloatBuffer destination) throws IllegalArgumentException {
    // Make sure there is enough room for the components:
    if (destination.remaining() < Vector3d.COMPONENT_COUNT) {
      throw new IllegalArgumentException("The specified destination buffer is not large enough.");
    }

    // The components are stored in XYZ order.
    destination.put(this.x);
    destination.put(this.y);
    destination.put(this.z);
  }
コード例 #9
0
ファイル: Vector3d.java プロジェクト: ElsewhereGames/Math
  /**
   * Sets the x, y, and z components of this vector to the values supplied by the <code>source
   * </code> buffer.
   *
   * @param source The buffer which supplies the values of this vector. The values are expected to
   *     be stored in XYZ order.
   * @throws IllegalArgumentException If the <code>source</code> buffer does not have enough
   *     elements remaining for all components of this vector.
   */
  public final void setComponents(final FloatBuffer source) {
    // Make sure the source contains enough components:
    if (source.remaining() < Vector3d.COMPONENT_COUNT) {
      throw new IllegalArgumentException(
          "The specified source buffer does not contain enough components.");
    }

    // The components are stored in XYZ order.
    this.x = source.get();
    this.y = source.get();
    this.z = source.get();
  }
コード例 #10
0
ファイル: XglCodeGen.java プロジェクト: zackangelo/ivy
  private static String floatArrToStr(FloatBuffer in) {
    StringBuilder b = new StringBuilder();

    in.flip();
    in.limit(in.capacity());

    if (in.remaining() < 1) {
      throw new IllegalArgumentException("Buffer is empty! (" + in.toString() + ")");
    }

    b.append("new float[] {");

    while (in.remaining() > 0) {
      b.append(in.get());
      b.append("f");
      if (in.remaining() > 0) b.append(",");
    }

    b.append("}");

    return b.toString();
  }
コード例 #11
0
 /*     */ public static void glUniformMatrix4ARB(
     int location, boolean transpose, FloatBuffer matrices) {
   /* 332 */ ContextCapabilities caps = GLContext.getCapabilities();
   /* 333 */ long function_pointer = caps.glUniformMatrix4fvARB;
   /* 334 */ BufferChecks.checkFunctionAddress(function_pointer);
   /* 335 */ BufferChecks.checkDirect(matrices);
   /* 336 */ nglUniformMatrix4fvARB(
       location,
       matrices.remaining() >> 4,
       transpose,
       MemoryUtil.getAddress(matrices),
       function_pointer);
   /*     */ }
コード例 #12
0
  /**
   * Writes the given samples to the file.
   *
   * <p>Note: this function is non-blocking and can be called from within the process tread.
   *
   * @param startSample the file-position of the first sample. If the position larger than the
   *     number of samples written so far, the gap will be filled with null samples.
   * @param audioArray the data to be written to file.
   */
  public void putNext(int startSample, float[] audioArray) {
    synchronized (processingLock) {
      if (!started) {
        return;
      }
      if (startSample < samplesDelivered) {
        Arrays.fill(audioArray, 0.0F);
        logger.severe("\"startSample\" already delivered.");
        return;
      }
      samplesDelivered = startSample + audioArray.length;

      if (currentBufferProvider == null) {
        logger.severe("Current buffer is null.");
        return;
      }
      if (!currentBufferProvider.isDone()) {
        logger.warning("File buffer not ready.");
        overflowCount++;
        return;
      }
      SyncBuffer currentBuffer;
      try {
        FileWriteTaskResult result = currentBufferProvider.get();
        currentBuffer = result.getbuffer();
      } catch (InterruptedException | ExecutionException ex) {
        logger.log(Level.SEVERE, null, ex);
        return;
      }
      FloatBuffer currentFloatBuffer = currentBuffer.asFloatBuffer();

      int offset = startSample - samplesProcessed;
      int toBeWritten = offset + audioArray.length;

      // Do we need to write samples to the next buffer?
      int remainingSpace = currentFloatBuffer.remaining();
      if (remainingSpace < toBeWritten) {
        switchBuffers(offset, audioArray, currentBuffer);
        return;
      }

      // Now we have checked all special conditions... we can proceed to the normal work.
      // 1) Pad with null samples.
      for (int i = 0; i < offset; i++) {
        currentFloatBuffer.put(0F);
      }
      // 2) append the audioArray
      currentFloatBuffer.put(audioArray);
      samplesProcessed = startSample + audioArray.length;
    }
  }
コード例 #13
0
ファイル: Line.java プロジェクト: jmecn/learnJME3
  public void orthogonalLineFit(FloatBuffer points) {
    if (points == null) {
      return;
    }

    points.rewind();

    // compute average of points
    int length = points.remaining() / 3;

    BufferUtils.populateFromBuffer(origin, points, 0);
    for (int i = 1; i < length; i++) {
      BufferUtils.populateFromBuffer(compVec1, points, i);
      origin.addLocal(compVec1);
    }

    origin.multLocal(1f / (float) length);

    // compute sums of products
    float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;
    float sumYY = 0.0f, sumYZ = 0.0f, sumZZ = 0.0f;

    points.rewind();
    for (int i = 0; i < length; i++) {
      BufferUtils.populateFromBuffer(compVec1, points, i);
      compVec1.subtract(origin, compVec2);
      sumXX += compVec2.x * compVec2.x;
      sumXY += compVec2.x * compVec2.y;
      sumXZ += compVec2.x * compVec2.z;
      sumYY += compVec2.y * compVec2.y;
      sumYZ += compVec2.y * compVec2.z;
      sumZZ += compVec2.z * compVec2.z;
    }

    // find the smallest eigen vector for the direction vector
    compMat1.m00 = sumYY + sumZZ;
    compMat1.m01 = -sumXY;
    compMat1.m02 = -sumXZ;
    compMat1.m10 = -sumXY;
    compMat1.m11 = sumXX + sumZZ;
    compMat1.m12 = -sumYZ;
    compMat1.m20 = -sumXZ;
    compMat1.m21 = -sumYZ;
    compMat1.m22 = sumXX + sumYY;

    compEigen1.calculateEigen(compMat1);
    direction = compEigen1.getEigenVector(0);
  }
コード例 #14
0
 /** FloatBuffer version of: {@link #glBufferData BufferData} */
 public static void glBufferData(int target, FloatBuffer data, int usage) {
   nglBufferData(target, data.remaining() << 2, memAddress(data), usage);
 }
コード例 #15
0
 /** FloatBuffer version of: {@link #glGetBufferSubData GetBufferSubData} */
 public static void glGetBufferSubData(int target, long offset, FloatBuffer data) {
   nglGetBufferSubData(target, offset, data.remaining() << 2, memAddress(data));
 }
コード例 #16
0
ファイル: BasicFloat.java プロジェクト: susotajuraj/jdk8u-jdk
 private static void relGet(FloatBuffer b, int start) {
   int n = b.remaining();
   float v;
   for (int i = start; i < n; i++) ck(b, (long) b.get(), (long) ((float) ic(i)));
   b.rewind();
 }
コード例 #17
0
  private void switchBuffers(int offset, float[] audioArray, SyncBuffer oldBuffer) {
    int toBePadded = offset;
    FloatBuffer oldFloatBuffer = oldBuffer.asFloatBuffer();
    // 1) use the remaining space in the current buffer
    // ...pad the current buffer as much as fits.
    while ((toBePadded > 0) && (oldFloatBuffer.hasRemaining())) {
      oldFloatBuffer.put(0F);
      toBePadded--;
      samplesProcessed++;
    }

    // ...put as much as fits from the audioArray
    int audioArrayWrittenToOld = 0;
    if (oldFloatBuffer.hasRemaining() && toBePadded == 0) {
      audioArrayWrittenToOld = oldFloatBuffer.remaining();
      oldFloatBuffer.put(audioArray, 0, audioArrayWrittenToOld);
      samplesProcessed += audioArrayWrittenToOld;
    }

    // 2) put the rest in a new buffer
    if (!startBufferDone) {
      // setup the first file buffer
      bussyBufferProvider = new AlwaysStreamedBuffer(new SyncBuffer(requestedFileBufferSizeFloat));
    } else {
      if (!firstFileBufferDone) {
        // setup the second file buffer
        bussyBufferProvider =
            new AlwaysStreamedBuffer(new SyncBuffer(requestedFileBufferSizeFloat));
      }
    }

    if (bussyBufferProvider == null) {
      logger.severe("Next buffer is null!!");
      return;
    }
    if (!bussyBufferProvider.isDone()) {
      logger.warning("Next buffer not ready.");
      overflowCount++;
      return;
    }
    SyncBuffer newBuffer;
    FileChannel channel;
    try {
      FileWriteTaskResult result = bussyBufferProvider.get();
      newBuffer = result.getbuffer();
      channel = result.getChannel();
    } catch (InterruptedException | ExecutionException ex) {
      logger.log(Level.SEVERE, null, ex);
      return;
    }
    FloatBuffer newFloatBuffer = newBuffer.asFloatBuffer();
    //

    int remainingInNewBuffer = newFloatBuffer.remaining();
    int toBeWrittenToNew = toBePadded + audioArray.length - audioArrayWrittenToOld;
    if (toBeWrittenToNew > remainingInNewBuffer) {
      logger.severe("File buffer too small for this offset.");
    } else {
      for (int i = 0; i < toBePadded; i++) {
        newFloatBuffer.put(0F);
        samplesProcessed++;
      }
      int restAudioArray = audioArray.length - audioArrayWrittenToOld;
      newFloatBuffer.put(audioArray, audioArrayWrittenToOld, restAudioArray);
      samplesProcessed += restAudioArray;
    }

    if (startBufferDone) {
      FileWriteTask fileWriteTask = new FileWriteTask(outputFile, channel, oldBuffer);
      currentBufferProvider = bussyBufferProvider;
      bussyBufferProvider = executor.submit(fileWriteTask);
      firstFileBufferDone = true;
    } else {
      // we just have processed the first buffer:
      currentBufferProvider = bussyBufferProvider;
      bussyBufferProvider = null;
      startBufferDone = true;
    }
  }
コード例 #18
0
  /**
   * Specific method for skinning with tangents to avoid cluttering the classic skinning calculation
   * with null checks that would slow down the process even if tangents don't have to be computed.
   * Also the iteration has additional indexes since tangent has 4 components instead of 3 for pos
   * and norm
   *
   * @param maxWeightsPerVert maximum number of weights per vertex
   * @param mesh the mesh
   * @param offsetMatrices the offsetMaytrices to apply
   * @param tb the tangent vertexBuffer
   */
  private void applySkinningTangents(Mesh mesh, Matrix4f[] offsetMatrices, VertexBuffer tb) {
    int maxWeightsPerVert = mesh.getMaxNumWeights();

    if (maxWeightsPerVert <= 0) {
      throw new IllegalStateException("Max weights per vert is incorrectly set!");
    }

    int fourMinusMaxWeights = 4 - maxWeightsPerVert;

    // NOTE: This code assumes the vertex buffer is in bind pose
    // resetToBind() has been called this frame
    VertexBuffer vb = mesh.getBuffer(Type.Position);
    FloatBuffer fvb = (FloatBuffer) vb.getData();
    fvb.rewind();

    VertexBuffer nb = mesh.getBuffer(Type.Normal);

    FloatBuffer fnb = (FloatBuffer) nb.getData();
    fnb.rewind();

    FloatBuffer ftb = (FloatBuffer) tb.getData();
    ftb.rewind();

    // get boneIndexes and weights for mesh
    ByteBuffer ib = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData();
    FloatBuffer wb = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData();

    ib.rewind();
    wb.rewind();

    float[] weights = wb.array();
    byte[] indices = ib.array();
    int idxWeights = 0;

    TempVars vars = TempVars.get();

    float[] posBuf = vars.skinPositions;
    float[] normBuf = vars.skinNormals;
    float[] tanBuf = vars.skinTangents;

    int iterations = (int) FastMath.ceil(fvb.capacity() / ((float) posBuf.length));
    int bufLength = 0;
    int tanLength = 0;
    for (int i = iterations - 1; i >= 0; i--) {
      // read next set of positions and normals from native buffer
      bufLength = Math.min(posBuf.length, fvb.remaining());
      tanLength = Math.min(tanBuf.length, ftb.remaining());
      fvb.get(posBuf, 0, bufLength);
      fnb.get(normBuf, 0, bufLength);
      ftb.get(tanBuf, 0, tanLength);
      int verts = bufLength / 3;
      int idxPositions = 0;
      // tangents has their own index because of the 4 components
      int idxTangents = 0;

      // iterate vertices and apply skinning transform for each effecting bone
      for (int vert = verts - 1; vert >= 0; vert--) {
        float nmx = normBuf[idxPositions];
        float vtx = posBuf[idxPositions++];
        float nmy = normBuf[idxPositions];
        float vty = posBuf[idxPositions++];
        float nmz = normBuf[idxPositions];
        float vtz = posBuf[idxPositions++];

        float tnx = tanBuf[idxTangents++];
        float tny = tanBuf[idxTangents++];
        float tnz = tanBuf[idxTangents++];

        // skipping the 4th component of the tangent since it doesn't have to be transformed
        idxTangents++;

        float rx = 0, ry = 0, rz = 0, rnx = 0, rny = 0, rnz = 0, rtx = 0, rty = 0, rtz = 0;

        for (int w = maxWeightsPerVert - 1; w >= 0; w--) {
          float weight = weights[idxWeights];
          Matrix4f mat = offsetMatrices[indices[idxWeights++]];

          rx += (mat.m00 * vtx + mat.m01 * vty + mat.m02 * vtz + mat.m03) * weight;
          ry += (mat.m10 * vtx + mat.m11 * vty + mat.m12 * vtz + mat.m13) * weight;
          rz += (mat.m20 * vtx + mat.m21 * vty + mat.m22 * vtz + mat.m23) * weight;

          rnx += (nmx * mat.m00 + nmy * mat.m01 + nmz * mat.m02) * weight;
          rny += (nmx * mat.m10 + nmy * mat.m11 + nmz * mat.m12) * weight;
          rnz += (nmx * mat.m20 + nmy * mat.m21 + nmz * mat.m22) * weight;

          rtx += (tnx * mat.m00 + tny * mat.m01 + tnz * mat.m02) * weight;
          rty += (tnx * mat.m10 + tny * mat.m11 + tnz * mat.m12) * weight;
          rtz += (tnx * mat.m20 + tny * mat.m21 + tnz * mat.m22) * weight;
        }

        idxWeights += fourMinusMaxWeights;

        idxPositions -= 3;

        normBuf[idxPositions] = rnx;
        posBuf[idxPositions++] = rx;
        normBuf[idxPositions] = rny;
        posBuf[idxPositions++] = ry;
        normBuf[idxPositions] = rnz;
        posBuf[idxPositions++] = rz;

        idxTangents -= 4;

        tanBuf[idxTangents++] = rtx;
        tanBuf[idxTangents++] = rty;
        tanBuf[idxTangents++] = rtz;

        // once again skipping the 4th component of the tangent
        idxTangents++;
      }

      fvb.position(fvb.position() - bufLength);
      fvb.put(posBuf, 0, bufLength);
      fnb.position(fnb.position() - bufLength);
      fnb.put(normBuf, 0, bufLength);
      ftb.position(ftb.position() - tanLength);
      ftb.put(tanBuf, 0, tanLength);
    }

    vars.release();

    vb.updateData(fvb);
    nb.updateData(fnb);
    tb.updateData(ftb);
  }
コード例 #19
0
 /** Alternative version of: {@link #glViewportArrayv ViewportArrayv} */
 public static void glViewportArrayv(int first, FloatBuffer v) {
   nglViewportArrayv(first, v.remaining() >> 2, memAddress(v));
 }
コード例 #20
0
ファイル: GwtGL20.java プロジェクト: moly/libgdx
 private void ensureCapacity(FloatBuffer buffer) {
   if (buffer.remaining() > floatBuffer.length()) {
     floatBuffer = TypedArrays.createFloat32Array(buffer.remaining());
   }
 }