alBufferDataStatic instead of alBufferData

Member
Posts: 352
Joined: 2002.04
Post: #1
According to Tech Note TN2199 it is better to use alBufferDataStatic instead if alBufferData for sound on the iPhone. However even when I import OpenAL/oalStaticBufferExtension.h the function is undeclared. Has anyone else experienced this?
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #2
Yes, it is super funky to figure it out. Look closely at what they're doing with alBufferDataStaticProc in the oalTouch sample. ... Funky!
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #3
Actually, the way they do it is kind of dramatic. Here's what I do:

Code:
// retrieve the static buffer function
alBufferDataStaticProcPtr    alBufferDataStaticProc = (alBufferDataStaticProcPtr)alcGetProcAddress(nil, (const ALCchar *)"alBufferDataStatic");

// buffer the data
alBufferDataStaticProc(bufferID, bitChanFormat, audioData, audioDataSize, dataFormat.mSampleRate);
Quote this message in a reply
Member
Posts: 352
Joined: 2002.04
Post: #4
That's great, thanks AnotherJake. I'd had a quick look at oalTouch example and was a bit confused!
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2009.01
Post: #5
Pardon my ignorance, but I've replaced my calls to alBufferData() with alBufferDataStaticProc(), and I'm getting some very unpleasant results.

The sequence is more or less:

Code:
        NSUInteger bufferID;
        alGenBuffers(1, &bufferID);
        error = alGetError();
        if (error) NSLog(@"    alGenBuffers got alGetError():  %d\n\n", error);
        
//alBufferData(bufferID,AL_FORMAT_STEREO16,outData,fileSize,44100);
        alBufferDataStaticProcPtr    alBufferDataStaticProc = (alBufferDataStaticProcPtr)alcGetProcAddress(nil, (const ALCchar *)"alBufferDataStatic");
        
        alBufferDataStaticProc(bufferID, AL_FORMAT_STEREO16, outData, fileSize, 44100);
        
        error = alGetError();
        if (error) NSLog(@"    alBufferData got alGetError():  %d\n\n", error);
        
        // save the buffer so I can release it later
        [bufferStorageArray addObject:[NSNumber numberWithUnsignedInteger:bufferID]];
        
        // grab a source ID from openAL
        UInt32 sourceID;
        alGenSources(1, &sourceID);
        error = alGetError();
        if (error) NSLog(@"    alGenSources got alGetError():  %d\n\n", error);
        
        // attach the buffer to the source
        alSourcei(sourceID, AL_BUFFER, bufferID);
        alSourcef(sourceID, AL_GAIN, 1.0f);

With alBufferData it works perfectly, but with alBufferDataStaticProc, the sound is horrendous on playback. Do I need to do something to retain the buffer?
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #6
I don't see anything poking out except that you're manually inputing the audio format and sample rate. I get the format using:

Code:
size = sizeof(dataFormat);
AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &size, &dataFormat);

And use the values from that.

Still, you'd think that if a given file worked for you using alBufferData, it should work exactly the same with alBufferDataStaticProc. Weird.
Quote this message in a reply
Member
Posts: 352
Joined: 2002.04
Post: #7
Actually, I had a similar problem. Try AnotherJake's solution first as that might work and is simpler, but what I did was to use the oalTouch sample's loading code and that solved whatever problem was causing the distorted sound.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Starting OpenAL & alBufferData()? technocrat9000 8 6,555 Nov 6, 2008 09:12 AM
Last Post: bmantzey