Advertisement
Guest User

Untitled

a guest
Aug 20th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package net.starshock;
  2.  
  3. import paulscode.sound.Library;
  4. import paulscode.sound.SoundSystem;
  5. import paulscode.sound.SoundSystemConfig;
  6. import paulscode.sound.SoundSystemException;
  7. import paulscode.sound.codecs.CodecJOrbis;
  8. import paulscode.sound.codecs.CodecWav;
  9. import paulscode.sound.libraries.LibraryJavaSound;
  10. import paulscode.sound.libraries.LibraryLWJGLOpenAL;
  11.  
  12. public class Sounder {
  13.  
  14.     public static SoundSystem ss;
  15.     public static boolean dead;
  16.     public static final int MUSIC_AMOUNT = 3;
  17.     public static float masterVolume = 0.2f, musicVolume = 0.9f;
  18.  
  19.     public static void init() {
  20.         try {
  21.             SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
  22.             SoundSystemConfig.setCodec("wav", CodecWav.class);
  23.         } catch (SoundSystemException e) {
  24.             System.err.println("Error linking with the plug-ins");
  25.         }
  26.  
  27.         boolean aLCompatible = SoundSystem.libraryCompatible(LibraryLWJGLOpenAL.class);
  28.         boolean jSCompatible = SoundSystem.libraryCompatible(LibraryJavaSound.class);
  29.  
  30.         Class libraryType;
  31.  
  32.         if (aLCompatible) {
  33.             libraryType = LibraryLWJGLOpenAL.class; // OpenAL
  34.         } else if (jSCompatible) {
  35.             libraryType = LibraryJavaSound.class; // Java Sound
  36.         } else {
  37.             libraryType = Library.class; // Silent
  38.         }
  39.  
  40.         try {
  41.             ss = new SoundSystem(libraryType);
  42.         } catch (SoundSystemException sse) {
  43.             sse.printStackTrace();
  44.             return;
  45.         }
  46.  
  47.         // ss.newStreamingSource(true, "music0", "music0.ogg", true, 0, 0, 0,
  48.         // SoundSystemConfig.ATTENUATION_NONE, 0);
  49.         // ss.setVolume("music0", musicVolume);
  50.         // ss.newStreamingSource(true, "music1", "music1.ogg", true, 0, 0, 0,
  51.         // SoundSystemConfig.ATTENUATION_NONE, 0);
  52.         // ss.setVolume("music1", musicVolume);
  53.         // ss.newStreamingSource(true, "music2", "music2.ogg", true, 0, 0, 0,
  54.         // SoundSystemConfig.ATTENUATION_NONE, 0);
  55.         // ss.setVolume("music2", musicVolume);
  56.     }
  57.  
  58.     public static void kill() {
  59.         dead = true;
  60.         ss.cleanup();
  61.     }
  62.  
  63.     public static void startSoundtrack() {
  64.         // Thread stThread = new Thread(new Runnable() {
  65.         //
  66.         // @Override
  67.         // public void run() {
  68.         // int currentSong = Main.rng.nextInt(MUSIC_AMOUNT);
  69.         //
  70.         // System.out.println("Started soundtrack, now at /music" + currentSong
  71.         // + ".ogg");
  72.         //
  73.         // while (!dead) {
  74.         // System.out.println("====================");
  75.         //
  76.         // ss.play("music" + currentSong);
  77.         //
  78.         // try {
  79.         // Thread.sleep(1000 * 10 * 60);
  80.         // } catch (InterruptedException e) {
  81.         // }
  82.         //
  83.         // currentSong = Main.rng.nextInt(MUSIC_AMOUNT);
  84.         //
  85.         // System.out.println("Switched song, now at /music" + currentSong +
  86.         // ".ogg");
  87.         // }
  88.         // }
  89.         // });
  90.         //
  91.         // stThread.start();
  92.     }
  93.  
  94.     public static void play(String sound) {
  95.         // ss.quickPlay(false, sound, false, 0, 0, 0,
  96.         // SoundSystemConfig.ATTENUATION_NONE, 0);
  97.     }
  98.  
  99.     public static void playAt(String sound, float x, float y, float z) {
  100.         ss.setListenerPosition(Game.player.pos.x, Game.player.pos.y, Game.player.pos.z);
  101.         ss.setListenerAngle(Game.player.yaw);
  102.         ss.quickPlay(false, sound, false, x, y, z, SoundSystemConfig.ATTENUATION_ROLLOFF, 1);
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement