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

The following examples show how to use org.lwjgl.openal.AL10#alSourceUnqueueBuffers() . 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
/**
 * 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 3
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 4
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 5
Source File: OpenALStreamPlayer.java    From opsu 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 6
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 7
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 8
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 9
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 10
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alSourceUnqueueBuffers(int source, int numBuffers, IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alSourceUnqueueBuffers(source, buffers);
}
 
Example 11
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alSourceUnqueueBuffers(final int source, final int numBuffers, final IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alSourceUnqueueBuffers(source, buffers);
}
 
Example 12
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);
    }
}