On Wed, Dec 29, 2010 at 10:54 AM, Slash4 <[email protected]> wrote:
> First, my application is using a SCREEN_DIM_WAKE_LOCK so the screen is
> always on, yet the backlight and the keyboard are dimmed. Did you say
> in this case, the battery would not be consumed ?
>
Absolutely not. The CPU running flat-out takes a fair amount of power.
Especially since on most devices if you do this you will cause the kernel
to bring the CPU up to its full speed, since as far as it can tell it has
tons of work to do.
> So, about accuracy, the fastest callback that I can set is 60ms (a
> quarternote at 250 BPM tempo). I can afford a 10ms, lets say 15ms
> jitter, more and it will be noticeable at this tempo. Following this
> idea, I added a Thread.Sleep(10) since yesterday, to avoid too much
> iterations of my timing loop :
> while(isRunning){
>
> //Do stuff...
>
> try {
> Thread.sleep(10);
> } catch (InterruptedException e) {
>
> }
> }//End while
>
> Is it "better" for CPU or is it only cosmetic ?
>
I think you should be able to get 10ms accuracy with regular timers -- for
reference, a frame at 60fps is 20ms, and we regularly run times update loops
at 60fps.
Possibly a bigger issue you will run into is GCs, which prior to 2.3 can
take significantly more than 10ms and block all threads running in the
Dalvik VM while doing so. At the very least, you want to be extremely
careful in the rest of your app to avoid generating garbage objects while
running. You can tell if this is causing the problem because there will be
a log printed each time there is a GC.
> I didn't specified a priority on the Thread, so I suppose it's
> inherited from the parent's priority. What would be the best value for
> it in your opinion ?
>
Probably:
http://developer.android.com/reference/android/os/Process.html#THREAD_PRIORITY_AUDIO
But note if you use this -- you ABSOLUTELY CAN NOT use a busy-loop. Running
at this priority means that thread needs to use as little CPU as it can,
only what it needs to do the specific audio work.
--
Dianne Hackborn
Android framework engineer
[email protected]
Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en