Exemple #1
0
 public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
   // The listener is reset
   AlUtils.resetAlListener();
   // the orientation is changed
   AlUtils.setAlListenerOrientation(0.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f);
   // we set sound context
   AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
   AL10.alDopplerFactor(0.8f);
   // We play the two sounds since we enter
   sonG.loop(1f, 1f, 0f, 0f, 0f);
   sonD.loop(1f, 1f, 0f, 0f, 0f);
   AL10.alSourcef(sonG.getIndex(), AL10.AL_ROLLOFF_FACTOR, 1.5f);
   AL10.alSourcef(sonD.getIndex(), AL10.AL_ROLLOFF_FACTOR, 1.5f);
   // We play the beginning explanation sound
   enterSound.play();
 }
  @Override
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    super.init(gc, sbg);
    input = gc.getInput();
    soundJump = new Sound2(Conf.SND_BIP_PATH + "bip6.ogg");
    soundJump2 = new Sound2(Conf.SND_DEPLACEMENT_PATH + "saut.ogg");
    soundBump = new Sound2(Conf.SND_DEPLACEMENT_PATH + "bump.ogg");
    killedEnemySound = new Sound2(Conf.SND_PERSOS_PATH + "hurt_light2.ogg");
    helpSound = new Sound2(Conf.getVoice("jeuf1"));

    font = new AngelCodeFont(Conf.FONTS_PATH + "hiero.fnt", Conf.FONTS_PATH + "hiero.png");
    // We set Open Al constants about physical world
    AL10.alDopplerFactor(1.0f); // Doppler effect
    AL10.alDopplerVelocity(1.0f); // Sound speed
    AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
    AL10.alDopplerFactor(50.0f);
  }
Exemple #3
0
  public final synchronized boolean initialize() {
    if (!this.gpz) {
      try {
        AL.create();
        bIM();

        AL10.alDistanceModel(53252);

        check();

        this.gpz = true;
      } catch (LWJGLException localLWJGLException) {
        K.warn(
            "Probl?me lors de SoundManager.initialize(). Impossible d'initialiser le SoundManager",
            localLWJGLException);
        this.gpz = false;
        this.gpA = true;
        return false;
      }
    }
    return (!this.aKV) && (blp());
  }
Exemple #4
0
  /** Initialise the sound effects stored. This must be called before anything else will work */
  public void init() {
    if (inited) {
      return;
    }
    System.out.println("Initialising sounds..");
    inited = true;

    AccessController.doPrivileged(
        new PrivilegedAction<Object>() {

          public Object run() {
            try {

              AL.create();
              enumerateDevices();
              soundWorks = true;
              sounds = true;
              music = true;
              System.out.println("- Sound works");
            } catch (Exception e) {
              System.err.println("Sound initialisation failure.");
              System.err.println(e);
              soundWorks = false;
              sounds = false;
              music = false;
            }

            return null;
          }
        });

    if (soundWorks) {
      sourceCount = 0;
      sources = BufferUtils.createIntBuffer(maxSources);
      while (AL10.alGetError() == AL10.AL_NO_ERROR) {
        IntBuffer temp = BufferUtils.createIntBuffer(1);

        try {
          AL10.alGenSources(temp);

          if (AL10.alGetError() == AL10.AL_NO_ERROR) {
            sourceCount++;
            sources.put(temp.get(0));
            if (sourceCount > maxSources - 1) {
              break;
            }
          }
        } catch (OpenALException e) {
          // expected at the end
          break;
        }
      }
      System.out.println("- " + sourceCount + " OpenAL source available");

      if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        sounds = false;
        music = false;
        soundWorks = false;
        System.err.println("- AL init failed");
      } else {
        FloatBuffer listenerOri =
            BufferUtils.createFloatBuffer(6).put(new float[] {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f});
        FloatBuffer listenerVel =
            BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f});
        FloatBuffer listenerPos =
            BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f});
        listenerPos.flip();
        listenerVel.flip();
        listenerOri.flip();
        AL10.alListener(AL10.AL_POSITION, listenerPos);
        AL10.alListener(AL10.AL_VELOCITY, listenerVel);
        AL10.alListener(AL10.AL_ORIENTATION, listenerOri);
        AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE);
        System.out.println("- Sounds source generated");
      }
    }
  }