Java Code Examples for org.lwjgl.openal.AL10#alDeleteBuffers()

The following examples show how to use org.lwjgl.openal.AL10#alDeleteBuffers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * Play a mod or xm track streamed from the specified location
    * 
    * @param module The moudle to play back
    * @param source The OpenAL source to play the music on
    * @param start True if the music should be started
    * @param loop True if the track should be looped
    */
public void play(Module module, int source, boolean loop, boolean start) {
	this.source = source;
	this.loop = loop;
	this.module = module;
	done = false;
	
	ibxm = new IBXM(48000);
	ibxm.set_module(module);
	songDuration = ibxm.calculate_song_duration();

	if (bufferNames != null) {
		AL10.alSourceStop(source);
		bufferNames.flip();
		AL10.alDeleteBuffers(bufferNames);
	}
	
	bufferNames = BufferUtils.createIntBuffer(2);
	AL10.alGenBuffers(bufferNames);
	remainingBufferCount = 2;
	
	for (int i=0;i<2;i++) {
        stream(bufferNames.get(i));
	}
       AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcef(source, AL10.AL_PITCH, 1.0f);
	AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); 
	
	if (start) {
		AL10.alSourcePlay(source);
	}
}
 
Example 2
Source File: MusicController.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Stops and releases all sources, clears each of the specified Audio
 * buffers, destroys the OpenAL context, and resets SoundStore for future use.
 *
 * Calling SoundStore.get().init() will re-initialize the OpenAL context
 * after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
 *
 * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
 */
private static void destroyOpenAL() {
	if (!trackExists())
		return;
	stop();

	try {
		// get Music object's (private) Audio object reference
		Field sound = player.getClass().getDeclaredField("sound");
		sound.setAccessible(true);
		Audio audio = (Audio) (sound.get(player));

		// first clear the sources allocated by SoundStore
		int max = SoundStore.get().getSourceCount();
		IntBuffer buf = BufferUtils.createIntBuffer(max);
		for (int i = 0; i < max; i++) {
			int source = SoundStore.get().getSource(i);
			buf.put(source);

			// stop and detach any buffers at this source
			AL10.alSourceStop(source);
			AL10.alSourcei(source, AL10.AL_BUFFER, 0);
		}
		buf.flip();
		AL10.alDeleteSources(buf);
		int exc = AL10.alGetError();
		if (exc != AL10.AL_NO_ERROR) {
			throw new SlickException(
					"Could not clear SoundStore sources, err: " + exc);
		}

		// delete any buffer data stored in memory, too...
		if (audio != null && audio.getBufferID() != 0) {
			buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
			buf.flip();
			AL10.alDeleteBuffers(buf);
			exc = AL10.alGetError();
			if (exc != AL10.AL_NO_ERROR) {
				throw new SlickException("Could not clear buffer "
						+ audio.getBufferID()
						+ ", err: "+exc);
			}
		}

		// clear OpenAL
		AL.destroy();

		// reset SoundStore so that next time we create a Sound/Music, it will reinit
		SoundStore.get().clear();

		player = null;
	} catch (Exception e) {
		softErr(e, "Failed to destroy OpenAL");
	}
}
 
Example 3
Source File: Sonics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public void destroy()
{
    AL10.alDeleteSources(source);
    AL10.alDeleteBuffers(buffer);
}
 
Example 4
Source File: Audio.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
protected final void doDelete() {
	if (AL.isCreated()) {
		al_buffers.clear();
		AL10.alDeleteBuffers(al_buffers);
	}
}
 
Example 5
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alDeleteBuffers(int numBuffers, IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alDeleteBuffers(buffers);
}
 
Example 6
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alDeleteBuffers(final int numBuffers, final IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alDeleteBuffers(buffers);
}
 
Example 7
Source File: MusicController.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Stops and releases all sources, clears each of the specified Audio
 * buffers, destroys the OpenAL context, and resets SoundStore for future use.
 *
 * Calling SoundStore.get().init() will re-initialize the OpenAL context
 * after a call to destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
 *
 * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
 */
private static void destroyOpenAL() {
	if (!trackExists())
		return;
	stop();

	if (!AL.isCreated())
		return;

	try {
		// get Music object's (private) Audio object reference
		Field sound = player.getClass().getDeclaredField("sound");
		sound.setAccessible(true);
		Audio audio = (Audio) (sound.get(player));

		// first clear the sources allocated by SoundStore
		int max = SoundStore.get().getSourceCount();
		IntBuffer buf = BufferUtils.createIntBuffer(max);
		for (int i = 0; i < max; i++) {
			int source = SoundStore.get().getSource(i);
			buf.put(source);

			// stop and detach any buffers at this source
			AL10.alSourceStop(source);
			AL10.alSourcei(source, AL10.AL_BUFFER, 0);
		}
		buf.flip();
		AL10.alDeleteSources(buf);
		int exc = AL10.alGetError();
		if (exc != AL10.AL_NO_ERROR) {
			throw new SlickException(
					"Could not clear SoundStore sources, err: " + exc);
		}

		// delete any buffer data stored in memory, too...
		if (audio != null && audio.getBufferID() != 0) {
			buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
			buf.flip();
			AL10.alDeleteBuffers(buf);
			exc = AL10.alGetError();
			if (exc != AL10.AL_NO_ERROR) {
				throw new SlickException("Could not clear buffer "
						+ audio.getBufferID()
						+ ", err: "+exc);
			}
		}

		// clear OpenAL
		AL.destroy();

		// reset SoundStore so that next time we create a Sound/Music, it will reinit
		SoundStore.get().clear();

		player = null;
	} catch (Exception e) {
		ErrorHandler.error("Failed to destroy the OpenAL context.", e, true);
	}
}