Advertisement
Guest User

Untitled

a guest
Dec 12th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. public static String loadSoundFromWad(Wad wad, String lumpName) {
  2.     String soundName = wad.getWadFileLocation().getName() + lumpName;
  3.     Lump lump = wad.getLumpByName(lumpName);
  4.     if (lump != null) {
  5.         try{
  6.             // Get bytebuffer from the sound lump in the wad
  7.             ByteBuffer audioByteBuffer = lump.getRawLumpData().getByteBuffer();
  8.            
  9.             // Create new byte array
  10.             byte[] audioBuffer = new byte[audioByteBuffer.remaining()];
  11.            
  12.             // Fill byte array with wad buffer data
  13.             audioByteBuffer.get(audioBuffer);
  14.            
  15.             // Flip the buffer for reading
  16.             audioByteBuffer.flip();
  17.            
  18.             // Create Inputstream based on Bytebuffer
  19.             InputStream audioStream = new ByteBufferBackedInputStream(audioByteBuffer);
  20.            
  21.             // Buffer the Inputstream
  22.             BufferedInputStream bufferedAudioStream = new BufferedInputStream(audioStream);
  23.            
  24.             // Create AudioInputStream from BufferedInputStream
  25.             AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bufferedAudioStream);
  26.            
  27.             // Send to sound system
  28.             soundSystem.loadSound(audioBuffer, audioInputStream.getFormat(), soundName);
  29.             return soundName;
  30.         }catch(Exception e) {
  31.             e.printStackTrace();
  32.         }
  33.     }
  34.    
  35.     return null;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement