当前位置: 首页>>代码示例>>Java>>正文


Java ShortBuffer.allocate方法代码示例

本文整理汇总了Java中java.nio.ShortBuffer.allocate方法的典型用法代码示例。如果您正苦于以下问题:Java ShortBuffer.allocate方法的具体用法?Java ShortBuffer.allocate怎么用?Java ShortBuffer.allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ShortBuffer的用法示例。


在下文中一共展示了ShortBuffer.allocate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clone

import java.nio.ShortBuffer; //导入方法依赖的package包/类
/**
 * Creates a new ShortBuffer with the same contents as the given ShortBuffer.
 * The new ShortBuffer 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 ShortBuffer to copy
 * @return the copy
 */
public static ShortBuffer clone(ShortBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

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

    return copy;
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:27,代码来源:BufferUtils.java

示例2: encodeToOpus

import java.nio.ShortBuffer; //导入方法依赖的package包/类
private byte[] encodeToOpus(byte[] rawAudio)
{
    ShortBuffer nonEncodedBuffer = ShortBuffer.allocate(rawAudio.length / 2);
    ByteBuffer encoded = ByteBuffer.allocate(4096);
    for (int i = 0; i < rawAudio.length; i += 2)
    {
        int firstByte =  (0x000000FF & rawAudio[i]);      //Promotes to int and handles the fact that it was unsigned.
        int secondByte = (0x000000FF & rawAudio[i + 1]);  //

        //Combines the 2 bytes into a short. Opus deals with unsigned shorts, not bytes.
        short toShort = (short) ((firstByte << 8) | secondByte);

        nonEncodedBuffer.put(toShort);
    }
    nonEncodedBuffer.flip();

    //TODO: check for 0 / negative value for error.
    int result = Opus.INSTANCE.opus_encode(opusEncoder, nonEncodedBuffer, OPUS_FRAME_SIZE, encoded, encoded.capacity());

    //ENCODING STOPS HERE

    byte[] audio = new byte[result];
    encoded.get(audio);
    return audio;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA-Audio,代码行数:26,代码来源:AudioConnection.java

示例3: allocateBufferSignal

import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void allocateBufferSignal() {
    if (mConfig.pcmFormat == FSKConfig.PCM_8BIT) {
        mSignalPCM8 = ByteBuffer.allocate(mConfig.sampleRate); //1 second buffer
    }
    else if (mConfig.pcmFormat == FSKConfig.PCM_16BIT) {
        mSignalPCM16 = ShortBuffer.allocate(mConfig.sampleRate); //1 second buffer
    }
}
 
开发者ID:jphacks,项目名称:KB_1711,代码行数:9,代码来源:FSKEncoder.java

示例4: decodeFromOpus

import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected short[] decodeFromOpus(AudioPacket decryptedPacket)
{
    int result;
    ShortBuffer decoded = ShortBuffer.allocate(4096);
    if (decryptedPacket == null)    //Flag for packet-loss
    {
        result = Opus.INSTANCE.opus_decode(opusDecoder, null, 0, decoded,
                AudioConnection.OPUS_FRAME_SIZE, 0);
        lastSeq = (char) -1;
        lastTimestamp = -1;
    }
    else
    {
        char seq = decryptedPacket.getSequence();
        this.lastSeq = seq;
        this.lastTimestamp = decryptedPacket.getTimestamp();

        byte[] encodedAudio = decryptedPacket.getEncodedAudio();

        result = Opus.INSTANCE.opus_decode(opusDecoder, encodedAudio, encodedAudio.length, decoded,
                AudioConnection.OPUS_FRAME_SIZE, 0);
    }

    //If we get a result that is less than 0, then there was an error. Return null as a signifier.
    if (result < Opus.OPUS_OK)
    {
        handleDecodeError(result);
        return null;
    }

    short[] audio = new short[result * 2];
    decoded.get(audio);
    return audio;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA-Audio,代码行数:35,代码来源:Decoder.java

示例5: allocateBufferSignal

import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void allocateBufferSignal() {
    mSignal = ShortBuffer.allocate(mSignalBufferSize);
}
 
开发者ID:jphacks,项目名称:KB_1711,代码行数:4,代码来源:FSKDecoder.java

示例6: allocateBufferFrame

import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void allocateBufferFrame() {
    mFrame = ShortBuffer.allocate(mConfig.samplesPerBit); // one frame contains one bit
}
 
开发者ID:jphacks,项目名称:KB_1711,代码行数:4,代码来源:FSKDecoder.java

示例7: generateShortBuffer

import java.nio.ShortBuffer; //导入方法依赖的package包/类
@Generates private ShortBuffer generateShortBuffer() {
  return ShortBuffer.allocate(generateInt());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:FreshValueGenerator.java


注:本文中的java.nio.ShortBuffer.allocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。