surge-synthesizer / tuning-library

Micro-tuning format parsing and frequency finding as a header-only C+ library
https://surge-synth-team.org/tuning-library/
MIT License
83 stars 15 forks source link

Is the pitch correct if scale starts from D? #65

Closed KKQ-KKQ closed 10 months ago

KKQ-KKQ commented 10 months ago

If KeyboardMapping is not starts from C, the pitch seems to be incorrect.

The following test case is failed. Am I wrong?

TEST_CASE("Scale shift")
{
    SECTION("Scale starts from D")
    {
        auto s = Tunings::readSCLFile(testFile("12-shuffled.scl"));
        auto shift = 2;
        Tunings::Tuning t(s, Tunings::startScaleOnAndTuneNoteTo(60 + shift, 69, 440.));
        REQUIRE(s.count == 12);
        REQUIRE(t.frequencyForMidiNote(60 + shift) / 440. == Approx(exp2(shift/12.0)).margin(1e-6));

        std::vector<int> order = {{0, 2, 1, 3, 5, 4, 6, 7, 8, 10, 9, 11, 12}};
        auto l60s = t.logScaledFrequencyForMidiNote(60 + shift);
        for (size_t i = 0; i < order.size(); ++i)
        {
            auto li = t.logScaledFrequencyForMidiNote(60 + shift + i);
            auto oi = order[i];
            REQUIRE(li - l60s == Approx(oi / 12.0).margin(1e-6));
        }
    }
}
KKQ-KKQ commented 10 months ago

Oh I was wrong. It is not an issue.

Tunings::startScaleOnAndTuneNoteTo(60 + shift, 69, 440.) means A4 == 440Hz.