Sources report a queue which alSourceUnqueueBuffers does not release

Started by stillwind, July 07, 2013, 22:27:30

Previous topic - Next topic

stillwind

Edit to OP : I've found another way to achieve what I need that doesn't involve queueing at all. So, this isn't a showstopper for me, although for learning's and future sake, I would like to know what the issue is, and resolution... thanks  :)

Hi, I'm new to OpenAL, and I'm having a problem reusing sources. I've done some trials, based on the SoundStore written by Kevin Glass. So, I'm using the original method of pooling sources, and have 64 at creation time.

I want to sometimes play a sound on its own, and sometimes put it in a queue with another sound. It works fine so long as I get a source from the pool which hasn't been used before. But when it has, even though it has not been used for any explicit queueing on my part, it reports it has a queued buffer. It's in a stopped state, but even so, I can't seem to unqueue it. I've tried the 2 methods of unqueue with and without the IntBuffer parameter.

I wrote this method to test what's happening, first a little loop which plays a really small sound (about 40ms) and then waits 100ms between calls:

// report on the queued sources before play
		for (int i = 0; i < 10; i++) {
			System.out.println("testing queues iteration="+i);
			waveSourceMgr.reportQueueingSources();
			soundFiles[TICK_AUDIO].playNow(1.0f, 1.0f);
			
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}


The method to report on the sources gets a summary of what is free and what has a queue, and tries to release the queue only for non-playing sources:

void reportQueueingSources() {
	int countUsed = 0;
	int countQueueing = 0;
	int countNotQueueing = 0;
		
	for (int i=1;i<sourceCount-1;i++) {
		int state = AL10.alGetSourcei(sources.get(i), AL10.AL_SOURCE_STATE);
		printErrorCode("@ getting state");
		
		// let anything in use be
		if (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED) {
			countUsed++;
		}
		else {
			// not in use, see if there's any queue
			int queued = AL10.alGetSourcei(sources.get(i), AL10.AL_BUFFERS_QUEUED);
			printErrorCode("@ getting queued");
			
			if (queued == 0) {
				countNotQueueing++;
			}
			else {
				// there's a queue, I should be able to unqueue
				countQueueing++;
				System.out.println("got a queued source, state="+state);
				
				AL10.alSourceUnqueueBuffers(sources.get(i));
				printErrorCode("@ doing unqueue queued="+queued);
				
				// check queue again
				int queued2 = AL10.alGetSourcei(sources.get(i), AL10.AL_BUFFERS_QUEUED);
				printErrorCode("@ getting queued again");
				
				System.out.println("after attempt to unqueue, 2nd check on queued="+queued2);
			}
		}
	}
	
	System.out.println("reportQueueingSources, summary: in use="+countUsed+" free w/o queue="+countNotQueueing+" free with queue="+countQueueing);
}


And this is a sample of the output, it's basically the same for each iteration, after the first one which of course reports nothing queueing, this is the 2nd call:

testing queues iteration=1 (2nd go round)
got a queued source, state=4116 (this is AL_STOPPED)
Error @ doing unqueue queued=1 Invalid enum parameter value (this is AL10.AL_INVALID_VALUE)
after attempt to unqueue, 2nd check on queued=1
reportQueueingSources, summary: in use=0 free w/o queue=61 free with queue=1


It's important because I need to use the source later for queueing and because the sounds I'm using vary in format/attributes I have to have a clean queue to start with. With an unused source it works fine, but whenever it's one of the problem ones, my call to AL10.alSourceQueueBuffers fails with AL10.AL_INVALID_OPERATION.

Thanks for any help with this!