Need a really simple library for playing sounds and music? Try TinySound.

[quote=“kuusisto,post:18,topic:38411”]
No probs at all. It was just a random .wav file that I downloaded to test drive the library. Grab it here http://dnfw.org/hl/sound/kart/coin.wav

Hope it helps :slight_smile:

[quote=“dimension17,post:21,topic:38411”]

Thanks. It would appear that, after conversion to the internal format using Java’s AudioSystem class, the getFrameLength() function is returning -1. I can read all the bytes into a list instead of precomputing, but perhaps someone else knows why this is the case. It doesn’t appear to be documented. I’m at work right now, but I’ll try to fix this sometime tonight.

I

[quote=“kuusisto,post:22,topic:38411”]

It looks like this conversion is supported since Java 7 and the file simply won’t load in 6. Since I’m not entirely convinced yet that this isn’t a bug, I’ve just pushed changes that check for negative frame length and don’t load the sound if so. Unfortunately, that means you’ll need to use a different audio file to play around.

For generating nice, simple sound effects I highly recommend as3sfxr (http://www.superflashbros.net/as3sfxr/), which is a Flash port of Dr. Petter’s sfxr (http://www.drpetter.se/project_sfxr.html).

Wow, that’s a really useful tool. Thanks! 8)

Anyone with half a brain can take a sound file and load it into Audacity (free) and convert it to the format required by the sound service. I see no reason why conversion has to be a requirement, as long as the game can play the sound correctly.

I spent some time looking at Paul Lamb’s sound system and was overwhelmed. Modular or not, it is like a couple phone books is size. I was hoping to learn a thing or two but mostly got lost. So I can sympathize with the desire to make a small sound system.

Based on things I’ve heard from folks here, though, and on my own experiences, a web game pretty much can’t use .wav files other than a few short sf/x, because of the download time. Some sort of compression is needed and Ogg/Vorbis is preferred. I think if you can figure out a way to support Ogg/Vorbis, you will have solved a big obstacle. Paul’s system does so, and is to be recommended for that.

I couldn’t figure out how to do some “fancy” things I wanted to do, like looping (via alternating two playbacks) longer Ogg/Vorbis files without getting memory leaks. Also, the very act of playing a compressed sound is significantly more costly than playing a PCM format file. (Was looking at decompressing and storing as .wav on the client, but that gets into a lot of hoohah about Signing.)

Hopefully you will have better luck if you decide to tackle this. For myself, I’ve decided to ditch Ogg/Vorbis and to generate my sounds on the fly. I can do this because I have a lot of background with FM and it is pretty efficient for sound synthesis.

Best of luck with your project!

philfrei - Decoding an OGG to PCM data can be done relatively painlessly with libraries like JOrbis. Alternatively, you could use Slick-Util’s OGGInputStream, or Paul’s OGG decoders on their own. Then you don’t need to worry about how to play the compressed data, or having to sign anything, or storing WAV files on the user’s machine, or whatever you were trying to do before.

Thanks. JOrbis didn’t work 100% for me. Maybe it reflects more on my competence than the library. I was having memory leak problems, using code based on this tutorial: http://www.jcraft.com/jorbis/tutorial/Tutorial.html Perhaps there is a better example to use for implementing. Or I didn’t modify the code in a good way for the degree of replays I was trying to build into the app in question.

For sure, others have had good results with JOrbis. And I have a very appealing FM workaround, so I haven’t looked back to figure out where I went wrong.

But to stay on topic, a big plus for TinySound would be to allow use of JOrbis, and the above link has both a program that works and lots of references & useful links, if the OP doesn’t already know about them and is interested. :slight_smile:

This isn’t a bad idea. I like that JOrbis is pure java (no native libraries to distribute) and wouldn’t require me to change my license. I’ll look into this. On the other hand, it might be kind of interesting/fun to write my own Vorbis decoder, but that would perhaps take a different level of motivation.

This code is all you need to get JOrbis working with Java Sound. Then you just need to include this JAR that includes JOrbis and the necessary metadata to tell Java Sound to use it for OGG files :slight_smile:

I’ve updated TinySound for better format conversion and lag prevention (frame-skipping). I’m working on Vorbis support using Javazoom’s VorbisSPI library. It should work right out of the box, but something is off. I hope to have that working by the end of today.

Yeah that jar I linked is Javazoom’s VorbisSPI :slight_smile:

I downloaded it twice, but both times the jar appeared to be corrupted. Regardlesss, I was going to include the jorbis, tritonus-share and vorbisspi libraries separately for the sake of being able to select different versions of each.

Corrupted? The download works fine for me :S

Try this link?

Anyway, my jar is just those three combined together to make distribution easier ;D

For those following along, you can now load Ogg Vorbis with the help of three pure-Java libraries included with TinySound.

That link worked, thanks. I still ended up keeping the libraries separate to make it clear what is being included and to allow for different version combinations.

I’ve pushed the Javadocs to the Github pages for the TinySound repository, so it’s now easier to see what functionality is available.

For those interested:
Repo https://github.com/finnkuusisto/TinySound
Docs http://finnkuusisto.github.com/TinySound

I’m working on trying to add sound to my game and i’m casting everything just as it’s written in the example. But when I create the sound with the method “kuusisto.tinysound.Sound sound = TinySound.loadSound(filename);” and then call it with “sound.play();” it keeps saying that ‘sound’ is null and i keep getting a nullpointerexception. Any help with this? Otherwise, everything is beautifully simple.

The loadSound() function returns null if it failed to load. It’s possibly a format thing, but there should be an error message printed to the terminal. I guess I should say that it will also return null if you haven’t yet called the init() function.

i call the init() function in the very beginning of the program. do i have to call it in the beginning of that same method or class? As for an error message, all i got was the standard nullpointerexcepiton error.

Maybe it’s because the file is not found?

That’s probably it. It looks like I don’t print a message if the InputStream that it opens is null. Make sure your sound file is on the classpath. Also, you should only specify the file name if you use the load function that takes a String. If you want to load a sound using a path to the file, you need to use the function that takes a File object.