Package java.nio

Examples of java.nio.IntBuffer


        setupEfx();

        final ALCdevice device = AL.getDevice();

        // Create context (only necessary if LWJGL context isn't sufficient, done as example)
        final IntBuffer contextAttribList = BufferUtils.createIntBuffer(8);
        contextAttribList.put(ALC10.ALC_FREQUENCY);
        contextAttribList.put(44100);
        contextAttribList.put(ALC10.ALC_REFRESH);
        contextAttribList.put(60);
        contextAttribList.put(ALC10.ALC_SYNC);
        contextAttribList.put(ALC10.ALC_FALSE);
        contextAttribList.rewind();
        // ALC_MAX_AUXILIARY_SENDS won't go above compile-time max. Set to compile-time max if
        // greater.
        contextAttribList.put(EFX10.ALC_MAX_AUXILIARY_SENDS);
        contextAttribList.put(2);
        final ALCcontext newContext = ALC10.alcCreateContext(device, contextAttribList);
        if (newContext == null) {
            throw new Exception("Failed to create context.");
        }
        final int contextCurResult = ALC10.alcMakeContextCurrent(newContext);
        if (contextCurResult == ALC10.ALC_FALSE) {
            throw new Exception("Failed to make context current.");
        }

        // Query EFX ALC values
        System.out.println("AL_VERSION: " + AL10.alGetString(AL10.AL_VERSION));
        final IntBuffer buff = BufferUtils.createIntBuffer(1);
        ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, buff);
        System.out.println("ALC_EFX_MAJOR_VERSION: " + buff.get(0));
        ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, buff);
        System.out.println("ALC_EFX_MINOR_VERSION: " + buff.get(0));
        ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, buff);
        final int maxAuxSends = buff.get(0);
        System.out.println("ALC_MAX_AUXILIARY_SENDS: " + maxAuxSends);


        // Try to create 4 Auxiliary Effect Slots
        int numAuxSlots = 0;
        final int[] auxEffectSlots = new int[4]; // try more to test
        AL10.alGetError();
        for (numAuxSlots = 0; numAuxSlots < 4; numAuxSlots++) {
            auxEffectSlots[numAuxSlots] = EFX10.alGenAuxiliaryEffectSlots();
            if (AL10.alGetError() != AL10.AL_NO_ERROR) {
                break;
            }
        }
        System.out.println("Created " + numAuxSlots + " aux effect slots.");

        // Try to create 2 Effects
        int numEffects = 0;
        final int[] effects = new int[2];
        for (numEffects = 0; numEffects < 2; numEffects++) {
            effects[numEffects] = EFX10.alGenEffects();
            if (AL10.alGetError() != AL10.AL_NO_ERROR) {
                break;
            }
        }
        System.out.println("Created " + numEffects + " effects.");

        // Set first Effect Type to Reverb and change Decay Time
        AL10.alGetError();
        if (EFX10.alIsEffect(effects[0])) {
            EFX10.alEffecti(effects[0], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB);
            if (AL10.alGetError() != AL10.AL_NO_ERROR) {
                System.out.println("Reverb effect not supported.");
            } else {
                EFX10.alEffectf(effects[0], EFX10.AL_REVERB_DECAY_TIME, 5.0f);
                System.out.println("Reverb effect created.");
            }
        } else {
            throw new Exception("First effect not a valid effect.");
        }

        // Set second Effect Type to Flanger and change Phase
        AL10.alGetError();
        if (EFX10.alIsEffect(effects[1])) {
            EFX10.alEffecti(effects[1], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_FLANGER);
            if (AL10.alGetError() != AL10.AL_NO_ERROR) {
                System.out.println("Flanger effect not support.");
            } else {
                EFX10.alEffecti(effects[1], EFX10.AL_FLANGER_PHASE, 180);
                System.out.println("Flanger effect created.");
            }
        } else {
            throw new Exception("Second effect not a valid effect.");
        }

        // Try to create a Filter
        AL10.alGetError();
        final int filter = EFX10.alGenFilters();
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            throw new Exception("Failed to create filter.");
        }
        System.out.println("Generated a filter.");
        if (EFX10.alIsFilter(filter)) {
            // Set Filter type to Low-Pass and set parameters
            EFX10.alFilteri(filter, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS);
            if (AL10.alGetError() != AL10.AL_NO_ERROR) {
                System.out.println("Low pass filter not supported.");
            } else {
                EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAIN, 0.5f);
                EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAINHF, 0.5f);
                System.out.println("Low pass filter created.");
            }
        }

        // Attach Effect to Auxiliary Effect Slot
        AL10.alGetError();
        EFX10.alAuxiliaryEffectSloti(auxEffectSlots[0], EFX10.AL_EFFECTSLOT_EFFECT, effects[0]);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            throw new Exception("Failed to attach effect to aux effect slot.");
        }
        System.out.println("Successfully loaded effect into effect slot.");

        // Configure Source Auxiliary Effect Slot Sends
        final int source = AL10.alGenSources();
        // Set Source Send 0 to feed auxEffectSlots[0] without filtering
        AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0,
                EFX10.AL_FILTER_NULL);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            throw new Exception("Failed to configure Source Send 0");
        }
        System.out.println("Linked aux effect slot to soutce slot 0");
        // Set Source Send 1 to feed uiEffectSlot[1] with filter filter
        AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[1], 1, filter);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            // e.g. if only 1 send per source is available
            throw new Exception("Failed to configure Source Send 1");
        }
        System.out.println("Linked aux effect slot to soutce slot 1");
        // Disable Send 0
        AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 0,
                EFX10.AL_FILTER_NULL);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            throw new Exception("Failed to disable Source Send 0");
        }
        System.out.println("Disabled source send 0");
        // Disable Send 1
        AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 1,
                EFX10.AL_FILTER_NULL);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            throw new Exception("Failed to disable Source Send 1");
        }
        System.out.println("Disabled source send 1");


        // Filter 'source', a generated Source
        AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, filter);
        if (AL10.alGetError() == AL10.AL_NO_ERROR) {
            {
                System.out.println("Successfully applied a direct path filter");
                // Remove filter from 'source'
                AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL);
                if (AL10.alGetError() == AL10.AL_NO_ERROR) {
                    System.out.println("Successfully removed direct filter");
                }
            }
            // Filter the Source send 0 from 'source' to Auxiliary Effect Slot auxEffectSlot[0]
            // using Filter uiFilter[0]
            AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, filter);
            if (AL10.alGetError() == AL10.AL_NO_ERROR) {
                {
                    System.out.println("Successfully applied aux send filter");
                    // Remove Filter from Source Auxiliary Send
                    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0,
                            EFX10.AL_FILTER_NULL);
                    if (AL10.alGetError() == AL10.AL_NO_ERROR) {
                        System.out.println("Successfully removed filter");
                    }
                }
            }
        }

        // Set Source Cone Outer Gain HF value
        AL10.alSourcef(source, EFX10.AL_CONE_OUTER_GAINHF, 0.5f);
        if (AL10.alGetError() == AL10.AL_NO_ERROR) {
            System.out.println("Successfully set cone outside gain filter");
        }

        // Set distance units to be in feet
        AL10.alListenerf(EFX10.AL_METERS_PER_UNIT, 0.3f);
        if (AL10.alGetError() == AL10.AL_NO_ERROR) {
            System.out.println("Successfully set distance units");
        }

        // Cleanup
        final IntBuffer auxEffectSlotsBuf = (IntBuffer) BufferUtils.createIntBuffer(
                auxEffectSlots.length).put(auxEffectSlots).rewind();
        EFX10.alDeleteAuxiliaryEffectSlots(auxEffectSlotsBuf);
        final IntBuffer effectsBuf = (IntBuffer) BufferUtils.createIntBuffer(
                effects.length).put(effects).rewind();
        EFX10.alDeleteEffects(effectsBuf);
        EFX10.alDeleteFilters(filter);
        AL.destroy();
    }
