alBufferDataStatic instead of alBufferData
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?
Yes, it is super funky to figure it out. Look closely at what they're doing with alBufferDataStaticProc in the oalTouch sample. ... Funky!
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);
That's great, thanks AnotherJake. I'd had a quick look at oalTouch example and was a bit confused!
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:
With alBufferData it works perfectly, but with alBufferDataStaticProc, the sound is horrendous on playback. Do I need to do something to retain the buffer?
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?
I don't see anything poking out except that you're manually inputing the audio format and sample rate. I get the format using:
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.
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.
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Starting OpenAL & alBufferData()? | technocrat9000 | 8 | 5,708 |
Nov 6, 2008 09:12 AM Last Post: bmantzey |
|

