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

The following examples show how to use org.lwjgl.openal.AL10#alSourceQueueBuffers() . 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: 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 2
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 3
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 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
/**
 * 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 6
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 7
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 8
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * Play a mod or xm track streamed from the specified location
    * 
    * @param module The moudle to play back
    * @param source The OpenAL source to play the music on
    * @param start True if the music should be started
    * @param loop True if the track should be looped
    */
public void play(Module module, int source, boolean loop, boolean start) {
	this.source = source;
	this.loop = loop;
	this.module = module;
	done = false;
	
	ibxm = new IBXM(48000);
	ibxm.set_module(module);
	songDuration = ibxm.calculate_song_duration();

	if (bufferNames != null) {
		AL10.alSourceStop(source);
		bufferNames.flip();
		AL10.alDeleteBuffers(bufferNames);
	}
	
	bufferNames = BufferUtils.createIntBuffer(2);
	AL10.alGenBuffers(bufferNames);
	remainingBufferCount = 2;
	
	for (int i=0;i<2;i++) {
        stream(bufferNames.get(i));
	}
       AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcef(source, AL10.AL_PITCH, 1.0f);
	AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); 
	
	if (start) {
		AL10.alSourcePlay(source);
	}
}
 
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 alSourceQueueBuffers(int source, int numBuffers, IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alSourceQueueBuffers(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 alSourceQueueBuffers(final int source, final int numBuffers, final IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alSourceQueueBuffers(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);
    }
}