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


Java ShortBuffer类代码示例

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


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

示例1: draw

import java.nio.ShortBuffer; //导入依赖的package包/类
private void draw(float[] matrix, FloatBuffer vertexBuffer, FloatBuffer uvBuffer, ShortBuffer drawListBuffer, short[] indices) {
    texture.bindTexture(0);
    GLES20.glEnable(GLES20.GL_BLEND_COLOR);
    GLES20.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glDepthMask(false);
    int mPositionHandle = GLES20.glGetAttribLocation(SpriteKitGraphicTools.imageShaderProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(mPositionHandle, 3,
            GLES20.GL_FLOAT, false,
            0, vertexBuffer);
    int mTexCoordLoc = GLES20.glGetAttribLocation(SpriteKitGraphicTools.imageShaderProgram, "a_texCoord");
    GLES20.glEnableVertexAttribArray(mTexCoordLoc);
    GLES20.glVertexAttribPointer(mTexCoordLoc, 2, GLES20.GL_FLOAT,
            false,
            0, uvBuffer);
    int mtrxhandle = GLES20.glGetUniformLocation(SpriteKitGraphicTools.imageShaderProgram, "uMVPMatrix");
    GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, matrix, 0);
    int mSamplerLoc = GLES20.glGetUniformLocation(SpriteKitGraphicTools.imageShaderProgram, "s_texture");
    GLES20.glUniform1i(mSamplerLoc, 0);
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length,
            GLES20.GL_UNSIGNED_SHORT, drawListBuffer);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTexCoordLoc);
    GLES20.glDisable(GLES20.GL_BLEND_COLOR);
}
 
开发者ID:sakkeerhussain,项目名称:SpriteKit-Android,代码行数:26,代码来源:Sprite.java

示例2: convertAudioBytes

import java.nio.ShortBuffer; //导入依赖的package包/类
/**
 * Convert the audio bytes into the stream
 * 
 * @param format The audio format being decoded
 * @param audio_bytes The audio byts
 * @param two_bytes_data True if we using double byte data
 * @return The byte bufer of data
 */
private static ByteBuffer convertAudioBytes(AudioFormat format, byte[] audio_bytes, boolean two_bytes_data) {
	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);
			}
			dest.put(b);
		}
	}
	dest.rewind();
	return dest;
}
 
开发者ID:imaTowan,项目名称:Towan,代码行数:31,代码来源:AiffData.java

示例3: readSequenceFrom

import java.nio.ShortBuffer; //导入依赖的package包/类
public Instruction[] readSequenceFrom(ShortBuffer buffer, int startIndex, int length,
    OffsetToObjectMapping mapping) {
  ShortBufferBytecodeStream range =
      new ShortBufferBytecodeStream(buffer, startIndex, length);
  List<Instruction> insn = new ArrayList<>(length);
  while (range.hasMore()) {
    Instruction instruction = readFrom(range, mapping);
    if (instruction instanceof ConstString) {
      updateHighestSortingString(((ConstString) instruction).getString());
    } else if (instruction instanceof ConstStringJumbo) {
      updateHighestSortingString(((ConstStringJumbo) instruction).getString());
    }
    insn.add(instruction);
  }
  return insn.toArray(new Instruction[insn.size()]);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:17,代码来源:InstructionFactory.java

示例4: isDirect

import java.nio.ShortBuffer; //导入依赖的package包/类
private static boolean isDirect(Buffer buf) {
    if (buf instanceof FloatBuffer) {
        return ((FloatBuffer) buf).isDirect();
    }
    if (buf instanceof IntBuffer) {
        return ((IntBuffer) buf).isDirect();
    }
    if (buf instanceof ShortBuffer) {
        return ((ShortBuffer) buf).isDirect();
    }
    if (buf instanceof ByteBuffer) {
        return ((ByteBuffer) buf).isDirect();
    }
    if (buf instanceof DoubleBuffer) {
        return ((DoubleBuffer) buf).isDirect();
    }
    if (buf instanceof LongBuffer) {
        return ((LongBuffer) buf).isDirect();
    }
    throw new UnsupportedOperationException(" BufferAux.isDirect was called on " + buf.getClass().getName());
}
 
开发者ID:asiermarzo,项目名称:Ultraino,代码行数:22,代码来源:BufferUtils.java

示例5: queueInput

import java.nio.ShortBuffer; //导入依赖的package包/类
@Override
public void queueInput(ByteBuffer inputBuffer) {
  if (inputBuffer.hasRemaining()) {
    ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
    int inputSize = inputBuffer.remaining();
    inputBytes += inputSize;
    sonic.queueInput(shortBuffer);
    inputBuffer.position(inputBuffer.position() + inputSize);
  }
  int outputSize = sonic.getSamplesAvailable() * channelCount * 2;
  if (outputSize > 0) {
    if (buffer.capacity() < outputSize) {
      buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder());
      shortBuffer = buffer.asShortBuffer();
    } else {
      buffer.clear();
      shortBuffer.clear();
    }
    sonic.getOutput(shortBuffer);
    outputBytes += outputSize;
    buffer.limit(outputSize);
    outputBuffer = buffer;
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:25,代码来源:SonicAudioProcessor.java

示例6: convertAudioBytes

import java.nio.ShortBuffer; //导入依赖的package包/类
/**
 * Convert the audio bytes into the stream
 * 
 * @param audio_bytes The audio byts
 * @param two_bytes_data True if we using double byte data
 * @return The byte bufer of data
 */
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data) {
	ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
	dest.order(ByteOrder.nativeOrder());
	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());
	} else {
		while (src.hasRemaining())
			dest.put(src.get());
	}
	dest.rewind();
	return dest;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:25,代码来源:WaveData.java

