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

The following examples show how to use org.lwjgl.openal.AL10#alGetSourcei() . 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: 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 2
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public synchronized void update() {
	if (done) {
		return;
	}

	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	while (processed > 0) {
		unqueued.clear();
		AL10.alSourceUnqueueBuffers(source, unqueued);
		
		int bufferIndex = unqueued.get(0);

		int bufferLength = AL10.alGetBufferi(bufferIndex, AL10.AL_SIZE);

		playedPos += bufferLength;

		if (musicLength > 0 && playedPos > musicLength)
			playedPos -= musicLength;

		if (stream(bufferIndex)) {
			AL10.alSourceQueueBuffers(source, unqueued);
		} else {
			remainingBufferCount--;
			if (remainingBufferCount == 0) {
				done = true;
			}
		}
		processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
	
	if (state != AL10.AL_PLAYING) {
		AL10.alSourcePlay(source);
	}
}
 
Example 3
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 4
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check if the music is currently playing
 * 
 * @return True if the music is playing
 */
public boolean isMusicPlaying() 
{
	if (!soundWorks) {
		return false;
	}
	
	int state = AL10.alGetSourcei(sources.get(0), AL10.AL_SOURCE_STATE);
	return ((state == AL10.AL_PLAYING) || (state == AL10.AL_PAUSED));
}
 
Example 5
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Find a free sound source
 * 
 * @return The index of the free sound source
 */
private int findFreeSource() {
	for (int i=1;i<sourceCount-1;i++) {
		int state = AL10.alGetSourcei(sources.get(i), AL10.AL_SOURCE_STATE);
		
		if ((state != AL10.AL_PLAYING) && (state != AL10.AL_PAUSED)) {
			return i;
		}
	}
	
	return -1;
}
 
Example 6
Source File: OpenALStreamPlayer.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 removeBuffers() {
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	int queued = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED);
	
	while (queued > 0)
	{
		AL10.alSourceUnqueueBuffers(source, buffer);
		queued--;
	}
}
 
Example 7
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if the music is currently playing
 * 
 * @return True if the music is playing
 */
public boolean isMusicPlaying() 
{
	if (!soundWorks) {
		return false;
	}
	
	int state = AL10.alGetSourcei(sources.get(0), AL10.AL_SOURCE_STATE);
	return ((state == AL10.AL_PLAYING) || (state == AL10.AL_PAUSED));
}
 
Example 8
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find a free sound source
 * 
 * @return The index of the free sound source
 */
private int findFreeSource() {
	for (int i=1;i<sourceCount-1;i++) {
		int state = AL10.alGetSourcei(sources.get(i), AL10.AL_SOURCE_STATE);
		
		if ((state != AL10.AL_PLAYING) && (state != AL10.AL_PAUSED)) {
			return i;
		}
	}
	
	return -1;
}
 
