java.nio.IntBuffer#get ( )源码实例Demo

下面列出了java.nio.IntBuffer#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ure   文件: USpeaker.java
public void start() {
    if (!initialized) return;
    log.debug("buffering playback for bgm '" + filename + "' on deck " + deckID);
    sampleIndex = new AtomicInteger();
    track = new VorbisTrack(config.getResourcePath() + filename, sampleIndex);
    this.format = track.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
    this.pcm = memAllocShort(BUFFER_SIZE);
    alcSetThreadContext(context);
    IntBuffer b = makePlaySource(0f);
    source = b.get(0);
    //alSourcei(source, AL_DIRECT_CHANNELS_SOFT, AL_TRUE);
    buffers = memAllocInt(2);
    alGenBuffers(buffers);
    for (int i=0;i<buffers.limit();i++) {
        if (stream(buffers.get(i))==0) {
            log.error("failed to buffer " + filename);
            return;
        }
    }
    alSourceQueueBuffers(source,buffers);
    alSourcePlay(source);
    log.info("playback started for bgm '" + filename + "' on deck " + deckID);
}
 
源代码2 项目: deeplearning4j   文件: IntegerArrayIO.java
public static int[] readArray(InputStream input) throws IOException {
    DataInputStream dataInput = new DataInputStream(input);
    int length = dataInput.readInt();

    ByteBuffer tmpBuffer = ByteBuffer.allocate(length * INT_BYTES);
    ReadableByteChannel channel = Channels.newChannel(dataInput);
    channel.read(tmpBuffer);

    tmpBuffer.rewind();
    IntBuffer intBuffer = tmpBuffer.asIntBuffer();

    int[] array = new int[length];
    intBuffer.get(array);

    return array;
}
 
源代码3 项目: ure   文件: VorbisTrack.java
VorbisTrack(String filePath, AtomicInteger sampleIndex) {
    try {
        encodedAudio = ioResourceToByteBuffer(filePath, 256*1024);
    } catch (IOException e) { e.printStackTrace(); }

    try (MemoryStack stack = stackPush()) {
        IntBuffer error = stack.mallocInt(1);
        handle = stb_vorbis_open_memory(encodedAudio,error,null);
        if (handle == NULL)
            throw new RuntimeException("Failed to open OGG file.  Error: " + error.get(0));
        STBVorbisInfo info = STBVorbisInfo.mallocStack(stack);
        stb_vorbis_get_info(handle, info);
        this.channels = info.channels();
        this.sampleRate = info.sample_rate();
        log.debug("vorbis file detected " + Integer.toString(channels) + " channel " + Integer.toString(sampleRate) + " samplerate");
    }
    this.samplesLength = stb_vorbis_stream_length_in_samples(handle);
    this.samplesSec = stb_vorbis_stream_length_in_seconds(handle);
    this.sampleIndex = sampleIndex;
    sampleIndex.set(0);
}
 
源代码4 项目: Monocle   文件: MonocleRobot.java
@Override
public void getScreenCapture(int x, int y, int width, int height, int[] data, boolean scaleToFit) {
    Application.checkEventThread();
    NativeScreen screen = NativePlatformFactory.getNativePlatform().getScreen();
    final int scrWidth = screen.getWidth();
    final int scrHeight = screen.getHeight();

    synchronized (NativeScreen.framebufferSwapLock) {
        IntBuffer buffer = screen.getScreenCapture().asIntBuffer();

        if (x == 0 && y == 0 && width == scrWidth && height == scrHeight) {
            // Easy case, the entire screen is being captured.
            System.arraycopy(buffer.array(), 0, data, 0, buffer.array().length);
            return;
        }

        int rowStop = Math.min(y + height, scrHeight);
        int colStop = Math.min(x + width, scrWidth);
        for (int row = y; row < rowStop; row++) {
            for (int col = x; col < colStop; col++) {
                data[(row - y) * (colStop - x) + (col - x)] = buffer.get(row * scrWidth + col);
            }
        }
    }
}
 
源代码5 项目: JavaAV   文件: Image.java
public static void copy(IntBuffer srcBuf, int srcStep, IntBuffer dstBuf, int dstStep) {
	int w = Math.min(srcStep, dstStep);
	int srcLine = srcBuf.position();
	int dstLine = dstBuf.position();

	while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) {
		srcBuf.position(srcLine);
		dstBuf.position(dstLine);

		w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining());

		for (int x = 0; x < w; x++) {
			int in = srcBuf.get();
			int out = in;
			dstBuf.put(out);
		}

		srcLine += srcStep;
		dstLine += dstStep;
	}
}
 
