org.newdawn.slick.openal.SoundStore Java Examples

The following examples show how to use org.newdawn.slick.openal.SoundStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * @param in The stream to read the music from 
 * @param ref  The symbolic name of this music 
 * @throws SlickException Indicates a failure to read the music from the stream
 */
public Music(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(in);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load music: "+ref);
	}
}
 
Example #2
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Poll the state of the current music. This causes streaming music
 * to stream and checks listeners. Note that if you're using a game container
 * this will be auto-magically called for you.
 * 
 * @param delta The amount of time since last poll
 */
public static void poll(int delta) {
	synchronized (musicLock) {
		if (currentMusic != null) {
			SoundStore.get().poll(delta);
			if (!SoundStore.get().isMusicPlaying()) {
				if (!currentMusic.positioning) {
					Music oldMusic = currentMusic;
					currentMusic = null;
					oldMusic.fireMusicEnded();
				}
			} else {
				currentMusic.update(delta);
			}
		}
	}
}
 
Example #3
Source File: SoundTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	SoundStore.get().setMaxSources(32);
	
	myContainer = container;
	sound = new Sound("testdata/restart.ogg");
	charlie = new Sound("testdata/cbrown01.wav");
	try {
		engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
	} catch (IOException e) {
		throw new SlickException("Failed to load engine", e);
	}
	music = musica = new Music("testdata/SMB-X.XM");
	//music = musica = new Music("testdata/theme.ogg", true);
	musicb = new Music("testdata/kirby.ogg", true);
	burp = new Sound("testdata/burp.aif");
	
	music.play();
}
 
Example #4
Source File: Sound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new Sound 
 * 
 * @param ref The location of the OGG or MOD/XM to load
 * @throws SlickException Indicates a failure to load the sound effect
 */