Example 9
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public synchronized void update() {
	if (done) {
		return;
	}

	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	while (processed > 0) {
		unqueued.clear();
		AL10.alSourceUnqueueBuffers(source, unqueued);
		
		int bufferIndex = unqueued.get(0);

		int bufferLength = AL10.alGetBufferi(bufferIndex, AL10.AL_SIZE);

		playedPos += bufferLength;

		if (musicLength > 0 && playedPos > musicLength)
			playedPos -= musicLength;

		if (stream(bufferIndex)) {
			AL10.alSourceQueueBuffers(source, unqueued);
		} else {
			remainingBufferCount--;
			if (remainingBufferCount == 0) {
				done = true;
			}
		}
		processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
	
	if (state != AL10.AL_PLAYING) {
		AL10.alSourcePlay(source);
	}
}
 
Example 10
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public void update() {
	if (done) {
		return;
	}
	
	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	
	while (processed > 0) {
		unqueued.clear();
		
		AL10.alSourceUnqueueBuffers(source, unqueued);
        if (stream(unqueued.get(0))) {
        	AL10.alSourceQueueBuffers(source, unqueued);
        } else {
        	remainingBufferCount--;
        	if (remainingBufferCount == 0) {
        		done = true;
        	}
        }
        processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
    
    if (state != AL10.AL_PLAYING) {
    	AL10.alSourcePlay(source);
    }
}
 
Example 11
Source File: QueuedAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void refill() { // Run by the Refiller thread
		int processed = AL10.alGetSourcei(source.getSource(), AL10.AL_BUFFERS_PROCESSED);
//System.out.println("this = " + this + " | processed = " + processed);
		while (processed > 0) {
//			assert processed <= al_buffers.capacity();
//			al_buffers.position(oldest_buffer);
//			al_buffers.limit(oldest_buffer + 1);
//			assert AL10.alIsBuffer(al_buffers.get(al_buffers.position())): al_buffers.get(al_buffers.position()) + " is not a buffer";
			AL10.alSourceUnqueueBuffers(source.getSource(), al_return_buffers);
//			assert al_return_buffers.get(0) == al_buffers.get(al_buffers.position()): "Unexpected buffer removed: " + al_return_buffers.get(0) + " should be " + al_buffers.get(al_buffers.position());
			int bytes = fillBuffer(al_return_buffers.get(0));
			if (bytes == 0) {
				stop();
				return;
			}
//			assert AL10.alIsBuffer(al_buffers.get(al_buffers.position())): al_buffers.get(al_buffers.position()) + " is not a buffer";
			AL10.alSourceQueueBuffers(source.getSource(), al_return_buffers);
//System.out.println("oldest_buffer = " + oldest_buffer + " | processed = " + processed + " | capacity = " + buffer_streams[oldest_buffer].buffer().capacity() + " | position " + buffer_streams[oldest_buffer].buffer().position() + " | limit " + buffer_streams[oldest_buffer].buffer().limit() + " al_size = " + AL10.alGetBufferi(al_buffers.get(oldest_buffer), AL10.AL_SIZE));
			oldest_buffer = (oldest_buffer + 1)%NUM_BUFFERS;
			processed--;
/*			int test_processed = AL10.alGetSourcei(source.getSource(), AL10.AL_BUFFERS_PROCESSED);
			assert test_processed >= processed: test_processed + " " + processed;*/
		}
		if (AL10.alGetSourcei(source.getSource(), AL10.AL_SOURCE_STATE) == AL10.AL_STOPPED)
			AL10.alSourcePlay(source.getSource());
//System.out.println("		AL10.alGetSourcei(source_index,AL10.AL_SOURCE_STATE) = " + 		AL10.alGetSourcei(source.getSource(),AL10.AL_SOURCE_STATE) + " | AL10.AL_STOPPED = " + AL10.AL_STOPPED + " | AL10.AL_PLAYING = " + AL10.AL_PLAYING);
	}
 
Example 12
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if the music is currently playing
 * 
 * @return True if the music is playing
 */
public boolean isMusicPlaying() 
{
	if (!soundWorks) {
		return false;
	}
	
	int state = AL10.alGetSourcei(sources.get(0), AL10.AL_SOURCE_STATE);
	return ((state == AL10.AL_PLAYING) || (state == AL10.AL_PAUSED));
}
 
Example 13
Source File: Mini2DxOpenALAudio.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public boolean isSoundPlaying(long soundId) {
	if (!soundIdToSource.containsKey(soundId)) {
		return false;
	}
	int sourceId = soundIdToSource.get(soundId);
	int soundState = AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE);

	switch (soundState) {
	case AL10.AL_PLAYING:
		return true;
	default:
		return false;
	}
}
 
Example 14
Source File: Mini2DxOpenALAudio.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public boolean isSoundPlaying(long soundId) {
	if (!soundIdToSource.containsKey(soundId)) {
		return false;
	}
	int sourceId = soundIdToSource.get(soundId);
	int soundState = AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE);

	switch (soundState) {
	case AL10.AL_PLAYING:
		return true;
	default:
		return false;
	}
}
 
Example 15
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clean up the buffers applied to the sound source
 */
private synchronized void removeBuffers() {
	AL10.alSourceStop(source);
	IntBuffer buffer = BufferUtils.createIntBuffer(1);

	while (AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED) > 0) {
		AL10.alSourceUnqueueBuffers(source, buffer);
		buffer.clear();
	}
}
 
Example 16
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int alGetSourcei(final int source, final int param) {
    return AL10.alGetSourcei(source, param);
}
 
Example 17
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int alGetSourcei(int source, int param) {
    return AL10.alGetSourcei(source, param);
}
 
Example 18
Source File: OpenALStreamPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Poll the bufferNames - check if we need to fill the bufferNames with another
 * section. 
 * 
 * Most of the time this should be reasonably quick
 */
public void update() {
	if (done) {
		return;
	}

	float sampleRate = audio.getRate();
	float sampleSize;
	if (audio.getChannels() > 1) {
		sampleSize = 4; // AL10.AL_FORMAT_STEREO16
	} else {
		sampleSize = 2; // AL10.AL_FORMAT_MONO16
	}
	
	int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED);
	while (processed > 0) {
		unqueued.clear();
		AL10.alSourceUnqueueBuffers(source, unqueued);
		
		int bufferIndex = unqueued.get(0);

		float bufferLength = (AL10.alGetBufferi(bufferIndex, AL10.AL_SIZE) / sampleSize) / sampleRate;
		positionOffset += bufferLength;
		
        if (stream(bufferIndex)) {			
        	AL10.alSourceQueueBuffers(source, unqueued);
        } else {
        	remainingBufferCount--;
        	if (remainingBufferCount == 0) {
        		done = true;
        	}
        }
        processed--;
	}
	
	int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
    
    if (state != AL10.AL_PLAYING) {
    	AL10.alSourcePlay(source);
    }
}
 
Example 19
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Check if a particular source is playing
 * 
 * @param index The index of the source to check
 * @return True if the source is playing
 */
boolean isPlaying(int index) {
	int state = AL10.alGetSourcei(sources.get(index), AL10.AL_SOURCE_STATE);
	
	return (state == AL10.AL_PLAYING);
}
 
Example 20
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Check if a particular source is playing
 * 
 * @param index The index of the source to check
 * @return True if the source is playing
 */
boolean isPlaying(int index) {
	int state = AL10.alGetSourcei(sources.get(index), AL10.AL_SOURCE_STATE);
	
	return (state == AL10.AL_PLAYING);
}