源代码6 项目: lwjglbook   文件: Texture.java
public Texture(ByteBuffer imageBuffer) throws Exception {
    ByteBuffer buf;
    // Load Texture file
    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer channels = stack.mallocInt(1);

        buf = stbi_load_from_memory(imageBuffer, w, h, channels, 4);
        if (buf == null) {
            throw new Exception("Image file not loaded: " + stbi_failure_reason());
        }

        width = w.get();
        height = h.get();
    }

    this.id = createTexture(buf);

    stbi_image_free(buf);
}
 
源代码7 项目: HoloKilo   文件: GLRenderer.java
static public int loadShader(int type, String shaderCode)
{
    int shader = GLES20.glCreateShader(type);

    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);
    IntBuffer compile = IntBuffer.allocate(1);
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compile);
    if (compile.get(0) == GLES20.GL_FALSE) {
        Log.e(Config.TAG, "Error:");
        Log.e(Config.TAG, shaderCode);
        Log.e(Config.TAG, "Fault:");
        printLog(shader);
        return 0;
    }

    return shader;
}
 
源代码8 项目: djl   文件: NDArray.java
/**
 * Converts this {@code NDArray} to an int array.
 *
 * @return an int array
 * @throws IllegalStateException when {@link DataType} of this {@code NDArray} mismatches
 */
default int[] toIntArray() {
    if (getDataType() != DataType.INT32) {
        throw new IllegalStateException(
                "DataType mismatch, Required int" + " Actual " + getDataType());
    }
    IntBuffer ib = toByteBuffer().asIntBuffer();
    int[] ret = new int[ib.remaining()];
    ib.get(ret);
    return ret;
}
 
源代码9 项目: Sound-Physics   文件: SoundPhysics.java
private static int alcGetInt(ALCdevice device, int pname)
{
	ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4);
	IntBuffer intBuffer = byteBuffer.asIntBuffer();
	
	//ALC10.alcGetInteger(device, pname, intBuffer);
	
	return intBuffer.get(0);
}
 
源代码10 项目: metrics   文件: IntBitPacking.java
protected void decompress(
        IntBuffer src,
        IntOutputStream dst,
        IntFilter filter)
{
    while (src.hasRemaining()) {
        int head = src.get();
        for (int i = (this.blockNum - 1) * 8; i >= 0; i -= 8) {
            int validBits = (int)((head >> i) & 0xff);
            unpack(src, dst, validBits, this.blockLen, filter);
        }
    }
    return;
}
 
public ArrayCellManager( final Spread spread , final IntBuffer buffer ){
  int length = buffer.capacity();
  cellArray = new ICell[length];
  int currentIndex = 0;
  for( int i = 0 ; i < length ; i++ ){
    int arrayLength = buffer.get();
    if( arrayLength != 0 ){
      int start = currentIndex;
      int end = start + arrayLength;
      cellArray[i] = new ArrayCell( new SpreadArrayLink( spread , i , start , end ) );
      currentIndex += arrayLength;
    }
  }
}
 
源代码12 项目: Monocle   文件: Framebuffer.java
void write(WritableByteChannel out) throws IOException {
    bb.clear();
    if (byteDepth == 4) {
        out.write(bb);
    } else if (byteDepth == 2) {
        if (lineByteBuffer == null) {
            lineByteBuffer = ByteBuffer.allocate(width * 2);
            lineByteBuffer.order(ByteOrder.nativeOrder());
            linePixelBuffer = lineByteBuffer.asShortBuffer();
        }
        IntBuffer srcPixels = bb.asIntBuffer();
        ShortBuffer shortBuffer = (ShortBuffer) linePixelBuffer;
        for (int i = 0; i < height; i++) {
            shortBuffer.clear();
            for (int j = 0; j < width; j++) {
                int pixel32 = srcPixels.get();
                int r = ((((pixel32 >> 19) & 31) * 539219) >> 8) & (31 << 11);
                int g = ((((pixel32 >> 10) & 63) * 265395) >> 13) & (63 << 5);
                int b = (((pixel32 >> 3) & 31) * 539219) >> 19;
                int pixel16 = r | g | b;
                shortBuffer.put((short) pixel16);
            }
            lineByteBuffer.clear();
            out.write(lineByteBuffer);
        }
    }
}
 
