PaulsCode Forum

Developers Corner => Programming => Topic started by: orange451 on September 04, 2014, 12:04:25 PM

Title: [SoundSystem] Read sound data from bytebuffer.
Post by: orange451 on September 04, 2014, 12:04:25 PM
Hello!
I am using Paul's sound system for my Java project. However, I do not want to be limited to just seperate flat files, and I would like to know if there is a way to load a sound from a bytebuffer, as I am using a packaged file format to store all my resources.

I sent Paul a PM about this a month ago :(
Title: Re: [SoundSystem] Read sound data from bytebuffer.
Post by: Paul on September 04, 2014, 02:46:49 PM
See the rawDataStream (http://www.paulscode.com/docs/SoundSystem/paulscode/sound/SoundSystem.html#rawDataStream%28javax.sound.sampled.AudioFormat,%20boolean,%20java.lang.String,%20float,%20float,%20float,%20int,%20float%29) and feedRawAudioData methods (URL for the second one isn't BBC compatible, but you can find it on the same page in the JavaDoc).
Title: Re: [SoundSystem] Read sound data from bytebuffer.
Post by: orange451 on September 04, 2014, 09:08:08 PM
Code: [Select]
// Get bytebuffer from the sound lump in the wad
ByteBuffer audioByteBuffer = lump.getRawLumpData().getByteBuffer();

// Create new byte array
byte[] audioBuffer = new byte[audioByteBuffer.remaining()];

// Fill byte array with wad buffer data
audioByteBuffer.get(audioBuffer);

// Flip the buffer for reading
audioByteBuffer.flip();

// Create Inputstream based on Bytebuffer
InputStream audioStream = new ByteBufferBackedInputStream(audioByteBuffer);

// Buffer the Inputstream
BufferedInputStream bufferedAudioStream = new BufferedInputStream(audioStream);

// Create AudioInputStream from BufferedInputStream
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(bufferedAudioStream);

// Send to sound system
soundSystem.rawDataStream(audioInputStream.getFormat(), false, "testSound", 0, 0, 0, SoundSystemConfig.ATTENUATION_ROLLOFF, SoundSystemConfig.getDefaultRolloff());
soundSystem.feedRawAudioData("testSound", audioBuffer);
soundSystem.activate("testSound");

The sound loads without problem (no errors). However, when I invoke: soundSystem.play("testSound"); I hear nothing.