View Full Code Here


      e.printStackTrace();
      exit(-1);
    }

    //create 1 buffer and 1 source
    IntBuffer buffers = BufferUtils.createIntBuffer(1);
    IntBuffer sources = BufferUtils.createIntBuffer(1);

    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //load wave data
    WaveData wavefile = WaveData.create(args[0]);

    //copy to buffers
    AL10.alBufferData(
      buffers.get(0),
      wavefile.format,
      wavefile.data,
      wavefile.samplerate);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //unload file again
    wavefile.dispose();

    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    AL10.alSourcef(sources.get(0), AL10.AL_REFERENCE_DISTANCE, 1024.0f);
    AL10.alSourcef(sources.get(0), AL10.AL_ROLLOFF_FACTOR, 0.5f);

    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }
   
    System.out.println("Move source with arrow keys\nMove listener with right shift and arrowkeys\nExit with ESC");

    while(!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
      Display.update();
     
      Keyboard.poll();
      if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        if(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
          listenerPosition.x -= MOVEMENT;
          AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
          System.out.println("listenerx: " + listenerPosition.x);
        } else {
          sourcePosition.x -= MOVEMENT;
          AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
          System.out.println("sourcex: " + sourcePosition.x);
        }
      }     
      if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        if(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
          listenerPosition.x += MOVEMENT;
          AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
          System.out.println("listenerx: " + listenerPosition.x);
        } else {       
          sourcePosition.x += MOVEMENT;
          AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
          System.out.println("sourcex: " + sourcePosition.x);
        }
      }
     
      if(Display.isCloseRequested()) {
        break;
      }
    
      try {
        Thread.sleep(100);
      } catch (InterruptedException inte) {
      }
    }

    //stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }
View Full Code Here

    AL.destroy();
  }

  private void printALCInfo() {
    IntBuffer version = BufferUtils.createIntBuffer(2);
    ALCdevice device;

    if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATION_EXT")) {
          if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATE_ALL_EXT")) {
              printDevices(ALC11.ALC_ALL_DEVICES_SPECIFIER, "playback");
          } else {
              printDevices(ALC10.ALC_DEVICE_SPECIFIER, "playback");
          }
          printDevices(ALC11.ALC_CAPTURE_DEVICE_SPECIFIER, "capture");
      } else {
        System.out.println("No device enumeration available");
    }

    device = ALC10.alcGetContextsDevice(ALC10.alcGetCurrentContext());
    checkForErrors();

      System.out.println("Default playback device: " + ALC10.alcGetString(device, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER));

      System.out.println("Default capture device: " + ALC10.alcGetString(device, ALC11.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));

      ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, version);
      ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, (IntBuffer) version.position(1));
      checkForErrors();

      System.out.println("ALC version: " + version.get(0) + "." + version.get(1));

      System.out.println("ALC extensions:");
      String[] extensions = ALC10.alcGetString(device, ALC10.ALC_EXTENSIONS).split(" ");
    for ( String extension : extensions ) {
      if ( extension.trim().length() == 0 ) {
View Full Code Here

      System.out.println("EFX not available");
      return;
    }

    ALCdevice device = AL.getDevice();
        IntBuffer major = BufferUtils.createIntBuffer(1);
        IntBuffer minor = BufferUtils.createIntBuffer(1);
        IntBuffer sends = BufferUtils.createIntBuffer(1);
        ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, major);
        ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, minor);
        if(ALC10.alcGetError(device) == ALC10.ALC_NO_ERROR) {
          System.out.println("EFX version: " + major.get() + "." + minor.get());
        }

        ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, sends);
        if(ALC10.alcGetError(device) == ALC10.ALC_NO_ERROR) {
          System.out.println("Max auxiliary sends: " + sends.get());
        }

        System.out.println("Supported filters: ");
        HashMap<String, Integer> filters = new HashMap<String, Integer>();
        filters.put("Low-pass", EFX10.AL_FILTER_LOWPASS);
View Full Code Here

    }

    public int[] transferBuffer(final long pageOffset, final int aryLength) {
        final int[] newPage = new int[aryLength];
        final CloseableMappedByteBuffer buf = allocateBuffer(pageOffset);
        final IntBuffer ibuf = buf.getBuffer().asIntBuffer();
        ibuf.get(newPage, 0, aryLength);
        IOUtils.closeQuietly(buf);
        return newPage;
    }
View Full Code Here

      GLContext.loadOpenGLLibrary();
      try {
        this.peer_info = peer_info;
        this.contextAttribs = attribs;

        IntBuffer attribList;
        if ( attribs != null ) {
          attribList = attribs.getAttribList();
          forwardCompatible = attribs.isForwardCompatible();
        } else {
          attribList = null;
View Full Code Here

      attribCount++;

    if ( attribCount == 0 )
      return null;

    final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);

    if ( !(majorVersion == 1 && minorVersion == 0) ) {
      attribs.put(implementation.getMajorVersionAttrib()).put(majorVersion);
      attribs.put(implementation.getMinorVersionAttrib()).put(minorVersion);
    }
    if ( 0 < layerPlane )
      attribs.put(implementation.getLayerPlaneAttrib()).put(layerPlane);
    if ( 0 < flags )
      attribs.put(implementation.getFlagsAttrib()).put(flags);
    if ( 0 < profileMask )
      attribs.put(implementation.getProfileMaskAttrib()).put(profileMask);
    if ( loseContextOnReset )
      attribs.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB).put(LOSE_CONTEXT_ON_RESET_ARB);

    attribs.put(0);
    attribs.rewind();
    return attribs;
  }
View Full Code Here

  }

  private Object createBlankCursor() throws LWJGLException {
    int width = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CXCURSOR);
    int height = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CYCURSOR);
    IntBuffer pixels = BufferUtils.createIntBuffer(width*height);
    return WindowsDisplay.doCreateCursor(width, height, 0, 0, 1, pixels, null);
  }
View Full Code Here

      ja[i] = iter.getIntNext();
  }

  public ByteBuffer getDataAsByteBuffer() {
    ByteBuffer bb = ByteBuffer.allocate((int) (4 * getSize())); // default big-endian
    IntBuffer ib = bb.asIntBuffer();
    ib.put((int[]) get1DJavaArray(int.class)); // make sure its in canonical order
    return bb;
  }
View Full Code Here

        return (baseType == NCLibrary.NC_SHORT) ? sArray : MAMath.convertUnsigned(sArray);


      case NCLibrary.NC_INT:
      case NCLibrary.NC_UINT:
        IntBuffer ib = bb.asIntBuffer();
        sArray = Array.factory(DataType.INT, shape, ib.array());
        return (baseType == NCLibrary.NC_INT) ? sArray : MAMath.convertUnsigned(sArray);
    }

    return null;
  }
View Full Code Here

TOP

Related Classes of java.nio.IntBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.