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

The following examples show how to use org.lwjgl.openal.AL10#alGetError() . 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: SoundPhysics.java    From Sound-Physics with GNU General Public License v3.0 6 votes vote down vote up
protected static boolean checkErrorLog(String errorMessage)
{
	int error = AL10.alGetError();
	String errorName;
	
	if (error != 0)
	{
		switch(error)
		{
			case AL10.AL_INVALID_NAME: 			errorName = "AL_INVALID_NAME"; break;
			case AL10.AL_INVALID_ENUM: 			errorName = "AL_INVALID_ENUM"; break;
			case AL10.AL_INVALID_VALUE: 		errorName = "AL_INVALID_VALUE"; break;
			case AL10.AL_INVALID_OPERATION: 	errorName = "AL_INVALID_OPERATION"; break;
			case AL10.AL_OUT_OF_MEMORY: 		errorName = "AL_OUT_OF_MEMORY"; break;
			default: errorName = Integer.toString(error); break;
		}
		
		System.out.println(logPrefix + " [ERROR]: " + errorMessage + " OpenAL error " + errorName);
		return true;
	}
	else
	{
		return false;
	}
}
 
Example 2
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
* Initialise OpenAL LWJGL styley
*/
  public void init() {
  	try {
	AL.create();
	soundWorks = true;
} catch (LWJGLException e) {
	System.err.println("Failed to initialise LWJGL OpenAL");
	soundWorks = false;
	return;
}

if (soundWorks) {
	IntBuffer sources = BufferUtils.createIntBuffer(1);
	AL10.alGenSources(sources);
	
	if (AL10.alGetError() != AL10.AL_NO_ERROR) {
		System.err.println("Failed to create sources");
		soundWorks = false;
	} else {
		source = sources.get(0);
	}
	
}
  }
 
Example 3
Source File: Sonics.java    From AnyaBasic with MIT License 5 votes vote down vote up
public Sonics()
{
    // Initialize OpenAL and clear the error bit.
    try
    {
        AL.create();
    }
    catch (LWJGLException e)
    {
        e.printStackTrace();
        return;
    }
    AL10.alGetError();

}
 
Example 4
Source File: AudioImpl.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.openal.Audio#setPosition(float)
 */
public boolean setPosition(float position) {
	position = position % length;
	
	AL10.alSourcef(store.getSource(index), AL11.AL_SEC_OFFSET, position);
	if (AL10.alGetError() != 0) {
		return false;
	}
	return true;
}
 
Example 5
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 6
Source File: Sonics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public int load( String filename, boolean isLooping )
{
    // Load wav data into a buffer.
    AL10.alGenBuffers(buffer);

    if(AL10.alGetError() != AL10.AL_NO_ERROR)
        return AL10.AL_FALSE;

    URL url = this.getClass().getClassLoader().getResource(filename);

    InputStream in ;
    WaveData waveFile = null;
    try
    {
        in = url.openStream();
        //Loads the wave file from this class's package in your classpath
        waveFile = WaveData.create(in);
        in.close();
        if(waveFile == null )
        {
            System.out.println("Error Loading sound data!");
        }
    }
    catch( IOException e )
    {
        e.printStackTrace();
    }


    AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
    waveFile.dispose();

    // Bind the buffer with the source.
    AL10.alGenSources(source);

    if (AL10.alGetError() != AL10.AL_NO_ERROR)
        return AL10.AL_FALSE;

    AL10.alSourcei(source.get(0), AL10.AL_BUFFER,   buffer.get(0) );
    AL10.alSourcef(source.get(0), AL10.AL_PITCH,    1.0f          );
    AL10.alSourcef(source.get(0), AL10.AL_GAIN,     1.0f          );
    AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos     );
    AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel     );
    if( isLooping ) AL10.alSourcei(source.get(0), AL10.AL_LOOPING,  AL10.AL_TRUE  );

    setListenerValues();

    // Do another error check and return.
    if (AL10.alGetError() == AL10.AL_NO_ERROR)
        return AL10.AL_TRUE;

    return AL10.AL_FALSE;
}
 
Example 7
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int alGetError() {
    return AL10.alGetError();
}
 
Example 8
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int alGetError() {
    return AL10.alGetError();
}
 
Example 9
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);
	}
}