ios4 - IOS/OpenAl Sound Interference -


i'm new in objective - c...

i found source code how use openal, copying , testing, sound played interference. can @ code , tell wrong ?

alccontext *context = null; alcdevice *device = alcopendevice(null); if (device) {     context = alccreatecontext(device, null);     alcmakecontextcurrent(context); } nsstring *path = [[nsbundle mainbundle] pathforresource:@"sound" oftype:@"caf"];  audiofileid fileid = 0; nsurl *url = [nsurl fileurlwithpath:path];  osstatus result = audiofileopenurl((cfurlref)url, kaudiofilereadpermission, 0, &fileid); if (result != 0)     nslog(@"faild load file @ path:%@",path);  uint32 filesize = 0; uint32 propsize = sizeof(uint64);  osstatus result1 = audiofilegetproperty(fileid, kaudiofilepropertyaudiodatabytecount, &propsize, &filesize); if (result1 != 0)     nslog(@"cannot size of file!");  unsigned char *buffer = malloc(filesize); osstatus result2 = noerr; result2 = audiofilereadbytes(fileid, false, 0, &filesize, buffer); audiofileclose(fileid); if (result2 != 0)     nslog(@"cannot load data file!");  aluint bufferid = 0; algenbuffers(1, &bufferid); albufferdata(bufferid, al_format_stereo16,  buffer, filesize, 44100);  free(buffer);   aluint sourceid = 0; algensources(1, &sourceid); alsourcei(sourceid, al_buffer, bufferid); alsourcef(sourceid, al_pitch, 1.0f); alsourcef(sourceid, al_gain, 1.0f);  alsourcei(sourceid, al_looping, al_true);  alsourceplay(sourceid); 

the sound won't play if sound data not stored in memory.

free(buffer);  

your sound data wiped memory, albufferdata() binds openal sound data. suggest store buffer pointer elsewhere can freed when want sound removed memory.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -