-1

I have been writing some OpenAL apps from some tutorials and they are all command line projects. One project continually changes the location of a source in space by repeatedly calling the alSource3f in a while loop. This is fine for an app that just runs. I can hear the source buffer's audio and hear it changing position in 3d space as the app runs. However, I want to dynamically change the source position myself using some UI slider's in a cocoa application. The problem is that now I cannot allow this while loop to operate on the main thread as it locks down the UI. I tried to throw the while loop and its contents on a background queue using the GCD api like this:

  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

      do {
      // get next theta
      updateSourceLocation(player);
      CheckALError ("Couldn't set source position");

      // refill buffers if needed
      refillALBuffers (&player);

      CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false);
   } while (difftime(time(NULL), startTime) < RUN_TIME);

   });

The function updateSourceLocation internally calls alSource3f and by the next line at CheckALError I get OpenAL Error: Couldn't set source position (AL_INVALID_ENUM). Can OpenAL library functions only be called on the main thread? What can I do to be able to control UI on the main thread and run OpenAL on a background queue or thread?

Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80
  • can the down-voter explain? this is a problem that was a bit above my head to solve and i posted context and code and details and explanation of my attempt. – Alex Bollbach Feb 28 '16 at 03:46

1 Answers1

1

You don't need to continuously be setting the source position. Just set it once it is changed, OpenAL will remember the position forever. However you do need to refill the buffers continuously, unless you are playing a loop.

  • but i want to set the location. now, then, whenever. the point of my question was that I can either set it in the main thread (which blocks the UI) or i can on a background thread but when i Do openAL throws an error. – Alex Bollbach Feb 03 '16 at 01:02