iDevGames Forums
OpenAL, i am doing it wrong or is it broken on iPad simulator? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: OpenAL, i am doing it wrong or is it broken on iPad simulator? (/thread-132.html)



OpenAL, i am doing it wrong or is it broken on iPad simulator? - AdrianM - Apr 21, 2010 01:19 PM

Can't test this on the device 'till tomorrow or the day after tomorrow.

I'm investigating how can i correctly create a source,buffers, queue buffers and then release the buffers for the source, so that i can reuse it with other buffers. The following code though does not seem to output the correct thing. Here it is:

Code:
pDevice = alcOpenDevice(NULL);
    pContext = alcCreateContext(pDevice, NULL);
    alcMakeContextCurrent(pContext);

    ALuint source;
    alGenSources(1, &source);    
    assert(alGetError() == AL_NO_ERROR);
    
    char asdo[10240] = {0}, asdo2[10240] = {0};
        
    ALuint buffers[2],uq[2];
    alGenBuffers(2, buffers);        
    assert(alGetError() == AL_NO_ERROR);
    
    alBufferData(buffers[0], AL_FORMAT_MONO16, asdo, 10240, 22100);
    assert(alGetError() == AL_NO_ERROR);
    
    alBufferData(buffers[1], AL_FORMAT_MONO16, asdo2, 10240, 22100);
    assert(alGetError() == AL_NO_ERROR);
    
    alSourceQueueBuffers(source, 1, &buffers[0]);
    assert(alGetError() == AL_NO_ERROR);
    
    alSourceQueueBuffers(source, 1, &buffers[1]);    
    assert(alGetError() == AL_NO_ERROR);
    ALint q;
    
    alGetSourcei(source, AL_BUFFERS_QUEUED, &q);
    assert(alGetError() == AL_NO_ERROR);
    printf("q=%d\n", q);
    
    alSourcePlay(source); // play
    assert(alGetError() == AL_NO_ERROR);
    alSourceStop(source); // stop
    assert(alGetError() == AL_NO_ERROR);
    
    alSourceUnqueueBuffers(source, 1, &uq[0]);
    assert(alGetError() == AL_NO_ERROR);
    
    alSourceUnqueueBuffers(source, 1, &uq[1]);        
    assert(alGetError() == AL_NO_ERROR);
    
    q = -1;
    alGetSourcei(source, AL_BUFFERS_QUEUED, &q);
    printf("q=%d Error=%d - %d %d - %d %d\n", q, alGetError(), uq[0], uq[1], buffers[0], buffers[1]);

It says:
q=2
q=2 Error=0 - 2401 2401 - 2401 2402

Why is it the second q still 2? I thought it had to be 0, because there are no more buffers queued; also the unqueued buffers are wrong,


OpenAL, i am doing it wrong or is it broken on iPad simulator? - Rasterman - Apr 21, 2010 09:52 PM

I have noticed the simulator definitely acts different than the real device. Also since OpenAL runs in another thread you may need to put sleeps between your calls for you to get the results you expect.


OpenAL, i am doing it wrong or is it broken on iPad simulator? - AdrianM - Apr 23, 2010 08:52 AM

Rasterman Wrote:I have noticed the simulator definitely acts different than the real device. Also since OpenAL runs in another thread you may need to put sleeps between your calls for you to get the results you expect.

Sorry for the late response, i got my ipad and eagerly tested on it too. Same results.
It turned out that yeah, you are definetely right on sleeping. I did that and solved the problem. My question is then: how long should i sleep, and when? Should i do it for every openal command? I'm wondering how other people are dealing with this synchronization with openal.

Thanks,

Adrian


OpenAL, i am doing it wrong or is it broken on iPad simulator? - Rasterman - Apr 23, 2010 11:18 AM

Well it depends on your app, if its real time i wouldn't suggest using sleeps at all, you never know for certain a sleep will work or how long it will be, as it depends on how many threads are running and the OS thread scheduling. A better thing to do would be to code it so your app checks for the values it expects after a certain time has passed, polling type code. Or just unqueue the buffers and forget about them, why check that they are really unqueued? There is nothing you can do about it if they aren't. The only commands that probably need sleeps behind them are the ones that queue/unqueue buffers.