org.newdawn.slick.openal.Audio Java Examples
The following examples show how to use
org.newdawn.slick.openal.Audio.
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: FEResources.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
/** * Gets the audio. * * @param name the name * @return the audio */ public static Audio getAudio(String name) { Audio a = audio.get(name); if(a == null) { // System.err.println("Warn: " + name + " not explicitly defined"); try{ Audio b = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav")); audio.put(name, b); return b; } catch (Exception e){ return null; } } else { return a; } }
Example #2
Source File: FEResources.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public static Audio getAudio(String name) { Audio a = audio.get(name); if(a == null) { // System.err.println("Warn: " + name + " not explicitly defined"); try{ Audio b = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav")); audio.put(name, b); return b; } catch (Exception e){ return null; } } else { return a; } }
Example #3
Source File: SoundTrack.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Loops the given audio according to settings. * * @param name the music category */ public static void loop(String name){ if (FEResources.getAudioVolume() <= 0) return; if (name.equals(currentName) && current.isPlaying()) return; current.stop(); currentName = name; Map<String, ArrayList<String>> songs = loadAudioNames(); try{ String setting = FEResources.getAudioSetting(name.toUpperCase()); if(setting.equals("random")){ Random r = new Random(); setting = name + "_" + songs.get(name).get(r.nextInt(songs.get(name).size())); if(setting.split("_").length<2) setting = name; } current = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/music/"+setting+".wav")); current.playAsMusic(1.0f, FEResources.getAudioVolume(), true); } catch (Exception e){ e.printStackTrace(); System.err.println("Warn: Bad sound configuration: "+name); try{ Audio b = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/music/"+name+".wav")); b.playAsMusic(1.0f, FEResources.getAudioVolume(), true); }catch(Exception f){} } }
Example #4
Source File: SoundTrack.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public static void loop(String name){ if(!enabled) return; if(name.equals(current)) return; try { current = name; Audio a = AudioLoader.getStreamingAudio("OGG", ResourceLoader.getResource("res/music/"+name+".ogg")); a.playAsMusic(1, 1, true); } catch (IOException e) { e.printStackTrace(); } }
Example #5
Source File: SoundTrack.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public static void restart(){ if(!enabled) return; try { Audio a = AudioLoader.getStreamingAudio("OGG", ResourceLoader.getResource("res/music/"+current+".ogg")); a.playAsMusic(1, 1, true); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #6
Source File: AudioPlayer.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public static void playAudio(String name, float pitch, float gain, float x, float y, float z, float fade) { Audio audio = FEResources.getAudio(name); float cx, cy; if(camera == null) { cx = Game.getWindowWidth()/2; cy = Game.getWindowHeight()/2; } else { cx = camera.getX(); cy = camera.getY(); } audio.playAsSoundEffect(pitch, gain + globalGain, false, (x - cx) / fade, (y - cy) / fade, z); }
Example #7
Source File: MusicController.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
/** * 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"); } }
Example #8
Source File: AudioPlayer.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 4 votes |
/** * Play audio. * * @param name the name */ public static void playAudio(String name){ Audio audio = FEResources.getAudio(name); audio.playAsSoundEffect(1.0f, FEResources.getAudioVolume(), false); }
Example #9
Source File: MusicController.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * 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(); if (!AL.isCreated()) return; 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) { ErrorHandler.error("Failed to destroy the OpenAL context.", e, true); } }
Example #10
Source File: AudioPlayer.java From FEMultiplayer with GNU General Public License v3.0 | 4 votes |
public static void playAudio(String name, float pitch, float gain) { Audio audio = FEResources.getAudio(name); audio.playAsSoundEffect(pitch, gain + globalGain, false); }