Mercurial > hg > svcore
diff base/test/TestPitch.h @ 1025:88b54a185a0a
Use double instead of float for frequencies in Pitch, just for confidence
author | Chris Cannam |
---|---|
date | Mon, 08 Dec 2014 15:37:12 +0000 |
parents | 451f7f3ab6e7 |
children | bbc4e4ee15d5 |
line wrap: on
line diff
--- a/base/test/TestPitch.h Tue Dec 02 17:53:17 2014 +0000 +++ b/base/test/TestPitch.h Mon Dec 08 15:37:12 2014 +0000 @@ -72,18 +72,29 @@ QCOMPARE(Pitch::getPitchLabelForFrequency(261.63, 440, false), QString("C4")); } -#define MIDDLE_C 261.6255653f +#define MIDDLE_C 261.6255653005986 void frequencyForPitch() { QCOMPARE(Pitch::getFrequencyForPitch(60, 0), MIDDLE_C); - QCOMPARE(Pitch::getFrequencyForPitch(69, 0), 440.f); - QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.f); - QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.f); + QCOMPARE(Pitch::getFrequencyForPitch(69, 0), 440.0); + QCOMPARE(Pitch::getFrequencyForPitch(60, 0, 220), MIDDLE_C / 2.0); + QCOMPARE(Pitch::getFrequencyForPitch(69, 0, 220), 220.0); } void pitchForFrequency() { + double centsOffset = 0.0; + QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); + QCOMPARE(centsOffset, 0.0); + QCOMPARE(Pitch::getPitchForFrequency(261.0, ¢sOffset), 60); + QCOMPARE(int(centsOffset), -4); + QCOMPARE(Pitch::getPitchForFrequency(440.0, ¢sOffset), 69); + QCOMPARE(centsOffset, 0.0); + } + + void pitchForFrequencyF() + { float centsOffset = 0.f; QCOMPARE(Pitch::getPitchForFrequency(MIDDLE_C, ¢sOffset), 60); QCOMPARE(centsOffset, 0.f);