Simple Lossy Audio?

I am after a solution for a simple, easy to integrate lossy audio format for bundling audio assets with games. I am yet to find a solution and hoping that one exits.

What doesn’t work for me:
Paul’s 3D Sound Engine - I am not looking for a complete sound engine JUST a lossy audio format/decoder.
jorbis/j-ogg - Both are buggy as hell and have terrible API’s that are impossible to integrate elegantly (see how nasty the PulpCore/JME/GTGE integration is).

Ideally:
Could convert wave files to said format with a tool such as Audacity and have an API such as:


audioFile.getTotalSamples();
audioFile.decodeSamples(int offset, byte[] dest, int destOffset, int sampleCount);

…what’s wrong with Jorbis? It’s been working for me for the last 8 years. Admittedly I don’t stray too far from the beaten path in wave formats but then why would anyone really need to?

Cas :slight_smile:

Given somefile.ogg, can you post the code using jorbis to decode to pcm samples 100-200 into a byte array?

Hell no, I just either decode the whole thing or stream it. Hm and as you have to decode it in order to know where the samples are actually going to be I suppose that’s half of the problem solved already. OGG doesn’t have indices does it?

Cas :slight_smile:

Ogg is great for streaming audio but that’s not really what I want. Also completely decoding a longish music track into memory means ~60mb heap space wasted.

I think you’re trying to find the solution for something that isn’t a problem.

Firstly - yes, Ogg is great for streaming music. So why would you decode an entire track in to the heap?
Secondly - pack all your sound effects into a single Ogg (or two, if you have both stereo and mono effects), and make a note of their PCM byte offsets. Stream decode that Ogg at startup, chopping into bits according to your PCM byte index file, uploading each PCM effect to OpenAL (or whatever). Let OpenAL or whatever manage the memory for you - which it will do, perfectly nicely, outside of the Java heap. Your sound effects will take up a trivial amount of ram.

Cas :slight_smile:

I’m actually look for an applet (sandbox) solution so OpenAL is out. This is also why I don’t want to 60 megs on the heap given you can’t change the applet sandbox heap size without a security dialog.

I could do this with Jorbis and a fair amount of glue code it’s just I hate complicated solutions to what I perceive to be a simple problem and I was hoping there was a simple solution but it looks unlikely.

Why not 3D Sound Engine? You can grab only the codecs you need to keep it small. It doesn’t need to be signed.

Good audio compression is hard (and a patent minefield). What kind of compression ratios are you looking for? What sound quality? If you want something that doesn’t sound lossy…make your life easy and use an existing codec.

It ain’t that hard and you don’t have to use OpenAL as the rendering backend, just stream the data to JavaSound. At the end of the day if you want to use compressed sound you have to realise it’s Not Totally Simple In Java.

Cas :slight_smile:

In this case, since you are only after a decoder and not a complete sound engine, you could just use my CodecJOrbis or CodecJOgg plug-ins stand-alone (without the rest of the SoundSystem). Grab the ICodec and SoundBuffer classes from the core SoundSystem library (or make a couple of small modifications to the CodecJOrbis or CodecJOgg sourcecode) and it should be good to go without the rest of the engine. However, it is not capable of decoding “pcm samples 100-200 into a byte array” as you would like to do. The only way to do something like that I am aware of is to “remember” the desired offset when you create the .ogg file, as princec suggested.

jME3 has a class that uses J-Ogg to decode an audio file, no streaming, no extra layers, etc. The result is an InputStream that gives you data in signed short format.
See here: http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/jogg/com/jme3/audio/plugins/OGGLoader.java
So far any file I threw at it worked. I use mostly aoTuV and oggenc2 for encoding, as they have the best compression and speed.

Might 352kbps ADPCM be good enough? I’ve got an implementation with an API that’s pretty much exactly what you’re looking for:

https://sites.google.com/site/mumart/home/imaadpcm

Cheers,
Martin