/** * 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; } }
public static AudioData loadSound(String ref) throws SlickException { SoundStore.get().init(); Audio audio = null; try { if (ref.toLowerCase().endsWith(".ogg")) { audio = SoundStore.get().getOgg(ref); } else if (ref.toLowerCase().endsWith(".wav")) { audio = SoundStore.get().getWAV(ref); } else if (ref.toLowerCase().endsWith(".aif")) { audio = SoundStore.get().getAIF(ref); } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) { throw new SlickException("Use XStream for streaming .xm and .mod sounds"); } 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, e); } return new AudioData(audio.getBufferID()); }
public static AudioData loadSound(URL url) throws SlickException { SoundStore.get().init(); String ref = url.getFile(); Audio audio = null; try { if (ref.toLowerCase().endsWith(".ogg")) { audio = SoundStore.get().getOgg(url.openStream()); } else if (ref.toLowerCase().endsWith(".wav")) { audio = SoundStore.get().getWAV(url.openStream()); } else if (ref.toLowerCase().endsWith(".aif")) { audio = SoundStore.get().getAIF(url.openStream()); } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) { throw new SlickException("Use XStream for streaming .xm and .mod sounds"); } 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, e); } return new AudioData(audio.getBufferID()); }
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; } }
public Sounds() throws IOException { soundEnabled = true; musicEnabled = true; acceptSound = loadAudio("resources/sounds/menu-validate.wav"); declineSound = loadAudio("resources/sounds/menu-back.wav"); cursorSound = loadAudio("resources/sounds/menu-nav.wav"); boingSound = loadAudio("resources/sounds/boing.wav"); pointSound = loadAudio("resources/sounds/mouthpop.wav"); hitSounds = new Audio[3]; hitSounds[0] = loadAudio("resources/sounds/djembe-mid-4.wav"); hitSounds[1] = loadAudio("resources/sounds/djembe-hi-3.wav"); hitSounds[2] = loadAudio("resources/sounds/djembe-mid-2.wav"); pointsPowerupSound = loadAudio("resources/sounds/goblet-g-medium.wav"); deathSound = loadAudio("resources/sounds/stone-on-stone-impact.wav"); winSound = loadAudio("resources/sounds/win.wav"); loseSound = loadAudio("resources/sounds/lose.wav"); music = loadAudio("resources/sounds/loop003-jungle.wav"); menuMusic = loadAudio("resources/sounds/przeszkadzajki.wav"); }
/** * 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){} } }
public static void loadSound(NBMData data) throws IOException { Map<Integer, String> soundMap = data.getSoundMap(); Map<Integer, Audio> soundDataMap = data.getSoundDataMap(); for (Map.Entry<Integer, String> entry : soundMap.entrySet()){ int key = entry.getKey(); String path = entry.getValue(); Audio audio = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream(data.getParentPath() + "/" + path)); soundDataMap.put(key, audio); } }
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(); } }
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(); } }
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); }
public static Audio getSoundPressArrows() { return soundPressArrows; }
public static void setSoundPressArrows(Audio sound) { soundPressArrows = sound; }
public static Audio getSoundPressEnter() { return soundPressEnter; }
public static void setSoundPressEnter(Audio sound) { soundPressEnter = sound; }
/** * 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) { explode("Failed to destroy OpenAL.", e, DEFAULT_OPTIONS); } }
/** * Play audio. * * @param name the name */ public static void playAudio(String name){ Audio audio = FEResources.getAudio(name); audio.playAsSoundEffect(1.0f, FEResources.getAudioVolume(), false); }
/** * 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); } }
public Map<Integer, Audio> getSoundDataMap() { return soundDataMap; }
public static void playAudio(String name, float pitch, float gain) { Audio audio = FEResources.getAudio(name); audio.playAsSoundEffect(pitch, gain + globalGain, false); }
private final Audio loadAudio(final String file) throws IOException { return AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream(file)); }
/** * Loads and returns a sound effect or music track with the given file name. * * @param fileName Name of sound file * @return Sound as Audio object */ public static Audio getSound(String fileName) { loadSound(fileName); return sound; }