0

I am making an application that does some audio processing and plays it back in real time. The issue I'm facing is that the application works just fine when the phone is connected to the computer with a USB cable, but the audio starts to skip and pop when the cable is disconnected. With the cable disconnected, if I switch on the screen then the application resume normal behavior, but again has problems as soon as the screen switches off.

To me this sounded like the CPU is going into a power-saving mode and stays awake when the USB cable is connected or the screen is on, so I tried to rectify this situation by acquiring a PARTIAL_WAKE_LOCK. However this did nothing to fix the situation.

Can someone tell me as to what the issue might be? I'm quite sure my wakelock code is ok. Is there a way for me to diagnose if the CPU is going to sleep?

Keeping the screen on is not an option for me.

private static PowerManager.WakeLock wakeLock;

public static void acquire(Context ctx) {
    Log.d(Utils.LOG_TAG, "Trying to acquire wakelock.");
    if (wakeLock != null) 
        wakeLock.release();

    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Wakelock");
    wakeLock.acquire(30 * 60 * 1000);
    Log.d(Utils.LOG_TAG, "Partial wakelock acquired.");
}

public static void release() {
    if (wakeLock != null) { 
        wakeLock.release(); 
        Log.d(Utils.LOG_TAG, "Wakelock released.");
    } else
        Log.d(Utils.LOG_TAG, "No wakelock to release.");

    wakeLock = null;
}

public static boolean getStatus() {
    if (wakeLock == null)
        return false;
    else
        return true;
}
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Anuj Jain
  • 315
  • 1
  • 15

0 Answers0