Package java.nio

Examples of java.nio.ShortBuffer


    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);
View Full Code Here


  }

  /** Bulk output of a short array. */
  public void writeShorts (short[] object) throws KryoException {
    if (capacity - position >= object.length * 2 && isNativeOrder()) {
      ShortBuffer buf = niobuffer.asShortBuffer();
      buf.put(object);
      position += object.length * 2;
    } else
      super.writeShorts(object);
  }
View Full Code Here

 
  public void renderShortArray(Token token){
       short[] data = (short[]) token.getObject();

          ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 2);       
          ShortBuffer intBuffer = byteBuffer.asShortBuffer();
          intBuffer.put(data);

          byte[] array = byteBuffer.array();
      String str = Base64.encodeBytes(array);
      props.put(token.getId()+".base64", str);
  }
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_SHORT_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
          buf = ByteBuffer.allocate(arraySize * 2);
          ShortBuffer shortbuf = buf.asShortBuffer();
          shortbuf.put(this.getShortHeap().heap, arrayStart, arraySize);

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_LONG_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
View Full Code Here

      int bbLen = in.readInt();
      short[] faps = new short[bbLen/2];
      short[] eaps = new short[bbLen/2];
      ByteBuffer bb=ByteBuffer.allocate(bbLen);
      in.readFully(bb.array());
      ShortBuffer sb = bb.asShortBuffer();
      sb.get(faps);
      bb.clear();
      in.readFully(bb.array());
      sb = bb.asShortBuffer();
      sb.get(eaps);
      for (int i = 0; i<faps.length; i++) {
        set(faps[i], eaps[i]);
      }
    }
View Full Code Here

          c++;
        }
      int bbLen = faps.length * 2;
      out.writeInt(bbLen);
      ByteBuffer bb=ByteBuffer.allocate(bbLen);
      ShortBuffer sb = bb.asShortBuffer();
      sb.put(faps);
      out.write(bb.array());
      sb.clear();
      sb.put(eaps);
      out.write(bb.array());
    }
View Full Code Here

     * sets the indices for rendering the sphere.
     */
    private void setIndexData() {
        // allocate connectivity
        triCount = 2 * (zSamples - 2) * radialSamples;
        ShortBuffer idxBuf = BufferUtils.createShortBuffer(3 * triCount);
        setBuffer(Type.Index, 3, 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));
            }
        }
    }
View Full Code Here

        nb.put(0).put(insideView ? 1 : -1).put(0);
        tb.put(0.5f).put(1.0f);

        // allocate connectivity
        int triCount = (planes - 2) * radialSamples * 2 + radialSamples;
        ShortBuffer ib = BufferUtils.createShortBuffer(3 * triCount);
        setBuffer(Type.Index, 3, ib);

        // generate connectivity
        int index = 0;
        // Generate only for middle planes
        for (int plane = 1; plane < (planes - 1); plane++) {
            int bottomPlaneStart = ((plane - 1) * (radialSamples + 1));
            int topPlaneStart = (plane * (radialSamples + 1));
            for (int sample = 0; sample < radialSamples; sample++, index += 6) {
                if (insideView){
                    ib.put((short) (bottomPlaneStart + sample));
                    ib.put((short) (bottomPlaneStart + sample + 1));
                    ib.put((short) (topPlaneStart + sample));
                    ib.put((short) (bottomPlaneStart + sample + 1));
                    ib.put((short) (topPlaneStart + sample + 1));
                    ib.put((short) (topPlaneStart + sample));
                }else{
                    ib.put((short) (bottomPlaneStart + sample));
                    ib.put((short) (topPlaneStart + sample));
                    ib.put((short) (bottomPlaneStart + sample + 1));
                    ib.put((short) (bottomPlaneStart + sample + 1));
                    ib.put((short) (topPlaneStart + sample));
                    ib.put((short) (topPlaneStart + sample + 1));
                }
            }
        }

        // pole triangles
        int bottomPlaneStart = (planes - 2) * (radialSamples + 1);
        for (int samples = 0; samples < radialSamples; samples++, index += 3) {
            if (insideView){
                ib.put((short) (bottomPlaneStart + samples));
                ib.put((short) (bottomPlaneStart + samples + 1));
                ib.put((short) (vertCount - 1));
            }else{
                ib.put((short) (bottomPlaneStart + samples));
                ib.put((short) (vertCount - 1));
                ib.put((short) (bottomPlaneStart + samples + 1));
            }
        }

        updateBound();
    }
View Full Code Here

        FloatBuffer fpb = BufferUtils.createFloatBuffer(lineVerticesCount * 3);
        pb.setupData(Usage.Stream, 3, Format.Float, fpb);
        this.setBuffer(pb);

        VertexBuffer ib = new VertexBuffer(Type.Index);
        ShortBuffer sib = BufferUtils.createShortBuffer(boneLengths != null ? lineVerticesCount : numConnections * 2);
        ib.setupData(Usage.Static, 2, Format.UnsignedShort, sib);
        this.setBuffer(ib);

        if (boneLengths != null) {
            for (int i = 0; i < lineVerticesCount; ++i) {
                sib.put((short) i);
            }
        } else {
            for (Bone bone : skeleton.getRoots()) {
                this.writeConnections(sib, bone);
            }
        }
        sib.flip();

        this.updateCounts();
    }
View Full Code Here

        this(1);
    }

    public WireSphere(float radius) {
        updatePositions(radius);
        ShortBuffer ib = BufferUtils.createShortBuffer(samples * 2 * 2 + zSamples * samples * 2 /*+ 3 * 2*/);
        setBuffer(Type.Index, 2, ib);

//        ib.put(new byte[]{
//            (byte) 0, (byte) 1,
//            (byte) 2, (byte) 3,
//            (byte) 4, (byte) 5,
//        });

//        int curNum = 3 * 2;
        int curNum = 0;
        for (int j = 0; j < 2 + zSamples; j++) {
            for (int i = curNum; i < curNum + samples - 1; i++) {
                ib.put((short) i).put((short) (i + 1));
            }
            ib.put((short) (curNum + samples - 1)).put((short) curNum);
            curNum += samples;
        }

        setMode(Mode.Lines);

View Full Code Here

TOP

Related Classes of java.nio.ShortBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.