aboutsummaryrefslogtreecommitdiff
path: root/apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h')
-rw-r--r--apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h b/apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h
index 5814dccd..953cf49a 100644
--- a/apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h
+++ b/apps/OboeTester/app/src/main/cpp/analyzer/DataPathAnalyzer.h
@@ -41,6 +41,18 @@ public:
setNoiseAmplitude(0.02);
}
+ double calculatePhaseError(double p1, double p2) {
+ double diff = p1 - p2;
+ // Wrap around the circle.
+ while (diff > M_PI) {
+ diff -= (2 * M_PI);
+ }
+ while (diff < -M_PI) {
+ diff += (2 * M_PI);
+ }
+ return diff;
+ }
+
/**
* @param frameData contains microphone data with sine signal feedback
* @param channelCount
@@ -52,9 +64,8 @@ public:
mInfiniteRecording.write(sample);
if (transformSample(sample, mOutputPhase)) {
- resetAccumulator();
// Analyze magnitude and phase on every period.
- double diff = abs(mPhaseOffset - mPreviousPhaseOffset);
+ double diff = fabs(calculatePhaseError(mPhaseOffset, mPreviousPhaseOffset));
if (diff < mPhaseTolerance) {
mMaxMagnitude = std::max(mMagnitude, mMaxMagnitude);
}