aaudio: fix IsochronousClockModel drift calculation

Correct an error that caused the timing window to jump
forward in time by one burst when a late timestamp was detected.

Bug: 133513175
Bug: 122680738
Bug: 123643363
Test: aaudio_loopback -tm -s20
Change-Id: I65c05d2ab123bcd347cb900de055c49c0c9beada
diff --git a/media/libaaudio/src/client/IsochronousClockModel.cpp b/media/libaaudio/src/client/IsochronousClockModel.cpp
index 747d0e1..d26b352 100644
--- a/media/libaaudio/src/client/IsochronousClockModel.cpp
+++ b/media/libaaudio/src/client/IsochronousClockModel.cpp
@@ -108,17 +108,24 @@
     case STATE_RUNNING:
         if (nanosDelta < expectedNanosDelta) {
             // Earlier than expected timestamp.
-            // This data is probably more accurate so use it.
-            // or we may be drifting due to a slow HW clock.
-//            ALOGD("processTimestamp() - STATE_RUNNING - %d < %d micros - EARLY",
-//                 (int) (nanosDelta / 1000), (int)(expectedNanosDelta / 1000));
+            // This data is probably more accurate, so use it.
+            // Or we may be drifting due to a fast HW clock.
+//            int microsDelta = (int) (nanosDelta / 1000);
+//            int expectedMicrosDelta = (int) (expectedNanosDelta / 1000);
+//            ALOGD("processTimestamp() - STATE_RUNNING - %7d < %7d so %4d micros EARLY",
+//                 microsDelta, expectedMicrosDelta, (expectedMicrosDelta - microsDelta));
+
             setPositionAndTime(framePosition, nanoTime);
         } else if (nanosDelta > (expectedNanosDelta + mMaxLatenessInNanos)) {
             // Later than expected timestamp.
-//            ALOGD("processTimestamp() - STATE_RUNNING - %d > %d + %d micros - LATE",
-//                 (int) (nanosDelta / 1000), (int)(expectedNanosDelta / 1000),
-//                 (int) (mMaxLatenessInNanos / 1000));
-            setPositionAndTime(framePosition - mFramesPerBurst,  nanoTime - mMaxLatenessInNanos);
+//            int microsDelta = (int) (nanosDelta / 1000);
+//            int expectedMicrosDeadline = (int) ((expectedNanosDelta + mMaxLatenessInNanos) / 1000);
+//            ALOGD("processTimestamp() - STATE_RUNNING - %7d > %7d so %4d micros LATE",
+//                  microsDelta, expectedMicrosDeadline, (microsDelta - expectedMicrosDeadline));
+
+            // When we are late it may be because of preemption in the kernel or
+            //  we may be drifting due to a slow HW clock.
+            setPositionAndTime(framePosition,  nanoTime - mMaxLatenessInNanos);
         }
         break;
     default: