Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:52:56+00:00 2026-05-29T11:52:56+00:00

I am loading a initial set of 100+ sounds into the OpenAL buffer. After

  • 0

I am loading a initial set of 100+ sounds into the OpenAL buffer. After a while I am clearing the OpenAL context and reloading another set of sounds. But the newly loaded files are not playing. It seems that the previous OpenAL buffers are not really released.

Here is my code for initializing and destroying OpenAL

- (void)initOpenAL
{
    // Initialization
    mDevice = alcOpenDevice(NULL); // select the “preferred device”
    if (mDevice) {
        // use the device to make a context
        mContext=alcCreateContext(mDevice,NULL);
        // set my context to the currently active one
        alcMakeContextCurrent(mContext);
    }
}

- (void)cleanUpOpenAL
{
    // delete the sources
    for (NSNumber * sourceNumber in [soundDictionary allValues]) 
    {
        NSUInteger sourceID = [sourceNumber unsignedIntegerValue];
        alDeleteSources(1, &sourceID);
    }

    [soundDictionary removeAllObjects];

    // delete the buffers
    for (NSNumber * bufferNumber in bufferStorageArray) 
    {
        NSUInteger bufferID = [bufferNumber unsignedIntegerValue];
        alDeleteBuffers(1, &bufferID);
    }

    [bufferStorageArray removeAllObjects];

    // destroy the context
    alcDestroyContext(mContext);
    // close the device
    alcCloseDevice(mDevice);
}

This is how I load the sounds inside a loop:

NSString *filePath = [[NSBundle mainBundle] pathForResource:subString ofType:@"wav"];
        AudioFileID fileID = [self openAudioFile:filePath];

        // find out how big the actual audio data is
        UInt32 fileSize = (UInt32)[self audioFileSize:fileID];

        // this is where the audio data will live for the moment
        unsigned char * outData = malloc(fileSize);

        // this where we actually get the bytes from the file and put them
        // into the data buffer
        OSStatus result = noErr;
        result = AudioFileReadBytes(fileID, false, 0, &fileSize, outData);

        if (result != 0) NSLog(@"cannot load effect: %@",fileName);

        NSUInteger bufferID;
        // grab a buffer ID from openAL
        alGenBuffers(1, &bufferID);
        if((alGetError()) != AL_NO_ERROR) {
            printf("Error!");
        }

        // jam the audio data into the new buffer
        alBufferData(bufferID,AL_FORMAT_STEREO16,outData,fileSize,44100);
        if((alGetError()) != AL_NO_ERROR) {
            printf("Error!");
        }

        // clean up the buffer
        if (outData)
        {
            free(outData);
        }
        else
        {
            outData = NULL;
        }

        // save the buffer so I can release it later
        [bufferStorageArray addObject:[NSNumber numberWithUnsignedInteger:bufferID]];

        NSUInteger sourceID;

        // grab a source ID from openAL
        alGenSources(1, &sourceID);

        // attach the buffer to the source
        alSourcei(sourceID, AL_BUFFER, bufferID);

        // store this for future use
        [soundDictionary setObject:[NSNumber numberWithUnsignedInt:sourceID] forKey: [NSNumber numberWithUnsignedInt:i+(padNumber*10)]];

        subString = NULL;
        filePath = NULL;

And this is what I am doing before I am reloading the new set of sounds:

[self cleanUpOpenAL];
[self initOpenAL];

Any idea where things are going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:52:58+00:00Added an answer on May 29, 2026 at 11:52 am

    After almost a week of analysis, I found the bug. The problem was that I wasn’t closing the AudioFile. Everything worked after I added this piece of code after I’ve used the fileID

    AudioFileClose(fileID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte
When loading XML into an XmlDocument, i.e. XmlDocument document = new XmlDocument(); document.LoadXml(xmlData); is
After loading a PHP template (using jQuery's load function), this simple script won't make
After loading a reference to an assembly with something like: import clr clr.AddRferenceToFileAndPath(r'C:\foo.dll') How
After loading dynamic content to a DIV, I'd like to add a Close option,
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file
I use dynamic script loading to reduce the duration of the initial page load.
I have a Div which I want to say Loading... while an AJAX request
I am using codeigniter 1.7.3 and I have controllers set up and working, but
I am loading initial data (url list for a crawler) to Cassandra with status

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.