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 7941175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:35:23+00:00 2026-06-03T23:35:23+00:00

everyone , I have a problem about the API– alSourceUnqueueBuffers when I use the

  • 0

everyone , I have a problem about the API– alSourceUnqueueBuffers when I use the OpenAL Libaray.

My problem as follows:

1.I play a pcm-music though streaming mechanism.

2.The application can queue up one or multiple buffer names using alSourceQueueBuffers.

  1. when a buffer has been processed. I want to fill new audio data in my function: getSourceState . but when I use the API of OpenAL alSourceUnqueueBuffers. it returns an error
    — AL_INVALID_OPERATION . I do this as the document about the OpenAL.
    so I test a way to solve this problem. I use alSourceStop(source) before the api alSourceUnqueueBuffers, an use alSourcePlay(source) after i filled new data though
    alBufferData & alSourceQueueBuffers. but it is bad. because It breaks down the music.

who can help me to find this problem ?

and where i can find more information and method about openAL?

I am waiting for your help . thanks , everyone.

so my code as follows:

.h:

    @interface myPlayback : NSObject
    {
    ALuint                  source;
    ALuint              *   buffers;
    ALCcontext*             context;
    ALCdevice*              device;
    unsigned long long      offset;
    ALenum                  m_format;
    ALsizei                 m_freq;
    void*                   data;
    }

@end

.m

    - (void)initOpenAL
    {
    ALenum          error;

    // Create a new OpenAL Device
    // Pass NULL to specify the system’s default output device
    device = alcOpenDevice(NULL);
    if (device != NULL)
    {
        // Create a new OpenAL Context
        // The new context will render to the OpenAL Device just created 
        context = alcCreateContext(device, 0);
        if (context != NULL)
        {
            // Make the new context the Current OpenAL Context
            alcMakeContextCurrent(context);

            // Create some OpenAL Buffer Objects

            buffers = (ALuint*)malloc(sizeof(ALuint) * 5);
            alGenBuffers(5, buffers);
            if((error = alGetError()) != AL_NO_ERROR) {
                NSLog(@"Error Generating Buffers: %x", error);
                exit(1);
            }

            // Create some OpenAL Source Objects
            alGenSources(1, &source);
            if(alGetError() != AL_NO_ERROR) 
            {
                NSLog(@"Error generating sources! %x\n", error);
                exit(1);
            }

        }
    }
    // clear any errors
    alGetError();

    [self initBuffer];  
        [self initSource];
}

    - (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:@"4" ofType:@"caf"]] retain];

    if (fileURL)
    {   
        data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
        CFRelease(fileURL);
        m_freq = freq;
        m_format = format;
        if((error = alGetError()) != AL_NO_ERROR) {
            NSLog(@"error loading sound: %x\n", error);
            exit(1);
        }

        alBufferData(buffers[0], format, data, READ_SIZE , freq);
        offset += READ_SIZE;
        alBufferData(buffers[1], format, data + offset, READ_SIZE, freq);
        offset += READ_SIZE;
        alBufferData(buffers[2], format, data + offset, READ_SIZE, freq);
        offset += READ_SIZE;
        alBufferData(buffers[3], format, data + offset, READ_SIZE, freq);
        offset += READ_SIZE;
        alBufferData(buffers[4], format, data + offset, READ_SIZE, freq);
        offset += READ_SIZE;

        if((error = alGetError()) != AL_NO_ERROR) {
            NSLog(@"error attaching audio to buffer: %x\n", error);
        }       
    }
    else
        NSLog(@"Could not find file!\n");
}

    - (void) initSource
    {
    ALenum error = AL_NO_ERROR;
    alGetError(); // Clear the error

    // Turn Looping ON
    alSourcei(source, AL_LOOPING, AL_TRUE);

    // Set Source Position
    float sourcePosAL[] = {sourcePos.x, kDefaultDistance, sourcePos.y};
    alSourcefv(source, AL_POSITION, sourcePosAL);

    // Set Source Reference Distance
    alSourcef(source, AL_REFERENCE_DISTANCE, 50.0f);

    alSourceQueueBuffers(source, 5, buffers);

    if((error = alGetError()) != AL_NO_ERROR) {
        NSLog(@"Error attaching buffer to source: %x\n", error);
        exit(1);
    }   
}





    - (void)startSound
        {
        ALenum error;

        NSLog(@"Start!\n");
        // Begin playing our source file
        alSourcePlay(source);
        if((error = alGetError()) != AL_NO_ERROR) {
            NSLog(@"error starting source: %x\n", error);
        } else {
            // Mark our state as playing (the view looks at this)
            self.isPlaying = YES;
        }

        while (1) {
            [self getSourceState];
        }
}
    -(void)getSourceState
    {
    int queued;
    int processed;
    int state;
    alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
    alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
    alGetSourcei(source, AL_SOURCE_STATE, &state);
    NSLog(@"%d", queued);
    NSLog(@"%d", processed);

    NSLog(@"===================================");

    while (processed > 0) {
        for (int i = 0; i < processed; ++i) {
            ALuint buf;
            alGetError();
    //            alSourceStop(source);
            ALenum y = alGetError();
            NSLog(@"%d", y);
            alSourceUnqueueBuffers(source, 1, &buf);
            ALenum i = alGetError();
            NSLog(@"%d", i);
            processed --;
            alBufferData(buf, m_format, data + offset, READ_SIZE, m_freq);
            ALenum j = alGetError();
            NSLog(@"%d", j);
            alSourceQueueBuffers(source, 1, &buf);
            ALenum k = alGetError();
            NSLog(@"%d", k);
            offset += READ_SIZE;
//            alSourcePlay(source);
        }
    }

//    [self getSourceState];
}
  • 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-06-03T23:35:25+00:00Added an answer on June 3, 2026 at 11:35 pm

    I found the reason about the problem.

    the reason I turn Looping ON : alSourcei(source, AL_LOOPING, AL_TRUE);

    if you set this , when the source processed a buffer, you want to fill new data or delete the buffer from the source. you will get the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem about the font in iphone/ipad Everyone knows UILabel can't do
Good day everyone! I have a problem regarding my date. It needs to be
Hi everyone my problem today is I have a couple of buttons that slide
Good day everyone. I have been having the same problem all day at work
hey everyone, here is the site SEE BELOW I have a slight jquery problem
Hello everyone I have a difficult problem with using BULK INSERT command when I
I have an Android app, which is intended for use by about 10 people,
everyone, I met a problem about APNs when I used the code below. I
Hello everyone I'm just about to submit my app and i have archived it
I have a central git repository that everyone pushes to for testing and integration,

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.