commit 3bcad94a823eb8abd197eaa8977a21180a163979
parent 07c66c917eb24bb7613d83c4de430e2b5fa763ae
Author: gstraube <gstraube@mailbox.org>
Date: Sat, 27 May 2017 17:27:53 +0200
Only display detected pitch if deviation is small enough
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/com/github/cythara/MainActivity.java b/app/src/main/java/com/github/cythara/MainActivity.java
@@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity {
private static final int SAMPLE_RATE = 44100;
private static final int BUFFER_SIZE = FastYin.DEFAULT_BUFFER_SIZE;
private static final int OVERLAP = FastYin.DEFAULT_OVERLAP;
+ private static final double MAX_DEVIATION = 50;
final Handler updateHandler = new UpdateHandler(this);
final PitchListener pitchListener = new PitchListener(this);
@@ -59,17 +60,21 @@ public class MainActivity extends AppCompatActivity {
if (pitch != -1) {
PitchDifference pitchDifference = PitchComparator.retrieveNote(pitch);
- String msg = String.format(Locale.US, "Closest: %s Diff: %f Freq: %f",
- pitchDifference.closest.getGuitarString(),
- pitchDifference.deviation, pitch);
+ String msg = "";
+
+ if (Math.abs(pitchDifference.deviation) < MAX_DEVIATION) {
+ msg = String.format(Locale.US, "Closest: %s Diff: %f Freq: %f",
+ pitchDifference.closest.getGuitarString(),
+ pitchDifference.deviation, pitch);
+ Log.d("com.github.cythara", msg);
+ }
Message message = new Message();
Bundle bundle = new Bundle();
bundle.putString("pitch", msg);
message.setData(bundle);
- activity.updateHandler.sendMessage(message);
- Log.d("com.github.cythara", msg);
+ activity.updateHandler.sendMessage(message);
}
}
};