Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwantnon_cn

Posted 04 May 2013 - 08:49 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound not play normal. 

i just wonder why it is not just as the process of creating textures in OpenGL: when creating texture, after the texture established we can free the image data. 

so, back to OpenAL and the MusicCube sample, did it freed the _data in some where else i did not notice? or it just not be freed? if _data not freed, may it cause memory inefficiency?  

 

 

 

 


#5wantnon_cn

Posted 04 May 2013 - 08:49 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound not play normal. 

i just wonder why it is not just as the process of creating textures in OpenGL: when creating texture, after the texture established we can free the image data. 

so, back to OpenAL and the MusicCube sample, did it freed the _data in some where else i did not notice? or it just not be freed? if the _data not be freed, may it cause memory inefficiency?  

 

 

 


#4wantnon_cn

Posted 04 May 2013 - 08:47 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound not play normal. 

i just wonder why it is not just as the process of creating textures in OpenGL: when creating texture, after the texture established we can free the image data. 

did it freed the _data in some where else i not noticed? or it is just not freed? if the _data not be freed, may it cause memory inefficiency?  

 

 


#3wantnon_cn

Posted 04 May 2013 - 08:46 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound not play normal. 

i just wonder why it is not just as the process of create textures in OpenGL: after the texture established, we can free the image data. 

did it freed the _data in some where else i not noticed? or it is just not freed? if the _data not be freed, may it cause memory inefficiency?  

 


#2wantnon_cn

Posted 04 May 2013 - 08:45 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound play not normal. 

i just wonder why it is not just as the process of create textures in OpenGL: after the texture established, we can free the image data. 

did it freed the _data in some where else i not noticed? or it is just not freed? if the _data not be freed, may it cause memory inefficiency?  


#1wantnon_cn

Posted 04 May 2013 - 08:44 PM

i am adding sound to my iOS game using OpenAL, i downloaded the sample code "MusicCube" at Apple Developer, and i use the code directly in my game and it works fine.

but however, i have a question about the sample code, in the sample code, in file MusicCubePlayback.m i find the initBuffer function, for your convenience i paste it here:

- (void) initBuffer

{
ALenum  error = AL_NO_ERROR;
ALenum  format;
ALsizei size;
ALsizei freq;
 
NSBundle* bundle = [NSBundle mainBundle];
 
// get some audio data from a wave file
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle pathForResource:@"sound" ofType:@"wav"]] retain];
 
if (fileURL)
{
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        NSLog(@"audioInfo:%d,%d,%d",size,format,freq);
CFRelease(fileURL);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error loading sound: %x\n", error);
exit(1);
}
 
// use the static buffer data API
alBufferDataStaticProc(_buffer, format, _data, size, freq);
 
if((error = alGetError()) != AL_NO_ERROR) {
printf("error attaching audio to buffer: %x\n", error);
}
}
else
{
printf("Could not find file!\n");
_data = NULL;
}
}

my question is: after the alBuffer established, why didn't they free the _data?  i think the alBuffer should be a memory in audio card and through the initBuffer function we submit the audio data in _data to audio card(alBuffer) and then _data is no more needed so we can free it. but i tried to free _data and it cause the sound play not normal. 

i just wonder why it is not just as the process of create textures in OpenGL: after the texture established, we can free the image data. 

did it freed the _data in some where else i not noticed? or it is just not freed? if the _data not be freed, may it cause memory inefficiency?  


PARTNERS