Example usage for java.nio ShortBuffer limit

List of usage examples for java.nio ShortBuffer limit

Introduction

In this page you can find the example usage for java.nio ShortBuffer limit.

Prototype

public final int limit() 

Source Link

Document

Returns the limit of this buffer.

Usage

From source file:Main.java

public static ShortBuffer createShortBuffer(ShortBuffer buf, final int size) {
    if (buf != null && buf.limit() == size) {
        buf.rewind();//from  w w  w  . j  a v a2s. c o  m
        return buf;
    }

    buf = createShortBuffer(size);
    return buf;
}

From source file:Main.java

public static ShortBuffer clone(final ShortBuffer buf) {
    if (buf == null) {
        return null;
    }//from www  . j  a va2s. c  om
    buf.rewind();

    final ShortBuffer copy;
    if (buf.isDirect()) {
        copy = createShortBuffer(buf.limit());
    } else {
        copy = createShortBufferOnHeap(buf.limit());
    }
    copy.put(buf);

    return copy;
}

From source file:com.newventuresoftware.waveformdemo.MainActivity.java

private short[] getAudioSample() throws IOException {
    InputStream is = getResources().openRawResource(R.raw.jinglebells);
    byte[] data;//  w w  w  .ja v a 2s .  co m
    try {
        data = IOUtils.toByteArray(is);
    } finally {
        if (is != null) {
            is.close();
        }
    }

    ShortBuffer sb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    short[] samples = new short[sb.limit()];
    sb.get(samples);
    return samples;
}