GenuineSounds

Game Fix

Jun 15th, 2012
223
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. private HashMap<String, Integer> initSounds() throws FileNotFoundException {
  2.     HashMap soundList = new HashMap();
  3.     File soundDir = new File("./res/sound/");
  4.     for (int i = 0; i < soundDir.list().length; ++i) {
  5.         if (soundDir.list()[i].endsWith(".wav")) {
  6.             byte[] bits = getBytesFromFile(soundDir.listFiles()[i]);
  7.             WaveData data = WaveData.create(bits);
  8.             if (data != null) {
  9.                 int buffer = AL10.alGenBuffers();
  10.                 this.bufferList[i] = buffer;
  11.                 AL10.alBufferData(buffer, data.format, data.data, data.samplerate);
  12.                 data.dispose();
  13.                 int source = AL10.alGenSources();
  14.                 System.out.println(source);
  15.                 this.sourceList[i] = source;
  16.                 AL10.alSourcei(source, 4105, buffer);
  17.                 soundList.put(soundDir.list()[i], Integer.valueOf(source));
  18.             }
  19.         }
  20.     }
  21.     if (soundList.isEmpty()) {
  22.         // make a new setting for a disabled sound environment.
  23.     }
  24.     return soundList;
  25. }
  26.  
  27. public static byte[] getBytesFromFile(File file) {
  28.     try {
  29.         InputStream is = new FileInputStream(file);
  30.         long length = file.length();
  31.         if (length > Integer.MAX_VALUE) {}
  32.         byte[] bytes = new byte[(int) length];
  33.         int offset = 0;
  34.         int numRead = 0;
  35.         while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
  36.             offset += numRead;
  37.         }
  38.         if (offset < bytes.length) {
  39.             throw new IOException("Could not completely read file " + file.getName());
  40.         }
  41.         is.close();
  42.         return bytes;
  43.     }
  44.     catch (IOException e) {}
  45.     return null;
  46. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment