Path: blob/master/SLICK_HOME/src/org/newdawn/slick/openal/MODSound.java
1461 views
package org.newdawn.slick.openal;12import ibxm.Module;3import ibxm.OpenALMODPlayer;45import java.io.IOException;6import java.io.InputStream;7import java.nio.IntBuffer;89import org.lwjgl.BufferUtils;10import org.lwjgl.openal.AL10;1112/**13* A sound as a MOD file - can only be played as music14*15* @author Kevin Glass16*/17public class MODSound extends AudioImpl {18/** The MOD play back system */19private static OpenALMODPlayer player = new OpenALMODPlayer();2021/** The module to play back */22private Module module;23/** The sound store this belongs to */24private SoundStore store;2526/**27* Create a mod sound to be played back28*29* @param store The store this sound belongs to30* @param in The input stream to read the data from31* @throws IOException Indicates a failure to load a sound32*/33public MODSound(SoundStore store, InputStream in) throws IOException {34this.store = store;35module = OpenALMODPlayer.loadModule(in);36}3738/**39* @see org.newdawn.slick.openal.AudioImpl#playAsMusic(float, float, boolean)40*/41public int playAsMusic(float pitch, float gain, boolean loop) {42cleanUpSource();4344player.play(module, store.getSource(0), loop, SoundStore.get().isMusicOn());45player.setup(pitch, 1.0f);46store.setCurrentMusicVolume(gain);4748store.setMOD(this);4950return store.getSource(0);51}5253/**54* Clean up the buffers applied to the sound source55*/56private void cleanUpSource() {57AL10.alSourceStop(store.getSource(0));58IntBuffer buffer = BufferUtils.createIntBuffer(1);59int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);6061while (queued > 0)62{63AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);64queued--;65}6667AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);68}6970/**71* Poll the streaming on the MOD72*/73public void poll() {74player.update();75}7677/**78* @see org.newdawn.slick.openal.AudioImpl#playAsSoundEffect(float, float, boolean)79*/80public int playAsSoundEffect(float pitch, float gain, boolean loop) {81return -1;82}8384/**85* @see org.newdawn.slick.openal.AudioImpl#stop()86*/87public void stop() {88store.setMOD(null);89}9091/**92* @see org.newdawn.slick.openal.AudioImpl#getPosition()93*/94public float getPosition() {95throw new RuntimeException("Positioning on modules is not currently supported");96}9798/**99* @see org.newdawn.slick.openal.AudioImpl#setPosition(float)100*/101public boolean setPosition(float position) {102throw new RuntimeException("Positioning on modules is not currently supported");103}104}105106107