源代码13 项目: lwjglbook   文件: Terrain.java
/**
 * A Terrain is composed by blocks, each block is a GameItem constructed
 * from a HeightMap.
 *
 * @param terrainSize The number of blocks will be terrainSize * terrainSize
 * @param scale The scale to be applied to each terrain block
 * @param minY The minimum y value, before scaling, of each terrain block
 * @param maxY The maximum y value, before scaling, of each terrain block
 * @param heightMapFile
 * @param textureFile
 * @param textInc
 * @throws Exception
 */
public Terrain(int terrainSize, float scale, float minY, float maxY, String heightMapFile, String textureFile, int textInc) throws Exception {
    this.terrainSize = terrainSize;
    gameItems = new GameItem[terrainSize * terrainSize];

    ByteBuffer buf = null;
    int width;
    int height;
    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer channels = stack.mallocInt(1);

        buf = stbi_load(heightMapFile, w, h, channels, 4);
        if (buf == null) {
            throw new Exception("Image file [" + heightMapFile  + "] not loaded: " + stbi_failure_reason());
        }

        width = w.get();
        height = h.get();
    }

    // The number of vertices per column and row
    verticesPerCol = width - 1;
    verticesPerRow = height - 1;

    heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc);
    boundingBoxes = new Box2D[terrainSize][terrainSize];
    for (int row = 0; row < terrainSize; row++) {
        for (int col = 0; col < terrainSize; col++) {
            float xDisplacement = (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength();
            float zDisplacement = (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength();

            GameItem terrainBlock = new GameItem(heightMapMesh.getMesh());
            terrainBlock.setScale(scale);
            terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
            gameItems[row * terrainSize + col] = terrainBlock;

            boundingBoxes[row][col] = getBoundingBox(terrainBlock);
        }
    }

    stbi_image_free(buf);
}
 
源代码14 项目: metrics   文件: IntBitPackingUnpacks.java
public static void unpack25(
        int[] buf,
        IntBuffer src,
        IntOutputStream dst,
        IntFilter filter)
{
    final int m = 0x1ffffff;
    int n, c;

    n = src.get();
    buf[ 0] = filter.filterInt(n >>>  7 & m);
    c = n << 18 & m;
    n = src.get();
    buf[ 1] = filter.filterInt(c | n >>> 14);
    c = n << 11 & m;
    n = src.get();
    buf[ 2] = filter.filterInt(c | n >>> 21);
    c = n <<  4 & m;
    n = src.get();
    buf[ 3] = filter.filterInt(c | n >>> 28);
    buf[ 4] = filter.filterInt(n >>>  3 & m);
    c = n << 22 & m;
    n = src.get();
    buf[ 5] = filter.filterInt(c | n >>> 10);
    c = n << 15 & m;
    n = src.get();
    buf[ 6] = filter.filterInt(c | n >>> 17);
    c = n <<  8 & m;
    n = src.get();
    buf[ 7] = filter.filterInt(c | n >>> 24);
    c = n <<  1 & m;
    n = src.get();
    buf[ 8] = filter.filterInt(c | n >>> 31);
    buf[ 9] = filter.filterInt(n >>>  6 & m);
    c = n << 19 & m;
    n = src.get();
    buf[10] = filter.filterInt(c | n >>> 13);
    c = n << 12 & m;
    n = src.get();
    buf[11] = filter.filterInt(c | n >>> 20);
    c = n <<  5 & m;
    n = src.get();
    buf[12] = filter.filterInt(c | n >>> 27);
    buf[13] = filter.filterInt(n >>>  2 & m);
    c = n << 23 & m;
    n = src.get();
    buf[14] = filter.filterInt(c | n >>>  9);
    c = n << 16 & m;
    n = src.get();
    buf[15] = filter.filterInt(c | n >>> 16);
    c = n <<  9 & m;
    n = src.get();
    buf[16] = filter.filterInt(c | n >>> 23);
    c = n <<  2 & m;
    n = src.get();
    buf[17] = filter.filterInt(c | n >>> 30);
    buf[18] = filter.filterInt(n >>>  5 & m);
    c = n << 20 & m;
    n = src.get();
    buf[19] = filter.filterInt(c | n >>> 12);
    c = n << 13 & m;
    n = src.get();
    buf[20] = filter.filterInt(c | n >>> 19);
    c = n <<  6 & m;
    n = src.get();
    buf[21] = filter.filterInt(c | n >>> 26);
    buf[22] = filter.filterInt(n >>>  1 & m);
    c = n << 24 & m;
    n = src.get();
    buf[23] = filter.filterInt(c | n >>>  8);
    c = n << 17 & m;
    n = src.get();
    buf[24] = filter.filterInt(c | n >>> 15);
    c = n << 10 & m;
    n = src.get();
    buf[25] = filter.filterInt(c | n >>> 22);
    c = n <<  3 & m;
    n = src.get();
    buf[26] = filter.filterInt(c | n >>> 29);
    buf[27] = filter.filterInt(n >>>  4 & m);
    c = n << 21 & m;
    n = src.get();
    buf[28] = filter.filterInt(c | n >>> 11);
    c = n << 14 & m;
    n = src.get();
    buf[29] = filter.filterInt(c | n >>> 18);
    c = n <<  7 & m;
    n = src.get();
    buf[30] = filter.filterInt(c | n >>> 25);
    buf[31] = filter.filterInt(n >>>  0 & m);

    dst.write(buf, 0, 32);
}
 
源代码15 项目: djl   文件: JnaUtils.java
public static int getGpuCount() {
    IntBuffer count = IntBuffer.allocate(1);
    checkCall(LIB.MXGetGPUCount(count));

    return count.get();
}
 
源代码16 项目: diozero   文件: TinkerBoardMmapGpio.java
@Override
public void setMode(int gpio, DeviceMode mode) {
	IntBuffer mux_int_buffer = (gpio < 24) ? pmuIntBuffer : grfIntBuffer;
	int iomux_offset = getIoMuxOffsetForGpio(gpio);
	if (iomux_offset == UNKNOWN) {
		Logger.warn("Unknown IOMUX offset for GPIO #{}", Integer.valueOf(gpio));
		return;
	}
	// Configure mode
	int config_val = mux_int_buffer.get(iomux_offset);
	switch (mode) {
	case DIGITAL_INPUT:
	case DIGITAL_OUTPUT:
		if (gpio == 238 || gpio == 239) {
			config_val = (config_val | (0x0f<<(16+(gpio%8-4)*4))) & (~(0x0f<<((gpio%8-4)*4)));
		} else {
			config_val = (config_val | (0x03<<((gpio%8)*2+16))) & (~(0x03<<((gpio%8)*2)));
		}
		mux_int_buffer.put(iomux_offset, config_val);
		
		// Set digital direction
		int bank;
		int shift;
		if (gpio < 24) {
			bank = gpio / 32;
			shift = gpio % 32;
		} else {
			bank = (gpio + 8) / 32;
			shift = (gpio + 8) % 32;
		}
		int gpio_val = gpioBanks[bank].gpioIntBuffer.get(GPIO_SWPORTA_DDR_INT_OFFSET);
		if (mode == DeviceMode.DIGITAL_INPUT) {
			gpio_val &= ~(1<<shift);
		} else {
			gpio_val |= (1<<shift);
		}
		gpioBanks[bank].gpioIntBuffer.put(GPIO_SWPORTA_DDR_INT_OFFSET, gpio_val);
		break;
	case PWM_OUTPUT:
		Logger.warn("Mode {} not yet implemented for GPIO #{}", mode, Integer.valueOf(gpio));
		return;
	default:
		Logger.warn("Invalid mode ({}) for GPIO #{}", mode, Integer.valueOf(gpio));
		return;
	}
}
 
源代码17 项目: metrics   文件: IntBitPackingUnpacks.java
public static void unpack17(
        int[] buf,
        IntBuffer src,
        IntOutputStream dst,
        IntFilter filter)
{
    final int m = 0x1ffff;
    int n, c;

    n = src.get();
    buf[ 0] = filter.filterInt(n >>> 15 & m);
    c = n <<  2 & m;
    n = src.get();
    buf[ 1] = filter.filterInt(c | n >>> 30);
    buf[ 2] = filter.filterInt(n >>> 13 & m);
    c = n <<  4 & m;
    n = src.get();
    buf[ 3] = filter.filterInt(c | n >>> 28);
    buf[ 4] = filter.filterInt(n >>> 11 & m);
    c = n <<  6 & m;
    n = src.get();
    buf[ 5] = filter.filterInt(c | n >>> 26);
    buf[ 6] = filter.filterInt(n >>>  9 & m);
    c = n <<  8 & m;
    n = src.get();
    buf[ 7] = filter.filterInt(c | n >>> 24);
    buf[ 8] = filter.filterInt(n >>>  7 & m);
    c = n << 10 & m;
    n = src.get();
    buf[ 9] = filter.filterInt(c | n >>> 22);
    buf[10] = filter.filterInt(n >>>  5 & m);
    c = n << 12 & m;
    n = src.get();
    buf[11] = filter.filterInt(c | n >>> 20);
    buf[12] = filter.filterInt(n >>>  3 & m);
    c = n << 14 & m;
    n = src.get();
    buf[13] = filter.filterInt(c | n >>> 18);
    buf[14] = filter.filterInt(n >>>  1 & m);
    c = n << 16 & m;
    n = src.get();
    buf[15] = filter.filterInt(c | n >>> 16);
    c = n <<  1 & m;
    n = src.get();
    buf[16] = filter.filterInt(c | n >>> 31);
    buf[17] = filter.filterInt(n >>> 14 & m);
    c = n <<  3 & m;
    n = src.get();
    buf[18] = filter.filterInt(c | n >>> 29);
    buf[19] = filter.filterInt(n >>> 12 & m);
    c = n <<  5 & m;
    n = src.get();
    buf[20] = filter.filterInt(c | n >>> 27);
    buf[21] = filter.filterInt(n >>> 10 & m);
    c = n <<  7 & m;
    n = src.get();
    buf[22] = filter.filterInt(c | n >>> 25);
    buf[23] = filter.filterInt(n >>>  8 & m);
    c = n <<  9 & m;
    n = src.get();
    buf[24] = filter.filterInt(c | n >>> 23);
    buf[25] = filter.filterInt(n >>>  6 & m);
    c = n << 11 & m;
    n = src.get();
    buf[26] = filter.filterInt(c | n >>> 21);
    buf[27] = filter.filterInt(n >>>  4 & m);
    c = n << 13 & m;
    n = src.get();
    buf[28] = filter.filterInt(c | n >>> 19);
    buf[29] = filter.filterInt(n >>>  2 & m);
    c = n << 15 & m;
    n = src.get();
    buf[30] = filter.filterInt(c | n >>> 17);
    buf[31] = filter.filterInt(n >>>  0 & m);

    dst.write(buf, 0, 32);
}
 
源代码18 项目: openjdk-8-source   文件: CMap.java
CMapFormat12(ByteBuffer buffer, int offset, char[] xlat) {
    if (xlat != null) {
        throw new RuntimeException("xlat array for cmap fmt=12");
    }

    numGroups = buffer.getInt(offset+12);
    startCharCode = new long[numGroups];
    endCharCode = new long[numGroups];
    startGlyphID = new int[numGroups];
    buffer.position(offset+16);
    buffer = buffer.slice();
    IntBuffer ibuffer = buffer.asIntBuffer();
    for (int i=0; i<numGroups; i++) {
        startCharCode[i] = ibuffer.get() & INTMASK;
        endCharCode[i] = ibuffer.get() & INTMASK;
        startGlyphID[i] = ibuffer.get() & INTMASK;
    }

    /* Finds the high bit by binary searching through the bits */
    int value = numGroups;

    if (value >= 1 << 16) {
        value >>= 16;
        highBit += 16;
    }

    if (value >= 1 << 8) {
        value >>= 8;
        highBit += 8;
    }

    if (value >= 1 << 4) {
        value >>= 4;
        highBit += 4;
    }

    if (value >= 1 << 2) {
        value >>= 2;
        highBit += 2;
    }

    if (value >= 1 << 1) {
        value >>= 1;
        highBit += 1;
    }

    power = 1 << highBit;
    extra = numGroups - power;
}
 
源代码19 项目: jogl-samples   文件: Gl_320_query_occlusion.java
private boolean initQuery(GL3 gl3) {

        gl3.glGenQueries(1, queryName);

        IntBuffer queryBits = GLBuffers.newDirectIntBuffer(1);
        gl3.glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, queryBits);

        boolean validated = queryBits.get(0) >= 32;

        BufferUtils.destroyDirectBuffer(queryBits);

        return validated && checkError(gl3, "initQuery");
    }
 
源代码20 项目: jogl-samples   文件: Gl_320_query_conditional.java
private boolean initQuery(GL3 gl3) {

        gl3.glGenQueries(1, queryName);

        IntBuffer queryBits = GLBuffers.newDirectIntBuffer(1);
        gl3.glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, queryBits);

        boolean validated = queryBits.get(0) >= 32;

        BufferUtils.destroyDirectBuffer(queryBits);

        return validated && checkError(gl3, "initQuery");
    }