Skip to content

Commit

Permalink
Add comments to explain the the phase offset usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
philburk committed Mar 12, 2024
1 parent 83803e5 commit 570c661
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions apps/OboeTester/app/src/main/cpp/analyzer/BaseSineAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,16 @@ class BaseSineAnalyzer : public LoopbackProcessor {
double mPhaseIncrement = 0.0;
double mOutputPhase = 0.0;
double mOutputAmplitude = 0.75;
// This is the phase offset between the output sine wave and the recorded
// signal at the tuned frequency.
// If this jumps around then we are probably just hearing noise.
// Noise can cause the magnitude to be high but mPhaseOffset will be pretty random.
// If we are tracking a sine wave then mPhaseOffset should be consistent.
double mPhaseOffset = 0.0;
// kPhaseInvalid indicates that the phase measurement cannot be used.
// We were seeing times when a magnitude of zero was causing atan2(s,c) to
// return a phase of zero, which looked valid to Java. This is a way of passing
// an error code back to Java as a single value to avoid race conditions.
static constexpr double kPhaseInvalid = -999.0;
double mMagnitude = 0.0;
static constexpr double kMinValidMagnitude = 2.0 / (1 << 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private void init() {
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mCurrentWidth = w;
mCurrentHeight = h;
mOffsetY = 0.5f * h;
mOffsetY = 0.5f * h; // Center waveform vertically in the viewport.
// Scale down so that we can see the top of the waveforms if they are clipped.
mScaleY = 0.95f * (0.0f - mOffsetY);
mScaleY = -0.95f * mOffsetY; // Negate so positive values are on top.
}

public String getMessage() {
Expand Down Expand Up @@ -122,8 +122,8 @@ protected void onDraw(Canvas canvas) {
float x0 = 0.0f;
if (xScale < 1.0) {
// Draw a vertical bar for multiple samples.
float ymin = mOffsetY;
float ymax = mOffsetY;
float ymin = mOffsetY; // vertical center
float ymax = mOffsetY; // vertical center
for (int i = 0; i < mSampleCount; i++) {
float x1 = i * xScale;
if ((int) x0 != (int) x1) {
Expand Down

0 comments on commit 570c661

Please sign in to comment.