7

I have a requirement for perfect gapless looped audio in a BlackBerry 10 app. My loops are stored as WAV files. The method I'm using for playing them is:

  1. Create a buffer for the WAV file using alutCreateBufferFromFile which returns a bufferID
  2. Create a sound source using alGenSources
  3. Attach the buffer to the source using alSourcei(source, AL_BUFFER, bufferID)
  4. Set the source looping property to true using alSourcei(source, AL_LOOPING, AL_TRUE)
  5. Play the source using alSourcePlay(source)

The audio plays fine most of the time, but during UI transitions (such as when the backlight goes off, or when the app is minimised) the audio stutters.

Any ideas how I can ensure the audio is smooth the whole time?

donturner
  • 17,867
  • 8
  • 59
  • 81

1 Answers1

3

How do you run a thread/process playing WAV file? Have you had a chance to play around priorities and policies with that thread?

I think these low-level system calls allowing to change process (thread, actually) priority and policy might help:

Also, have a look at respective doc pages:

I'd start with setting policy to FIFO and raise priority of the process playing audio file. Hope it helps.

Sunseeker
  • 1,503
  • 9
  • 21
  • Thanks, those are some handy hints. When I call `alSourcePlay` it spawns a separate thread to do the playing. How can I change the priority of that thread, rather than my main thread? – donturner Jul 08 '13 at 17:10
  • I've set the scheduling policy of my main thread to FIFO and upped the thread priority to 63 (the highest permissible for non-root apps) my theory being that the child process which plays the audio will inherit those properties. Unfortunately the stuttering still occurs. Any suggestions? – donturner Jul 08 '13 at 20:54
  • OK, I figured it out. The thread priority must be set prior to initialising anything to do with OpenAL, then it works like a charm. Thanks very much! – donturner Jul 08 '13 at 21:02