io.github.mwttg.pixelartillery2d.sound.OpenAlCleanUp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pixel-artillery-2d Show documentation
Show all versions of pixel-artillery-2d Show documentation
A library for 2D OpenGL and OpenAL support based on LWJGL 3
The newest version!
package io.github.mwttg.pixelartillery2d.sound;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.openal.AL11;
import org.lwjgl.openal.ALC11;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** A class with a method to clean up all the OpenAL stuff (Buffers, Devices, etc.) */
public final class OpenAlCleanUp {
private static final Logger LOG = LoggerFactory.getLogger(OpenAlCleanUp.class);
private static long deviceId;
private static final List soundBufferIds = new ArrayList<>();
private static final List soundSourceIds = new ArrayList<>();
private OpenAlCleanUp() {}
static void addDeviceId(final long id) {
deviceId = id;
}
static void addSoundBufferId(final int id) {
soundBufferIds.add(id);
}
static void addSoundSourceId(final int id) {
soundSourceIds.add(id);
}
/** Clean up all OpenAL stuff. */
public static void purge() {
LOG.info("clean up OpenAL");
LOG.debug("... free sound sources");
soundBufferIds.forEach(AL11::alDeleteSources);
LOG.debug("... free sound buffers");
soundSourceIds.forEach(AL11::alDeleteBuffers);
LOG.debug("... close sound device");
ALC11.alcCloseDevice(deviceId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy