Exemplo n.º 1
0
 public void dispose() {
   if (audio.noDevice) return;
   if (bufferID == -1) return;
   audio.freeBuffer(bufferID);
   alDeleteBuffers(bufferID);
   bufferID = -1;
   audio.forget(this);
 }
Exemplo n.º 2
0
 @Override
 public long loop(float volume) {
   if (audio.noDevice) return 0;
   int sourceID = audio.obtainSource(false);
   if (sourceID == -1) return -1;
   long soundId = audio.getSoundId(sourceID);
   alSourcei(sourceID, AL_BUFFER, bufferID);
   alSourcei(sourceID, AL_LOOPING, AL_TRUE);
   alSourcef(sourceID, AL_GAIN, volume);
   alSourcePlay(sourceID);
   return soundId;
 }
Exemplo n.º 3
0
 public void stop() {
   if (sourceID == -1) return;
   audio.freeSource(sourceID);
   sourceID = -1;
   renderedSeconds = 0;
   isPlaying = false;
 }
Exemplo n.º 4
0
 public long play(float volume) {
   if (audio.noDevice) return 0;
   int sourceID = audio.obtainSource(false);
   if (sourceID == -1) {
     // Attempt to recover by stopping the least recently played sound
     audio.retain(this, true);
     sourceID = audio.obtainSource(false);
   } else audio.retain(this, false);
   // In case it still didn't work
   if (sourceID == -1) return -1;
   long soundId = audio.getSoundId(sourceID);
   alSourcei(sourceID, AL_BUFFER, bufferID);
   alSourcei(sourceID, AL_LOOPING, AL_FALSE);
   alSourcef(sourceID, AL_GAIN, volume);
   alSourcePlay(sourceID);
   return soundId;
 }
Exemplo n.º 5
0
 public void dispose() {
   if (buffers == null) return;
   if (sourceID != -1) {
     audio.freeSource(sourceID);
     sourceID = -1;
   }
   alDeleteBuffers(buffers);
   buffers = null;
 }
Exemplo n.º 6
0
  public void writeSamples(byte[] data, int offset, int length) {
    if (length < 0) throw new IllegalArgumentException("length cannot be < 0.");

    if (sourceID == -1) {
      sourceID = audio.obtainSource(true);
      if (sourceID == -1) return;
      if (buffers == null) {
        buffers = BufferUtils.createIntBuffer(bufferCount);
        alGenBuffers(buffers);
        if (alGetError() != AL_NO_ERROR)
          throw new GdxRuntimeException("Unabe to allocate audio buffers.");
      }
      alSourcei(sourceID, AL_LOOPING, AL_FALSE);
      alSourcef(sourceID, AL_GAIN, volume);
      // Fill initial buffers.
      int queuedBuffers = 0;
      for (int i = 0; i < bufferCount; i++) {
        int bufferID = buffers.get(i);
        int written = Math.min(bufferSize, length);
        tempBuffer.clear();
        tempBuffer.put(data, offset, written).flip();
        alBufferData(bufferID, format, tempBuffer, sampleRate);
        alSourceQueueBuffers(sourceID, bufferID);
        length -= written;
        offset += written;
        queuedBuffers++;
      }
      // Queue rest of buffers, empty.
      tempBuffer.clear().flip();
      for (int i = queuedBuffers; i < bufferCount; i++) {
        int bufferID = buffers.get(i);
        alBufferData(bufferID, format, tempBuffer, sampleRate);
        alSourceQueueBuffers(sourceID, bufferID);
      }
      alSourcePlay(sourceID);
      isPlaying = true;
    }

    while (length > 0) {
      int written = fillBuffer(data, offset, length);
      length -= written;
      offset += written;
    }
  }
Exemplo n.º 7
0
 public void stop() {
   if (audio.noDevice) return;
   audio.stopSourcesWithBuffer(bufferID);
 }
Exemplo n.º 8
0
 @Override
 public void setLooping(long soundId, boolean looping) {
   if (audio.noDevice) return;
   audio.setSoundLooping(soundId, looping);
 }
Exemplo n.º 9
0
 @Override
 public void setPan(long soundId, float pan, float volume) {
   if (audio.noDevice) return;
   audio.setSoundPan(soundId, pan, volume);
 }
Exemplo n.º 10
0
 @Override
 public void setPitch(long soundId, float pitch) {
   if (audio.noDevice) return;
   audio.setSoundPitch(soundId, pitch);
 }
Exemplo n.º 11
0
 @Override
 public void setVolume(long soundId, float volume) {
   if (audio.noDevice) return;
   audio.setSoundGain(soundId, volume);
 }
Exemplo n.º 12
0
 @Override
 public void resume(long soundId) {
   if (audio.noDevice) return;
   audio.resumeSound(soundId);
 }
Exemplo n.º 13
0
 @Override
 public void resume() {
   if (audio.noDevice) return;
   audio.resumeSourcesWithBuffer(bufferID);
 }
Exemplo n.º 14
0
 @Override
 public void pause(long soundId) {
   if (audio.noDevice) return;
   audio.pauseSound(soundId);
 }
Exemplo n.º 15
0
 @Override
 public void pause() {
   if (audio.noDevice) return;
   audio.pauseSourcesWithBuffer(bufferID);
 }
Exemplo n.º 16
0
 @Override
 public void stop(long soundId) {
   if (audio.noDevice) return;
   audio.stopSound(soundId);
 }