units.cpp (2123B)
1 /** 2 * KFR (https://www.kfrlib.com) 3 * Copyright (C) 2016-2023 Dan Cazarin 4 * See LICENSE.txt for details 5 */ 6 7 #include <kfr/dsp/units.hpp> 8 9 namespace kfr 10 { 11 inline namespace CMT_ARCH_NAME 12 { 13 14 TEST(note_to_hertz) 15 { 16 testo::epsilon_scope<void> eps(2000); 17 CHECK(kfr::note_to_hertz(60) == fbase(261.6255653005986346778499935233)); 18 CHECK(kfr::note_to_hertz(pack(60)) == pack(fbase(261.6255653005986346778499935233))); 19 20 CHECK(kfr::note_to_hertz(69) == fbase(440.0)); 21 CHECK(kfr::note_to_hertz(pack(69)) == pack(fbase(440))); 22 } 23 24 TEST(hertz_to_note) 25 { 26 testo::epsilon_scope<void> eps(1000); 27 CHECK(kfr::hertz_to_note(261.6255653005986346778499935233) == fbase(60)); 28 CHECK(kfr::hertz_to_note(pack(261.6255653005986346778499935233)) == pack(fbase(60))); 29 30 CHECK(kfr::hertz_to_note(440) == fbase(69)); 31 CHECK(kfr::hertz_to_note(pack(440)) == pack(fbase(69))); 32 } 33 34 TEST(amp_to_dB) 35 { 36 testo::epsilon_scope<void> eps(1000); 37 38 CHECK(kfr::amp_to_dB(fbase(2.0)) == fbase(6.0205999132796239042747778944899)); 39 CHECK(kfr::amp_to_dB(fbase(-2.0)) == fbase(6.0205999132796239042747778944899)); 40 CHECK(kfr::amp_to_dB(fbase(1.0)) == fbase(0)); 41 CHECK(kfr::amp_to_dB(fbase(-1.0)) == fbase(0)); 42 CHECK(kfr::amp_to_dB(fbase(0.5)) == fbase(-6.0205999132796239042747778944899)); 43 CHECK(kfr::amp_to_dB(fbase(-0.5)) == fbase(-6.0205999132796239042747778944899)); 44 CHECK(kfr::amp_to_dB(fbase(0.0)) == fbase(-HUGE_VAL)); 45 } 46 47 TEST(dB_to_amp) 48 { 49 #if defined __clang__ && defined(CMT_ARCH_ARM) && __clang_major__ >= 13 50 // Clang 13+ compiler bug on ARM 51 #else 52 testo::epsilon_scope<void> eps(1000); 53 54 CHECK(kfr::exp(fbase(-HUGE_VAL)) == fbase(0.0)); 55 CHECK(kfr::exp2(fbase(-HUGE_VAL)) == fbase(0.0)); 56 CHECK(kfr::exp10(fbase(-HUGE_VAL)) == fbase(0.0)); 57 58 CHECK(kfr::dB_to_amp(fbase(-HUGE_VAL)) == fbase(0.0)); 59 CHECK(kfr::dB_to_amp(fbase(0.0)) == fbase(1.0)); 60 CHECK(kfr::dB_to_amp(fbase(6.0205999132796239042747778944899)) == fbase(2.0)); 61 CHECK(kfr::dB_to_amp(fbase(-6.0205999132796239042747778944899)) == fbase(0.5)); 62 #endif 63 } 64 65 } // namespace CMT_ARCH_NAME 66 } // namespace kfr