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

The following examples show how to use org.lwjgl.openal.AL10#alSourcei() . 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
private static void setEnvironment(int sourceID, float sendGain0, float sendGain1, float sendGain2, float sendGain3, float sendCutoff0, float sendCutoff1,
		float sendCutoff2, float sendCutoff3, float directCutoff, float directGain)
{
	//Set reverb send filter values and set source to send to all reverb fx slots
	EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAIN, sendGain0);
	EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAINHF, sendCutoff0);
	AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot0, 0, sendFilter0);	
	
	EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAIN, sendGain1);
	EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAINHF, sendCutoff1);
	AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot1, 1, sendFilter1);	
	
	EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAIN, sendGain2);
	EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAINHF, sendCutoff2);
	AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot2, 2, sendFilter2);	
	
	EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAIN, sendGain3);
	EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAINHF, sendCutoff3);
	AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot3, 3, sendFilter3);	
	
	EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAIN, directGain);
	EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff);
	AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0);
	
	AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, SoundPhysicsCore.Config.airAbsorption);
}
 
Example 2
Source File: StreamSound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private void cleanUpSource() {
	SoundStore store = SoundStore.get();
	
	AL10.alSourceStop(store.getSource(0));
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);
		queued--;
	}
	
	AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);
}
 
Example 3
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example 4
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example 5
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Play the specified buffer as music (i.e. use the music channel)
 * 
 * @param buffer The buffer to be played
 * @param pitch The pitch to play the music at
 * @param gain The gaing to play the music at
 * @param loop True if we should loop the music
 */
void playAsMusic(int buffer,float pitch,float gain, boolean loop) {
	paused = false;
	
	setMOD(null);
	
	if (soundWorks) {
		if (currentMusic != -1) {
			AL10.alSourceStop(sources.get(0));
		}
		
		getMusicSource();
		
		AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffer);
		AL10.alSourcef(sources.get(0), AL10.AL_PITCH, pitch);
	    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, loop ? AL10.AL_TRUE : AL10.AL_FALSE);
		
		currentMusic = sources.get(0);
		
		if (!music) {
			pauseLoop();
		} else {
			AL10.alSourcePlay(sources.get(0)); 
		}
	}
}
 
Example 6
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Starts the streaming.
 */
private void startPlayback() {
	removeBuffers();
	AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_FALSE);
	AL10.alSourcef(source, AL10.AL_PITCH, pitch);

	remainingBufferCount = BUFFER_COUNT;

	for (int i = 0; i < BUFFER_COUNT; i++) {
		stream(bufferNames.get(i));
	}

	AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcePlay(source);
}
 
Example 7
Source File: MODSound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private void cleanUpSource() {
	AL10.alSourceStop(store.getSource(0));
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);
		queued--;
	}
	
	AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);
}
 
Example 8
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 9
Source File: OpenALStreamPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Starts the streaming.
 */
private void startPlayback() {
	AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_FALSE);
	AL10.alSourcef(source, AL10.AL_PITCH, pitch);

	remainingBufferCount = BUFFER_COUNT;

	for (int i = 0; i < BUFFER_COUNT; i++) {
		stream(bufferNames.get(i));
	}

	AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcePlay(source);
}
 
Example 10
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 11
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Starts the streaming.
 */
private void startPlayback() {
	removeBuffers();
	AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_FALSE);
	AL10.alSourcef(source, AL10.AL_PITCH, pitch);

	remainingBufferCount = BUFFER_COUNT;

	for (int i = 0; i < BUFFER_COUNT; i++) {
		stream(bufferNames.get(i));
	}

	AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcePlay(source);
}
 
Example 12
Source File: QueuedAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
QueuedAudioPlayer(AudioSource source, AudioParameters params) {
	super(source, params);
	this.url = Utils.makeURL((String)params.sound);
	this.buffer_stream = new ByteBufferOutputStream(true);
	if ((!params.music && !Settings.getSettings().play_sfx) || this.source == null) {
		this.ogg_stream = null;
		this.channels = 0;
		this.audio = null;
		return;
	}

	if (params.relative)
		AL10.alSourcei(source.getSource(), AL10.AL_SOURCE_RELATIVE, AL10.AL_TRUE);
	else
		AL10.alSourcei(source.getSource(), AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE);
	
	setGain(params.gain);
	setPos(params.x, params.y, params.z);

	audio = new Audio(NUM_BUFFERS);
	IntBuffer al_buffers = audio.getBuffers();
	this.ogg_stream = new OGGStream(url);
	this.channels = ogg_stream.getChannels();
	for (int i = 0; i < al_buffers.capacity(); i++) {
		fillBuffer(al_buffers.get(i));
	}

	AL10.alSourcei(source.getSource(), AL10.AL_LOOPING, AL10.AL_FALSE);
	AL10.alSourcef(source.getSource(), AL10.AL_ROLLOFF_FACTOR, ROLLOFF_FACTOR);
	AL10.alSourcef(source.getSource(), AL10.AL_REFERENCE_DISTANCE, params.radius);
	AL10.alSourcef(source.getSource(), AL10.AL_MIN_GAIN, 0f);
	AL10.alSourcef(source.getSource(), AL10.AL_MAX_GAIN, 1f);
	AL10.alSourcef(source.getSource(), AL10.AL_PITCH, params.pitch);
	AL10.alSourceQueueBuffers(source.getSource(), al_buffers);
	if (params.music || AudioManager.getManager().startPlaying())
		AL10.alSourcePlay(source.getSource());

	AudioManager.getManager().registerQueuedPlayer(this);
}
 
Example 13
Source File: AbstractAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public void stop() {
	if (playing) {
		AL10.alSourceStop(source.getSource());
		AL10.alSourcei(source.getSource(), AL10.AL_BUFFER, AL10.AL_NONE);
		AL10.alSourceRewind(source.getSource());
		playing = false;
	}
}
 
Example 14
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 15
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alSourcei(final int source, final int param, final int value) {
    AL10.alSourcei(source, param, value);
}
 
Example 16
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alSourcei(int source, int param, int value) {
    AL10.alSourcei(source, param, value);
}
 
Example 17
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);
	}
}
 
Example 18
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 19
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");
	}
}