コード例 #1
0
ファイル: OpenALAudioDevice.java プロジェクト: Sasun/libgdx
  /** Blocks until some of the data could be buffered. */
  private int fillBuffer(byte[] data, int offset, int length) {
    int written = Math.min(bufferSize, length);

    outer:
    while (true) {
      int buffers = alGetSourcei(sourceID, AL_BUFFERS_PROCESSED);
      while (buffers-- > 0) {
        int bufferID = alSourceUnqueueBuffers(sourceID);
        if (bufferID == AL_INVALID_VALUE) break;
        renderedSeconds += secondsPerBuffer;

        tempBuffer.clear();
        tempBuffer.put(data, offset, written).flip();
        alBufferData(bufferID, format, tempBuffer, sampleRate);

        alSourceQueueBuffers(sourceID, bufferID);
        break outer;
      }
      // Wait for buffer to be free.
      try {
        Thread.sleep((long) (1000 * secondsPerBuffer / bufferCount));
      } catch (InterruptedException ignored) {
      }
    }

    // A buffer underflow will cause the source to stop.
    if (!isPlaying || alGetSourcei(sourceID, AL_SOURCE_STATE) != AL_PLAYING) {
      alSourcePlay(sourceID);
      isPlaying = true;
    }

    return written;
  }
コード例 #2
0
ファイル: OpenALAudio.java プロジェクト: Sasun/libgdx
  public void dispose() {
    if (noDevice) return;
    for (int i = 0, n = allSources.size; i < n; i++) {
      int sourceID = allSources.get(i);
      int state = alGetSourcei(sourceID, AL_SOURCE_STATE);
      if (state != AL_STOPPED) alSourceStop(sourceID);
      alDeleteSources(sourceID);
    }

    sourceToSoundId.clear();
    soundIdToSource.clear();

    AL.destroy();
    while (AL.isCreated()) {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
      }
    }
  }