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

The following examples show how to use org.lwjgl.openal.AL10#alSource() . 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: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Play the specified buffer as a sound effect with the specified
 * pitch and gain.
 * 
 * @param buffer The ID of the buffer to play
 * @param pitch The pitch to play at
 * @param gain The gain to play at
 * @param loop True if the sound should loop
 * @param x The x position to play the sound from
 * @param y The y position to play the sound from
 * @param z The z position to play the sound from
 * @return source The source that will be used
 */
int playAsSoundAt(int buffer,float pitch,float gain,boolean loop,float x, float y, float z) {
	gain *= soundVolume;
	if (gain == 0) {
		gain = 0.001f;
	}
	if (soundWorks) {
		if (sounds) {
			int nextSource = findFreeSource();
			if (nextSource == -1) {
				return -1;
			}
			
			AL10.alSourceStop(sources.get(nextSource));
			
			AL10.alSourcei(sources.get(nextSource), AL10.AL_BUFFER, buffer);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_PITCH, pitch);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_GAIN, gain); 
		    AL10.alSourcei(sources.get(nextSource), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		    
		    sourcePos.clear();
		    sourceVel.clear();
			sourceVel.put(new float[] { 0, 0, 0 });
			sourcePos.put(new float[] { x, y, z });
		    sourcePos.flip();
		    sourceVel.flip();
		    AL10.alSource(sources.get(nextSource), AL10.AL_POSITION, sourcePos);
   			AL10.alSource(sources.get(nextSource), AL10.AL_VELOCITY, sourceVel);
		    
			AL10.alSourcePlay(sources.get(nextSource)); 
			
			return nextSource;
		}
	}
	
	return -1;
}
 
Example 2
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Play the specified buffer as a sound effect with the specified
 * pitch and gain.
 * 
 * @param buffer The ID of the buffer to play
 * @param pitch The pitch to play at
 * @param gain The gain to play at
 * @param loop True if the sound should loop
 * @param x The x position to play the sound from
 * @param y The y position to play the sound from
 * @param z The z position to play the sound from
 * @return source The source that will be used
 */
int playAsSoundAt(int buffer,float pitch,float gain,boolean loop,float x, float y, float z) {
	gain *= soundVolume;
	if (gain == 0) {
		gain = 0.001f;
	}
	if (soundWorks) {
		if (sounds) {
			int nextSource = findFreeSource();
			if (nextSource == -1) {
				return -1;
			}
			
			AL10.alSourceStop(sources.get(nextSource));
			
			AL10.alSourcei(sources.get(nextSource), AL10.AL_BUFFER, buffer);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_PITCH, pitch);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_GAIN, gain); 
		    AL10.alSourcei(sources.get(nextSource), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		    
		    sourcePos.clear();
		    sourceVel.clear();
			sourceVel.put(new float[] { 0, 0, 0 });
			sourcePos.put(new float[] { x, y, z });
		    sourcePos.flip();
		    sourceVel.flip();
		    AL10.alSource(sources.get(nextSource), AL10.AL_POSITION, sourcePos);
   			AL10.alSource(sources.get(nextSource), AL10.AL_VELOCITY, sourceVel);
		    
			AL10.alSourcePlay(sources.get(nextSource)); 
			
			return nextSource;
		}
	}
	
	return -1;
}
 
Example 3
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Play the specified buffer as a sound effect with the specified
 * pitch and gain.
 * 
 * @param buffer The ID of the buffer to play
 * @param pitch The pitch to play at
 * @param gain The gain to play at
 * @param loop True if the sound should loop
 * @param x The x position to play the sound from
 * @param y The y position to play the sound from
 * @param z The z position to play the sound from
 * @return source The source that will be used
 */
int playAsSoundAt(int buffer,float pitch,float gain,boolean loop,float x, float y, float z) {
	gain *= soundVolume;
	if (gain == 0) {
		gain = 0.001f;
	}
	if (soundWorks) {
		if (sounds) {
			int nextSource = findFreeSource();
			if (nextSource == -1) {
				return -1;
			}
			
			AL10.alSourceStop(sources.get(nextSource));
			
			AL10.alSourcei(sources.get(nextSource), AL10.AL_BUFFER, buffer);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_PITCH, pitch);
			AL10.alSourcef(sources.get(nextSource), AL10.AL_GAIN, gain); 
		    AL10.alSourcei(sources.get(nextSource), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		    
		    sourcePos.clear();
		    sourceVel.clear();
			sourceVel.put(new float[] { 0, 0, 0 });
			sourcePos.put(new float[] { x, y, z });
		    sourcePos.flip();
		    sourceVel.flip();
		    AL10.alSource(sources.get(nextSource), AL10.AL_POSITION, sourcePos);
   			AL10.alSource(sources.get(nextSource), AL10.AL_VELOCITY, sourceVel);
		    
			AL10.alSourcePlay(sources.get(nextSource)); 
			
			return nextSource;
		}
	}
	
	return -1;
}
 
Example 4
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;
}