commit 908f8c6475543d4a2064ef35155ccfd1172a500a
parent ce4c855d7e4f51d7d9220abe7ff2fc8488294ee9
Author: gstraube <gstraube@mailbox.org>
Date: Mon, 17 Jul 2017 17:29:44 +0200
Invert signs of pitch deviations
If the detected pitch is lower than the reference pitch, the deviation shall be negative. Otherwise, it shall be positive.
Diffstat:
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/com/github/cythara/PitchComparator.java b/app/src/main/java/com/github/cythara/PitchComparator.java
@@ -17,7 +17,7 @@ class PitchComparator {
double minCentDifference = Float.POSITIVE_INFINITY;
Note closest = Note.E4;
for (Note note : notes) {
- double centDifference = 1200d * log2(note.getFrequency() / pitch);
+ double centDifference = 1200d * log2(pitch / note.getFrequency());
if (Math.abs(centDifference) < Math.abs(minCentDifference)) {
minCentDifference = centDifference;
diff --git a/app/src/test/java/com/github/cythara/PitchComparatorTest.java b/app/src/test/java/com/github/cythara/PitchComparatorTest.java
@@ -15,10 +15,10 @@ public class PitchComparatorTest {
@Test
public void retrieveNote() throws Exception {
Map<Float, PitchDifference> expectations = new HashMap<>();
- expectations.put(20f, new PitchDifference(E2, 2451.3832933619105));
- expectations.put(500f, new PitchDifference(E4, -721.296654095616));
- expectations.put(197.67f, new PitchDifference(G3, -14.688333908767358));
- expectations.put(128.415f, new PitchDifference(D3, 231.99964198777823));
+ expectations.put(20f, new PitchDifference(E2, -2451.3832933619105));
+ expectations.put(500f, new PitchDifference(E4, 721.296654095616));
+ expectations.put(197.67f, new PitchDifference(G3, 14.688333908767358));
+ expectations.put(128.415f, new PitchDifference(D3, -231.99964198777823));
for (Float pitch : expectations.keySet()) {
PitchDifference actual = PitchComparator.retrieveNote(pitch);