public Sound(String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(ref);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".aif")) {
			sound = SoundStore.get().getAIF(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .aif, .wav and .ogg are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #5
Source File: Sound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new Sound 
 * 
 * @param url The location of the OGG or MOD/XM to load
 * @throws SlickException Indicates a failure to load the sound effect
 */
public Sound(URL url) throws SlickException {
	SoundStore.get().init();
	String ref = url.getFile();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(url.openStream());
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(url.openStream());
		} else if (ref.toLowerCase().endsWith(".aif")) {
			sound = SoundStore.get().getAIF(url.openStream());
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(url.openStream());
		} else {
			throw new SlickException("Only .xm, .mod, .aif, .wav and .ogg are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #6
Source File: Sound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new Sound 
 * 
 * @param in The location of the OGG or MOD/XM to load
 * @param ref The name to associate this stream
 * @throws SlickException Indicates a failure to load the sound effect
 */
public Sound(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".aif")) {
			sound = SoundStore.get().getAIF(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else {
			throw new SlickException("Only .xm, .mod, .aif, .wav and .ogg are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #7
Source File: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * @param in The stream to read the music from 
 * @param ref  The symbolic name of this music 
 * @throws SlickException Indicates a failure to read the music from the stream
 */
public Music(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(in);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load music: "+ref);
	}
}
 
Example #8
Source File: Music.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Poll the state of the current music. This causes streaming music
 * to stream and checks listeners. Note that if you're using a game container
 * this will be auto-magically called for you.
 * 
 * @param delta The amount of time since last poll
 */
public static void poll(int delta) {
	synchronized (musicLock) {
		if (currentMusic != null) {
			SoundStore.get().poll(delta);
			if (!SoundStore.get().isMusicPlaying()) {
				if (!currentMusic.positioning) {
					Music oldMusic = currentMusic;
					currentMusic = null;
					oldMusic.fireMusicEnded();
				}
			} else {
				currentMusic.update(delta);
			}
		}
	}
}
 
Example #9
Source File: Music.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * @param in The stream to read the music from 
 * @param ref  The symbolic name of this music 
 * @throws SlickException Indicates a failure to read the music from the stream
 */
public Music(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(in);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load music: "+ref);
	}
}
 
Example #10
Source File: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param ref The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(String ref, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			if (streamingHint) {
				sound = SoundStore.get().getOggStream(ref);
			} else {
				sound = SoundStore.get().getOgg(ref);
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #11
Source File: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param url The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(URL url, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	String ref = url.getFile();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			if (streamingHint) {
				sound = SoundStore.get().getOggStream(url);
			} else {
				sound = SoundStore.get().getOgg(url.openStream());
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(url.openStream());
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(url.openStream());
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(url.openStream());
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+url);
	}
}
 
Example #12
Source File: FEMultiplayer.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void loop() {
		while(!Display.isCloseRequested()) {
			time = System.nanoTime();
			glClear(GL_COLOR_BUFFER_BIT |
			        GL_DEPTH_BUFFER_BIT |
			        GL_STENCIL_BUFFER_BIT);
			glClearDepth(1.0f);
			getInput();
			messages.clear();
			if(client != null){
				messages.addAll(client.getMessages());
				for(Message m : messages)
					client.messages.remove(m);
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
			if(!paused) {
				currentStage.beginStep();
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
			}
			glPopMatrix();
			Display.update();
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example #13
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Game loop update
 */
public void update() {
	while (Keyboard.next()) {
		if (Keyboard.getEventKeyState()) {
			if (Keyboard.getEventKey() == Keyboard.KEY_Q) {
				// play as a one off sound effect
				oggEffect.playAsSoundEffect(1.0f, 1.0f, false);
			}
			if (Keyboard.getEventKey() == Keyboard.KEY_W) {
				// replace the music thats curretly playing with 
				// the ogg
				oggStream.playAsMusic(1.0f, 1.0f, true);
			}
			if (Keyboard.getEventKey() == Keyboard.KEY_E) {
				// replace the music thats curretly playing with 
				// the mod
				modStream.playAsMusic(1.0f, 1.0f, true);
			}
			if (Keyboard.getEventKey() == Keyboard.KEY_R) {
				// play as a one off sound effect
				aifEffect.playAsSoundEffect(1.0f, 1.0f, false);
			}
			if (Keyboard.getEventKey() == Keyboard.KEY_T) {
				// play as a one off sound effect
				wavEffect.playAsSoundEffect(1.0f, 1.0f, false);
			}
		}
	}
	
	// polling is required to allow streaming to get a chance to
	// queue buffers.
	SoundStore.get().poll(0);
}
 
Example #14
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialise GL state
 */
protected void initGL() {
   try {
      InternalTextureLoader.get().clear();
      SoundStore.get().clear();

      container.initApplet();
   } catch (Exception e) {
      Log.error(e);
      container.stopApplet();
   }
}
 
Example #15
Source File: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Poll the state of the current music. This causes streaming music
 * to stream and checks listeners. Note that if you're using a game container
 * this will be auto-magically called for you.
 * 
 * @param delta The amount of time since last poll
 */
public static void poll(int delta) {
	if (currentMusic != null) {
		SoundStore.get().poll(delta);
		if (!SoundStore.get().isMusicPlaying()) {
			if (!currentMusic.positioning) {
				Music oldMusic = currentMusic;
				currentMusic = null;
				oldMusic.fireMusicEnded();
			}
		} else {
			currentMusic.update(delta);
		}
	}
}
 
Example #16
Source File: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set the volume of the music as a factor of the global volume setting
 * 
 * @param volume The volume to play music at. 0 - 1, 1 is Max
 */
public void setVolume(float volume) {
	// Bounds check
	if(volume > 1) {
		volume = 1;
	} else if(volume < 0) {
		volume = 0;
	}
	
	this.volume = volume;
	// This sound is being played as music
	if (currentMusic == this) {
		SoundStore.get().setCurrentMusicVolume(volume);
	}
}
 
Example #17
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#reinit()
 */
public void reinit() throws SlickException {
	InternalTextureLoader.get().clear();
	SoundStore.get().clear();
	initSystem();
	enterOrtho();
	
	try {
		game.init(this);
	} catch (SlickException e) {
		Log.error(e);
		running = false;
	}
}
 
Example #18
Source File: LoadingList.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Indicate if we're going to use deferred loading. (Also clears the current list)
 * 
 * @param loading True if we should use deferred loading
 */
public static void setDeferredLoading(boolean loading) {
	single = new LoadingList();
	
	InternalTextureLoader.get().setDeferredLoading(loading);
	SoundStore.get().setDeferredLoading(loading);
}
 
Example #19
Source File: SoundPositionTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	SoundStore.get().setMaxSources(32);
	
	myContainer = container;
	music = new Music("testdata/kirby.ogg", true);
	music.play();
}
 
Example #20
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param url The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(URL url, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	String ref = url.getFile();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
			if (streamingHint) {
				synchronized (musicLock) {
					sound = SoundStore.get().getOggStream(url);
				}
			} else {
				sound = SoundStore.get().getOgg(url.openStream());
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(url.openStream());
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(url.openStream());
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(url.openStream());
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+url);
	}
}
 
Example #21
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param ref The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(String ref, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
			if (streamingHint) {
				synchronized (musicLock) {
					//getting a stream ends the current stream....
					//which may cause a MusicEnded instead of of MusicSwap
					//Not that it really matters for MusicController use
					sound = SoundStore.get().getOggStream(ref);
				}
			} else {
				sound = SoundStore.get().getOgg(ref);
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #22
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the volume of the music as a factor of the global volume setting
 * 
 * @param volume The volume to play music at. 0 - 1, 1 is Max
 */
public void setVolume(float volume) {
	// Bounds check
	if(volume > 1) {
		volume = 1;
	} else if(volume < 0) {
		volume = 0;
	}
	
	this.volume = volume;
	// This sound is being played as music
	if (currentMusic == this) {
		SoundStore.get().setCurrentMusicVolume(volume);
	}
}
 
Example #23
Source File: Music.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the pitch of the music as a factor of it's normal pitch
 *
 * @param pitch The pitch to play music at.
 */
public void setPitch(float pitch) {
	this.pitch = pitch;
	if (currentMusic == this) {
		SoundStore.get().setMusicPitch(pitch);
	}
}
 
Example #24
Source File: FEMultiplayer.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void loop() {
		while(!Display.isCloseRequested()) {
			final long time = System.nanoTime();
			glClear(GL_COLOR_BUFFER_BIT |
			        GL_DEPTH_BUFFER_BIT |
			        GL_STENCIL_BUFFER_BIT);
			glClearDepth(1.0f);
			getInput();
			final ArrayList<Message> messages = new ArrayList<>();
			if(client != null){
				synchronized (client.messagesLock) {
					messages.addAll(client.messages);
					for(Message m : messages)
						client.messages.remove(m);
				}
			}
			SoundStore.get().poll(0);
			glPushMatrix();
			//Global resolution scale
//			Renderer.scale(scaleX, scaleY);
				currentStage.beginStep(messages);
				currentStage.onStep();
				currentStage.processAddStack();
				currentStage.processRemoveStack();
				currentStage.render();
//				FEResources.getBitmapFont("stat_numbers").render(
//						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
				currentStage.endStep();
				postRenderRunnables.runAll();
			glPopMatrix();
			Display.update();
			Display.sync(FEResources.getTargetFPS());
			timeDelta = System.nanoTime()-time;
		}
		AL.destroy();
		Display.destroy();
		if(client != null && client.isOpen()) client.quit();
	}
 
Example #25
Source File: Music.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param url The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(URL url, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	String ref = url.getFile();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
			if (streamingHint) {
				synchronized (musicLock) {
					sound = SoundStore.get().getOggStream(url);
				}
			} else {
				sound = SoundStore.get().getOgg(url.openStream());
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(url.openStream());
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(url.openStream());
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(url.openStream());
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+url);
	}
}
 
Example #26
Source File: Music.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param ref The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(String ref, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
			if (streamingHint) {
				synchronized (musicLock) {
					//getting a stream ends the current stream....
					//which may cause a MusicEnded instead of of MusicSwap
					//Not that it really matters for MusicController use
					sound = SoundStore.get().getOggStream(ref);
				}
			} else {
				sound = SoundStore.get().getOgg(ref);
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example #27
Source File: Music.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the volume of the music as a factor of the global volume setting
 * 
 * @param volume The volume to play music at. 0 - 1, 1 is Max
 */
public void setVolume(float volume) {
	// Bounds check
	if(volume > 1) {
		volume = 1;
	} else if(volume < 0) {
		volume = 0;
	}
	
	this.volume = volume;
	// This sound is being played as music
	if (currentMusic == this) {
		SoundStore.get().setCurrentMusicVolume(volume);
	}
}
 
Example #28
Source File: Music.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the pitch of the music as a factor of it's normal pitch
 *
 * @param pitch The pitch to play music at.
 */
public void setPitch(float pitch) {
	this.pitch = pitch;
	if (currentMusic == this) {
		SoundStore.get().setMusicPitch(pitch);
	}
}
 
Example #29
Source File: Options.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setValue(int value){
	super.setValue(value);
	SoundStore.get().setMusicVolume(OPTION_MASTER_VOLUME.val * OPTION_MUSIC_VOLUME.val / 10000f);
}
 
Example #30
Source File: MusicController.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Stops and releases all sources, clears each of the specified Audio
 * buffers, destroys the OpenAL context, and resets SoundStore for future use.
 *
 * Calling SoundStore.get().init() will re-initialize the OpenAL context
 * after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
 *
 * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
 */
private static void destroyOpenAL() {
	if (!trackExists())
		return;
	stop();

	try {
		// get Music object's (private) Audio object reference
		Field sound = player.getClass().getDeclaredField("sound");
		sound.setAccessible(true);
		Audio audio = (Audio) (sound.get(player));

		// first clear the sources allocated by SoundStore
		int max = SoundStore.get().getSourceCount();
		IntBuffer buf = BufferUtils.createIntBuffer(max);
		for (int i = 0; i < max; i++) {
			int source = SoundStore.get().getSource(i);
			buf.put(source);

			// stop and detach any buffers at this source
			AL10.alSourceStop(source);
			AL10.alSourcei(source, AL10.AL_BUFFER, 0);
		}
		buf.flip();
		AL10.alDeleteSources(buf);
		int exc = AL10.alGetError();
		if (exc != AL10.AL_NO_ERROR) {
			throw new SlickException(
					"Could not clear SoundStore sources, err: " + exc);
		}

		// delete any buffer data stored in memory, too...
		if (audio != null && audio.getBufferID() != 0) {
			buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
			buf.flip();
			AL10.alDeleteBuffers(buf);
			exc = AL10.alGetError();
			if (exc != AL10.AL_NO_ERROR) {
				throw new SlickException("Could not clear buffer "
						+ audio.getBufferID()
						+ ", err: "+exc);
			}
		}

		// clear OpenAL
		AL.destroy();

		// reset SoundStore so that next time we create a Sound/Music, it will reinit
		SoundStore.get().clear();

		player = null;
	} catch (Exception e) {
		softErr(e, "Failed to destroy OpenAL");
	}
}