Package java.nio

Examples of java.nio.ByteBuffer.asShortBuffer()


  public static void main(String[] args) {
    ByteBuffer buffer = ByteBuffer.allocate(20);
    buffer.position(1);
    System.out.println(Memory.getPosition(buffer));
   
    ShortBuffer sBuffer = buffer.asShortBuffer();
    sBuffer.position(1);
    System.out.println(Memory.getPosition(sBuffer));
   
    CharBuffer cBuffer = buffer.asCharBuffer();
    cBuffer.position(1);
View Full Code Here


  public static ShortBuffer newShortBuffer (int numShorts) {
    if (GWT.isProdMode()) {
      ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2);
      buffer.order(ByteOrder.nativeOrder());
      return buffer.asShortBuffer();
    } else {
      return ShortBuffer.wrap(new short[numShorts]);
    }
  }

View Full Code Here

  public static ShortBuffer newShortBuffer (int numShorts) {
    if (GWT.isProdMode()) {
      ByteBuffer buffer = ByteBuffer.allocateDirect(numShorts * 2);
      buffer.order(ByteOrder.nativeOrder());
      return buffer.asShortBuffer();
    } else {
      return ShortBuffer.wrap(new short[numShorts]);
    }
  }

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

        Pointer p = new Memory(1024);
        ByteBuffer b = p.getByteBuffer(0, 1024);
        assertEquals("ByteBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b));
        assertEquals("ShortBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asShortBuffer()));
        assertEquals("IntBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asIntBuffer()));
        assertEquals("LongBuffer Pointer does not match",
                     p, Native.getDirectBufferPointer(b.asLongBuffer()));
        assertEquals("FloatBuffer Pointer does not match",
View Full Code Here

        }
    }
   
    public void testDirectShortBufferArgument() {
        ByteBuffer buf  = ByteBuffer.allocateDirect(1024*2).order(ByteOrder.nativeOrder());
        ShortBuffer shortBuf = buf.asShortBuffer();
        final short MAGIC = (short)0xABED;
        lib.fillInt16Buffer(shortBuf, 1024, MAGIC);
        for (int i=0;i < shortBuf.capacity();i++) {
            assertEquals("Bad value at index " + i, MAGIC, shortBuf.get(i));
        }
View Full Code Here

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

    buffer.put(pcm, 0, bytes);
    buffer.flip();

    if (bufferID == -1) {
      bufferID = alGenBuffers();
      alBufferData(bufferID, channels > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.asShortBuffer(), sampleRate);
    }
  }

  public long play () {
    return play(1);
View Full Code Here

        if(byteBuffer.remaining() < byteLen) {
            throw new EOFException();
        }

        // Get the view Buffer.
        ShortBuffer viewBuffer = byteBuffer.asShortBuffer();

        // Get the shorts.
        viewBuffer.get(s, off, len);

        // Update the position.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.