示例7: 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

示例8: testShortGet

import java.nio.ShortBuffer; //导入依赖的package包/类
@Test(dataProvider = "shortViewProvider")
public void testShortGet(String desc, IntFunction<ByteBuffer> fbb,
                         Function<ByteBuffer, ShortBuffer> fbi) {
    ByteBuffer bb = allocate(fbb);
    ShortBuffer vb = fbi.apply(bb);
    int o = bb.position();

    for (int i = 0; i < vb.limit(); i++) {
        short fromBytes = getShortFromBytes(bb, o + i * 2);
        short fromMethodView = bb.getShort(o + i * 2);
        assertValues(i, fromBytes, fromMethodView, bb);

        short fromBufferView = vb.get(i);
        assertValues(i, fromMethodView, fromBufferView, bb, vb);
    }

    for (int i = 0; i < vb.limit(); i++) {
        short v = getShortFromBytes(bb, o + i * 2);
        short a = bb.getShort();
        assertValues(i, v, a, bb);

        short b = vb.get();
        assertValues(i, a, b, bb, vb);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ByteBufferViews.java

示例9: readVorbis

import java.nio.ShortBuffer; //导入依赖的package包/类
private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        vorbis = Utils.ioResourceToByteBuffer(resource, bufferSize);
        IntBuffer error = stack.mallocInt(1);
        long decoder = stb_vorbis_open_memory(vorbis, error, null);
        if (decoder == NULL) {
            throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
        }

        stb_vorbis_get_info(decoder, info);

        int channels = info.channels();

        int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);

        pcm = MemoryUtil.memAllocShort(lengthSamples);

        pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
        stb_vorbis_close(decoder);

        return pcm;
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:24,代码来源:SoundBuffer.java

示例10: 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

示例11: drainOverflow

import java.nio.ShortBuffer; //导入依赖的package包/类
private long drainOverflow(final ShortBuffer outBuff) {
    final ShortBuffer overflowBuff = mOverflowBuffer.data;
    final int overflowLimit = overflowBuff.limit();
    final int overflowSize = overflowBuff.remaining();

    final long beginPresentationTimeUs = mOverflowBuffer.presentationTimeUs +
            sampleCountToDurationUs(overflowBuff.position(), mInputSampleRate, mOutputChannelCount);

    outBuff.clear();
    // Limit overflowBuff to outBuff's capacity
    overflowBuff.limit(outBuff.capacity());
    // Load overflowBuff onto outBuff
    outBuff.put(overflowBuff);

    if (overflowSize >= outBuff.capacity()) {
        // Overflow fully consumed - Reset
        overflowBuff.clear().limit(0);
    } else {
        // Only partially consumed - Keep position & restore previous limit
        overflowBuff.limit(overflowLimit);
    }

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

示例12: convertAudioBytes

import java.nio.ShortBuffer; //导入依赖的package包/类
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data, ByteOrder order) {
    ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
    dest.order(ByteOrder.nativeOrder());
    ByteBuffer src = ByteBuffer.wrap(audio_bytes);
    src.order(order);
    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())
            dest.put(src.get());
    }
    dest.rewind();
    return dest;
}
 
开发者ID:TauOmicronMu,项目名称:TeamProject,代码行数:18,代码来源:WaveData.java

示例13: allocate

import java.nio.ShortBuffer; //导入依赖的package包/类
private void allocate(){
	ByteBuffer buffer = ResourceLoader.getBytes(path);
	IntBuffer error = BufferUtils.createIntBuffer(1);
	long decoder = stb_vorbis_open_memory(buffer, error, null);
	if(decoder == 0L){
		Application.error("Unable to open STB Vorbis");
		return;
	}
	
	STBVorbisInfo info = STBVorbisInfo.malloc();
	
	stb_vorbis_get_info(decoder, info);
	
	int channels = info.channels();
	int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
	ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples);
	pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
	stb_vorbis_close(decoder);
	
	AL10.alBufferData(id, info.channels() == 1? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, info.sample_rate());
}
 
开发者ID:tek256,项目名称:LD38,代码行数:22,代码来源:Sound.java

示例14: run

import java.nio.ShortBuffer; //导入依赖的package包/类
public void run() {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
    this.isInitialized = false;
    if (audioRecord != null) {
        //判断音频录制是否被初始化
        while (this.audioRecord.getState() == 0) {
            try {
                Thread.sleep(100L);
            } catch (InterruptedException localInterruptedException) {
            }
        }
        this.isInitialized = true;
        this.audioRecord.startRecording();
        while (((runAudioThread) || (mVideoTimestamp > mAudioTimestamp)) && (mAudioTimestamp < (1000 * RECORDING_TIME))) {
            updateTimestamp();
            bufferReadResult = this.audioRecord.read(audioData, 0, audioData.length);
            if ((bufferReadResult > 0) && ((recording && rec) || (mVideoTimestamp > mAudioTimestamp)))
                record(ShortBuffer.wrap(audioData, 0, bufferReadResult));
        }
        this.audioRecord.stop();
        this.audioRecord.release();
    }
}
 
开发者ID:feigxj,项目名称:VideoRecorder-master,代码行数:24,代码来源:FFmpegRecorderActivity.java

示例15: 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


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