# HG changeset patch # User Chris Cannam # Date 1559221833 -3600 # Node ID dd132354ea027e83d93be615f2d979fd4b20ea35 # Parent 8d84e5d16314f256e94aaab5a1c69bff2dc6b5f5 Expand tests a bit, make them fail if they fail diff -r 8d84e5d16314 -r dd132354ea02 tests/TestChromagram.cpp --- a/tests/TestChromagram.cpp Thu May 30 14:10:15 2019 +0100 +++ b/tests/TestChromagram.cpp Thu May 30 14:10:33 2019 +0100 @@ -45,41 +45,43 @@ return concertA * pow(2.0, (midiPitch - 69.0) / 12.0); } -BOOST_AUTO_TEST_CASE(sinusoid_12tET) +void test_sinusoid_12tET(double concertA, double sampleRate, int bpo) { - double concertA = 440.0; - double sampleRate = 44100.0; - int bpo = 60; + int chromaMinPitch = 36; + int chromaMaxPitch = 108; + int probeMinPitch = 36; + int probeMaxPitch = 108; + ChromaConfig config { sampleRate, - frequencyForPitch(36, concertA), - frequencyForPitch(108, concertA), + frequencyForPitch(chromaMinPitch, concertA), + frequencyForPitch(chromaMaxPitch, concertA), bpo, 0.0054, MathUtilities::NormaliseNone }; Chromagram chroma(config); + + int binsPerSemi = bpo / 12; - for (int midiPitch = 36; midiPitch < 108; ++midiPitch) { - - cout << endl; + for (int midiPitch = probeMinPitch; + midiPitch < probeMaxPitch; + ++midiPitch) { int blockSize = chroma.getFrameSize(); - int hopSize = chroma.getHopSize(); - cerr << "blockSize = " << blockSize - << ", hopSize = " << hopSize << endl; double frequency = frequencyForPitch(midiPitch, concertA); - int expectedPeakBin = ((midiPitch - 36) * 5) % bpo; - + int expectedPeakBin = + ((midiPitch - chromaMinPitch) * binsPerSemi) % bpo; +/* cout << "midiPitch = " << midiPitch << ", name = " << midiPitchName(midiPitch) << ", frequency = " << frequency << ", expected peak bin = " << expectedPeakBin << endl; - +*/ vector signal = generateSinusoid(frequency, sampleRate, blockSize); @@ -95,14 +97,13 @@ peakBin = i; } } - +/* cout << "peak value = " << peakValue << " at bin " << peakBin << endl; cout << "(neighbouring values are " << (peakBin > 0 ? output[peakBin-1] : output[bpo-1]) << " and " << (peakBin+1 < bpo ? output[peakBin+1] : output[0]) << ")" << endl; - if (peakBin != expectedPeakBin) { cout << "NOTE: peak bin " << peakBin << " does not match expected " << expectedPeakBin << endl; cout << "bin values are: "; @@ -111,7 +112,30 @@ } cout << endl; } +*/ + + BOOST_CHECK_EQUAL(peakBin, expectedPeakBin); } } +BOOST_AUTO_TEST_CASE(sinusoid_12tET_440_44100_36) +{ + test_sinusoid_12tET(440.0, 44100.0, 36); +} + +BOOST_AUTO_TEST_CASE(sinusoid_12tET_440_44100_60) +{ + test_sinusoid_12tET(440.0, 44100.0, 60); +} + +BOOST_AUTO_TEST_CASE(sinusoid_12tET_397_44100_60) +{ + test_sinusoid_12tET(397.0, 44100.0, 60); +} + +BOOST_AUTO_TEST_CASE(sinusoid_12tET_440_48000_60) +{ + test_sinusoid_12tET(440.0, 48000.0, 60); +} + BOOST_AUTO_TEST_SUITE_END() diff -r 8d84e5d16314 -r dd132354ea02 tests/TestGetKeyMode.cpp --- a/tests/TestGetKeyMode.cpp Thu May 30 14:10:15 2019 +0100 +++ b/tests/TestGetKeyMode.cpp Thu May 30 14:10:33 2019 +0100 @@ -70,19 +70,16 @@ for (int midiPitch = 48; midiPitch < 96; ++midiPitch) { - cout << endl; - GetKeyMode gkm(sampleRate, concertA, 10, 10); int blockSize = gkm.getBlockSize(); int hopSize = gkm.getHopSize(); - cerr << "blockSize = " << blockSize - << ", hopSize = " << hopSize << endl; double frequency = concertA * pow(2.0, (midiPitch - 69.0) / 12.0); +/* cout << "midiPitch = " << midiPitch << ", name = " << midiPitchName(midiPitch) << ", frequency = " << frequency << endl; - +*/ int blocks = 4; int totalLength = blockSize * blocks; vector signal = generateSinusoid(frequency, sampleRate, @@ -105,8 +102,10 @@ int tonic = key; if (minor) tonic -= 12; - string name = keyName(tonic, minor); - cout << "key value = " << key << ", name = " << name << endl; + BOOST_CHECK_EQUAL(tonic, 1 + (midiPitch % 12)); + +// string name = keyName(tonic, minor); +// cout << "key value = " << key << ", name = " << name << endl; } }