Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: Audio buffer underruns with 10.9.9.339


smcveigh wrote:

not sure what the hard limit is.  some of the highest-priority threads in the system are part of the io-audio driver (most are 50, and at least one interrupt thread is 51).

definitely would be interesting to see code that works ok on playbook but not a dev alpha (which has a better cpu).

Cheers,

Sean


It looks like setting the thread priority for the tone generation thread to 52 solves the problem.  Wonder why a priority of 50 works on the PlayBook.

Sucroid.com
Sweet Apps for the Fans
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Audio buffer underruns with 10.9.9.339

[ Edited ]

playbook audio drivers are probably running at a different priority.

when you have the time, I'd still like to run your problematic code (or an equivalently cpu-intensive generator) by the audio guys :smileyhappy:

I would hate to see your app stop working reliably if someone bumps the audio driver priority up in the future.

 

Cheers,

Sean

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

I've been investigating a similar issue with White Noise, which also generates its audio on-the-fly. I use a 2s buffer, or 120 fragments, when the app is not fullscreen.

I actually thought I was getting underruns, but adding some logging suggests that's not actually the case. Maybe what I'm seeing will shed some light on things in this case, or maybe it's something else.

Basically when the app is running, which is often at night with bedside mode engaged in the clock app (or from the lock screen), every so often I'd get a very brief glitch, a dropout in the sound on the order of 50ms or so (just guessing at that, but it's surely less than 200ms and more than 10ms).

After starting to experiment with thread priorities, first at 20 (default is 10) then 30, then 40, I happened to be monitoring it with the clock app running, with its active frame showing. The glitch is synchronized with the active frame updating as the minute hand ticks forward.

It happens only maybe one time in 5 or 10, so it takes a while to observe it. It's always synchronized to the 60-second rollover of the system clock, however. Not sure yet if it happens only with the clock app or bedside mode actually running.

I'm now at priority = 50 and no sign of the glitch in the last 20 minutes or so. Not conclusive but I'll post more later, or likely start a new thread since I don't seem to be having actual underruns. Something's interfering with the interrupt processing, I think.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

I'm testing on a Z10, by the way.

Another item to note: at first I thought this was probably linked to incoming messages or network activity, so I've tested with Airplane mode on and it had no effect: the glitches still occurred.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: Audio buffer underruns with 10.9.9.339

This seems to indicate that a bunch of (system?) threads are scheduled to wake up at a set interval all at once.  Hmm.

Sucroid.com
Sweet Apps for the Fans
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

Update: tested White Noise for hours last night, and over at least two hours during which I was awake and aware of it I didn't hear a single glitch.

This was only after I bumped it to the maximum priority, of 63. I had it at 52 for awhile and it wasn't long before I heard one of the glitches.

This isn't conclusive, and I don't want to or plan to leave it this way, but I think it's strong evidence of something worth investigating.

I'll try to narrow things down a bit more. Maybe 53 would be sufficient, or at least something less than 63.

Unfortunately, I have little choice but to submit an update to the app soon, with some sort of fix, so if using 63 is the best I can do then for now that's what I'll have to do. Fortunately, my app is extremely well behaved (you get that when many days of hard design and experimentation are involved), and there's no noticeable side effects of my using 63 in this one thread, aside from the glitch going away.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

I should probably face the fact that the issue may well be in my code, however. Something's not adding up with this.

Given that my code is apparently sitting in a select() statement most of the time, waiting for space to buffer more data, and given that I see no sign of underruns being reported and I have 120 frags (2s) of data buffered, it seems incredible that a change in my own thread's priority would be affecting anything here.

On the other hand, why would a boost in my own thread's priority have an effect on another part of the system, if it's something outside that thread which is causing this?

Now also tested at 58 (glitched) and 61 (no glitches so far). If someone at BlackBerry is seeing this converging on the priority level of some super-secret internal thing that happens every one minute, on the minute, feel free to jump in here. ;-)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

Final update for this thread, before I start a new one. Have now confirmed that the glitch still occurs with my audio-generation thread at priority 60, but not when it's at 61.

It's remarkably easy to reproduce at this point. All I have to do is run the clock app, and select Bedside Mode from its top menu. If it's going to glitch, it will happen in the next few minutes as the second hand moves to the 12. The problem is not eliminated by having the screen off, though it may be less frequent then.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Device: PlayBook

Re: Audio buffer underruns with 10.9.9.339

Seems to me it wouldn't be a bad idea to file a bug report for your glitch.

Sucroid.com
Sweet Apps for the Fans
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Audio buffer underruns with 10.9.9.339

Oh, I will. I've just found that without detailed study, and clear steps for reproducing a problem, the reports will typically sit for months before there's any real sign of activity. Or there's a request for a test case.

Either way, there's a bit more legwork for me to finish before I submit one, if just to make sure I've eliminated "dumb programmer" as the cause. :-)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!