Author Topic: [SoundSystem] Read sound data from bytebuffer.  (Read 5326 times)

Offline orange451

  • bit
  • Posts: 4
    • View Profile
[SoundSystem] Read sound data from bytebuffer.
« on: September 04, 2014, 12:04:25 PM »
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 :(

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: [SoundSystem] Read sound data from bytebuffer.
« Reply #1 on: September 04, 2014, 02:46:49 PM »
See the rawDataStream and feedRawAudioData methods (URL for the second one isn't BBC compatible, but you can find it on the same page in the JavaDoc).
« Last Edit: September 04, 2014, 02:50:12 PM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline orange451

  • bit
  • Posts: 4
    • View Profile
Re: [SoundSystem] Read sound data from bytebuffer.
« Reply #2 on: September 04, 2014, 09:08:08 PM »
Code: newbielink:javascript:void(0); [nonactive]
// 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

// Flip the buffer for reading

// 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);

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