OpenAL, i am doing it wrong or is it broken on iPad simulator?

Member
Posts: 29
Joined: 2008.10
Post: #1
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,
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #2
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.
Quote this message in a reply
Member
Posts: 29
Joined: 2008.10
Post: #3
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
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #4
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Updated to SDK4, CADisplayLink layer now sized wrong on iPad michaeltoy 6 4,774 Jul 19, 2010 12:39 AM
Last Post: Madrayken
  Upgraded to 10.6, XCode 3.2.1 -- OpenGL broken MonsterFerg 7 4,460 Feb 20, 2010 12:38 AM
Last Post: MonsterFerg
  OpenAL and AVAudioPlayer in the Simulator AkumaStreak 4 6,110 Jul 12, 2009 11:05 AM
Last Post: Madrayken
  broken pipes kendric 0 1,753 Jun 7, 2009 09:09 PM
Last Post: kendric
  Wrong x,y coordinates with Texture2D class Minishlink 2 3,287 Feb 12, 2009 11:37 AM
Last Post: Minishlink