class Audio {

  public void playSound(AudioInputStream stream, float volume) {
    init();
    // Walk the pending requests.
    for (int i = headIndex; i != tailIndex; i = (i + 1) % MAX_PENDING) {
      if (getPendingAudio()[i].getStream() == stream) {
        // Use the larger of the two volumes.
        getPendingAudio()[i].setVolume(Math.max(volume, getPendingAudio()[i].getVolume()));

        // Don't need to enqueue.
        return;
      }
    }
    getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
    tailIndex = (tailIndex + 1) % MAX_PENDING;
  }

    Audio();

}