Cleanup with AudioSystem3D

Hello,
I was wondering what the necessary steps are for shutting down the audio engine if the AudioSystem3D object is used (instead of the traditional OpenAL way of doing things - c-style like).

When I start up the engine, I do this


AudioSystem3D.init()
dev = AudioSystem3D.openDevice(null);
ctx = AudioSystem3D.createContext(dev);
AudioSystem3D.makeContextCurrent(ctx);

// later on I do this to create buffers
Buffer buffer = AudioSystem3D.loadBuffer("filename");

I see several methods in the API that I could potentially use such as


ctx.destroy();
dev.close();
ALut.alutExit();

Just not sure what to do.

Thanks for your help.

On top of the methods you’ve found, be sure to also do Buffer.delete() and Source.delete() on all your buffers and sources as well.

Delete sources first, then buffers, on the context you’re wishing to destroy. Then destroy the context, and close the device. I dunno where ALut.exit() fits into that though.

How do I get the sources if I only call


Buffer buffer = AudioSystem3D.loadBuffer("filename");

Thanks for the help!!!

Well I don’t think you can play a buffer without a source. So somewhere in your program you might have the following lines, which will give you your reference/s to your source/s:

Source source = AudioSystem3D.generateSource(Buffer)
Source[] sources = AudioSystem3D.generateSources(int)

Negative. I never load a source. I call the loadBuffer method from AudioSystem3D. Note that it takes a string for a parameter (file name). I’m guessing AudioSystem3D handles generating a source; however, I don’t see any release resources methods associated with AudioSystem3D. Listed below is the javadoc for this method.


public static Buffer loadBuffer(String filename) throws IOException, UnsupportedAudioFileException

    Loads a Sound3D buffer with the specified audio file.

    Parameters:
        filename - the name of the file to load. 
    Returns:
        a new Sound3D buffer containing the audio data from the specified file. 
    Throws:
        IOException - If the file cannot be found or some other IO error occurs. 
        UnsupportedAudioFileException - If the format of the sudio data is not supported

OK, so you don’t load any sources, but I’m pretty sure you can’t play a buffer. Only the Source class has the play/pause/stop methods (and in OpenAL, play/pause/stop can only occur on a source). So how do you play sounds then?

Anyway, if your app doesn’t use sources, then there’s no need to do any Source.delete(). Just using the Buffer.delete(), plus the other methods you found, are enough for an OpenAL cleanup.

Actually your right … I create Sources later on in my “Effects” objects — I just forgot about them.

So how should I go about deleting buffers? I see there is a function in the AL interface for deleting buffers; however, I really don’t have an AL interface. I just have the AudioSystem3D object…

Be sure to keep references to any buffers you create. When it’s time to cleanup, use their delete() method.

Thanks man! All of your advise worked out and I’m able to sucessfully release all the Sound resources!!!