Paulscode - Soundsystem - Load from bytebutter?

Hello all! :slight_smile:

In my game, I am currently using the Soundsystem written by Paulscode. Seeing as he is no longer an active member of these forums, I was hoping someone else would be able to help with this issue. I want to package a lot of my resource files so that they’re not in a tree of folders outside of the Jar. I have made it so models and textures could be loaded from these packaged files by using their bytebuffer data. However, I am not quite sure how to use the sound system in the same way.

I am using the WAD file format to store external resources, and from a wad I can only access a resources bytebuffer data.

Maybe I don’t understand the question. If your audio resources are in a subfolder of the source code, then it should be automatically packed inside of the jar.

For example, I have a package called pfaudio. In it is a class which is used to play wav files. The package also has a subfolder “audio” which has wav files in it.

The code used to get the wav file follows:

		URL url = PFAudioMixer.class.getResource(fileName);
		AudioInputStream ais = AudioSystem.getAudioInputStream(url);

where fileName = “audio/Boom.wav” and PFAudioMixer is a class in the pfaudio package.

To make the jar, I use Eclipse’s functionality. There is a point in the process where it is possible to check or uncheck specific folders for inclusion in the jar. The default is to include all the subfolders of whatever folder you are in at the time you click on the utility.

A similar thing can be done with graphics resources.

I recall that princec has made the code available for his Titans game, and if I remember correctly, he may have had it setup more like you describe where the files loaded are raw PCM data, not actual wavs. My memory is hazy on that. There was something unusual going on, but I can’t recall just what.

TinySound is a decent alternative to Paulscode, and afaik, Finn is still supporting his project.

I’m using the Wad file architecture for storing external files together, they’re not being stored inside of the Jar.

I had to search “wad file architecture” and found a reference to Doom. Is that what you mean?

How are you creating your jar? From an IDE?

If you are doing it from a command line, you can do so with the following syntax:
From: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

jar cf jar-file input-file(s)

input-file(s) can refer to a folder. But I’ve never done it this way. It might be a bit tricky figuring out exactly how to address the file via getResource() method.

I did a similar thing with Slick2D’s OpenAL code for OGG files. I did all the decoding, and serialized it in a byte array to a .buffer file. Then I simply added some code that if the filename loading the file ended with .buffer it would skip OGG decoding, and then load the buffer data right from the byte array. I know this is probably different than your situation, and I know that OGG files and WAV files are decoded differently but if you want the code I can post it.

Edit: My code has been trimmed down to just work for .ogg files, but if anybody wants to use it they can. You load clips by creating Music and SoundEffect objects, and you serialize sound data by modifying the SerializableSoundWrapper class with the filenames and where to get the files.
http://github.com/copyablecougar4/OpenAL-Reader I know when you post links to code it shouldn’t need much updating to work, but for that code to be modified you need to change SoundStore line 18 and 626 and ObjectLoading line 11 to not use [icode]warlord.opengl.Game[/icode] to either construct a file for use another method to get the file, and remove those two imports.

CopyableCougar4

Thanks for the reply!

I still haven’t figured this out, however. I do not want to have to create a temporary file just to load a sound; there has to be a way to use Pauls soundsystem to load a sound from a bytebuffer :frowning:

I keep meaning to try wrapping a ByteBuffer in an InputStream (and wrapping in eg. AudioInputStream) Something like this might help you on your way - http://stackoverflow.com/questions/4332264/wrapping-a-bytebuffer-with-an-inputstream That of course depends on whether Pauls system has a way to provide an input stream directly.

Quite helpful! I feel as though I’m almost there! :slight_smile:

// 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 ByteBufferInputStream(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(), true, "testSound", 0, 0, 0, SoundSystemConfig.ATTENUATION_ROLLOFF, SoundSystemConfig.getDefaultRolloff());
soundSystem.feedRawAudioData("testSound", audioBuffer);

The sound loads into the sound system with no error, however it doesn’t seem to make a sound when played.
Thanks for the idea with the bytebuffer - input stream :slight_smile:

Have you tried it with plain JavaSound? I’d rule out issues with the sound library to start with.

No problem. Like I said, I keep meaning to play with this - this way you test it out for me! ;D

The reason I switched to an OpenAL sound library was because JavaSound wouldn’t cut it.

I seem to be getting somewhere though :wink:
When I use this soundSystem’s “loadSound()” method, and supply all the information (byte[] of audio, audio format), and I pick a Name, it loads the sound into memory.

I wasn’t suggesting you change library (though personally, I’d much rather use JavaSound - just most people use it wrong!). The AudioInputStream is JavaSound - I’m suggesting you make sure that JavaSound can play that stream - then you’ll know whether the problem is the stream implementation or how Paul’s library is using it. For that matter, are you sure that Paul’s library implements playing a JavaSound stream through OpenAL?

I’m quite sure, yes. I was looking through his lwjgl api and it uses a similar method to what I tried.