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


Java ShortBuffer.flip方法代码示例

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


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

示例1: ensureLargeEnough

import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) {
    if (buffer != null) {
        buffer.limit(buffer.capacity());
    }
    if (buffer == null || (buffer.remaining() < required)) {
        int position = (buffer != null ? buffer.position() : 0);
        ShortBuffer newVerts = createShortBuffer(position + required);
        if (buffer != null) {
            buffer.flip();
            newVerts.put(buffer);
            newVerts.position(position);
        }
        buffer = newVerts;
    }
    return buffer;
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:17,代码来源: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: setData

import java.nio.ShortBuffer; //导入方法依赖的package包/类
public void setData(short[] in) {
    validate(); 
    ShortBuffer buffer = ShortBuffer.wrap(in); 
    buffer.position(in.length - 1); 
    buffer.flip(); 
    oal.alBufferData(id[0], OalConvert.getFormat(stereo, sixteenBit), buffer, in.length * 2 - 4, frequency);
}
 
开发者ID:HuskyGameDev,项目名称:2017-TeamEngine,代码行数:8,代码来源:OalAudioClip.java

示例4: remixAndMaybeFillOverflow

import java.nio.ShortBuffer; //导入方法依赖的package包/类
private long remixAndMaybeFillOverflow(final AudioBuffer input,
                                       final ShortBuffer outBuff) {
    final ShortBuffer inBuff = input.data;
    final ShortBuffer overflowBuff = mOverflowBuffer.data;

    outBuff.clear();

    // Reset position to 0, and set limit to capacity (Since MediaCodec doesn't do that for us)
    inBuff.clear();

    if (inBuff.remaining() > outBuff.remaining()) {
        // Overflow
        // Limit inBuff to outBuff's capacity
        inBuff.limit(outBuff.capacity());
        mRemixer.remix(inBuff, outBuff);

        // Reset limit to its own capacity & Keep position
        inBuff.limit(inBuff.capacity());

        // Remix the rest onto overflowBuffer
        // NOTE: We should only reach this point when overflow buffer is empty
        final long consumedDurationUs =
                sampleCountToDurationUs(inBuff.position(), mInputSampleRate, mInputChannelCount);
        mRemixer.remix(inBuff, overflowBuff);

        // Seal off overflowBuff & mark limit
        overflowBuff.flip();
        mOverflowBuffer.presentationTimeUs = input.presentationTimeUs + consumedDurationUs;
    } else {
        // No overflow
        mRemixer.remix(inBuff, outBuff);
    }

    return input.presentationTimeUs;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:36,代码来源:AudioChannel.java

示例5: remixAndMaybeFillOverflow

import java.nio.ShortBuffer; //导入方法依赖的package包/类
private long remixAndMaybeFillOverflow(final AudioBuffer input, final ShortBuffer outBuff) {
    final ShortBuffer inBuff = input.data;
    final ShortBuffer overflowBuff = mOverflowBuffer.data;

    outBuff.clear();

    // Reset position to 0, and set limit to capacity (Since MediaCodec doesn't do that for us)
    inBuff.clear();

    if (inBuff.remaining() > outBuff.remaining()) {
        // Overflow
        // Limit inBuff to outBuff's capacity
        inBuff.limit(outBuff.capacity());
        mRemixer.remix(inBuff, outBuff);

        // Reset limit to its own capacity & Keep position
        inBuff.limit(inBuff.capacity());

        // Remix the rest onto overflowBuffer
        // NOTE: We should only reach this point when overflow buffer is empty
        final long consumedDurationUs = sampleCountToDurationUs(inBuff.position(), mInputSampleRate, mInputChannelCount);
        mRemixer.remix(inBuff, overflowBuff);

        // Seal off overflowBuff & mark limit
        overflowBuff.flip();
        mOverflowBuffer.presentationTimeUs = input.presentationTimeUs + consumedDurationUs;
    } else {
        // No overflow
        mRemixer.remix(inBuff, outBuff);
    }

    return input.presentationTimeUs;
}
 
开发者ID:uestccokey,项目名称:EZFilter,代码行数:34,代码来源:AudioChannel.java

示例6: createShortBuffer

import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer createShortBuffer(short... data) {
    if (data == null) {
        return null;
    }
    ShortBuffer buff = createShortBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:11,代码来源:BufferUtils.java

示例7: createShortBufferFromArray

import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer createShortBufferFromArray(short[] data) {
    if (data == null) {
        return null;
    }
    ShortBuffer buff = createShortBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:11,代码来源:BufferUtils.java


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