當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。