| 7 | #include "fl/math/math.h" |
| 8 | |
| 9 | FL_TEST_FILE(FL_FILEPATH) { |
| 10 | |
| 11 | using namespace fl; |
| 12 | |
| 13 | FL_TEST_CASE("audio::SoundLevelMeter - silence gives very negative dBFS") { |
| 14 | audio::SoundLevelMeter meter; |
| 15 | fl::vector<fl::i16> silence(512, 0); |
| 16 | meter.processBlock(silence.data(), silence.size()); |
| 17 | // Silence should give -infinity or very negative dBFS |
| 18 | FL_CHECK_LT(meter.getDBFS(), -60.0); |
| 19 | } |
| 20 | |
| 21 | FL_TEST_CASE("audio::SoundLevelMeter - full scale signal near 0 dBFS") { |
| 22 | audio::SoundLevelMeter meter; |
| 23 | // Full-scale square wave (alternating ±32767) |
| 24 | fl::vector<fl::i16> fullScale; |
| 25 | fullScale.reserve(512); |
| 26 | for (int i = 0; i < 512; ++i) { |
| 27 | fullScale.push_back(static_cast<fl::i16>((i % 2 == 0) ? 32767 : -32767)); |
| 28 | } |
| 29 | meter.processBlock(fullScale.data(), fullScale.size()); |
| 30 | // Full scale should be near 0 dBFS |
| 31 | FL_CHECK_GT(meter.getDBFS(), -3.0); |
| 32 | } |
| 33 | |
| 34 | FL_TEST_CASE("audio::SoundLevelMeter - SPL calibration") { |
| 35 | audio::SoundLevelMeter meter(33.0, 0.0); |
| 36 | // Process a quiet signal to establish floor |
| 37 | fl::vector<fl::i16> quiet(512, 100); |
| 38 | meter.processBlock(quiet.data(), quiet.size()); |
| 39 | double spl = meter.getSPL(); |
| 40 | // SPL should be a reasonable value |
| 41 | FL_CHECK_GT(spl, 0.0); |
| 42 | } |
| 43 | |
| 44 | FL_TEST_CASE("audio::SoundLevelMeter - resetFloor clears state") { |
| 45 | audio::SoundLevelMeter meter; |
| 46 | fl::vector<fl::i16> signal; |
| 47 | signal.reserve(512); |
| 48 | for (int i = 0; i < 512; ++i) { |
| 49 | signal.push_back(static_cast<fl::i16>(5000 * ((i % 2 == 0) ? 1 : -1))); |
| 50 | } |
| 51 | meter.processBlock(signal.data(), signal.size()); |
| 52 | double spl1 = meter.getSPL(); |
| 53 | meter.resetFloor(); |
| 54 | meter.processBlock(signal.data(), signal.size()); |
| 55 | double spl2 = meter.getSPL(); |
| 56 | // Both should be valid numbers |
| 57 | FL_CHECK_GT(spl1, 0.0); |
| 58 | FL_CHECK_GT(spl2, 0.0); |
| 59 | } |
| 60 | |
| 61 | FL_TEST_CASE("audio::SoundLevelMeter - setFloorSPL changes calibration") { |
| 62 | audio::SoundLevelMeter meter(33.0, 0.0); |
| 63 | fl::vector<fl::i16> signal; |
| 64 | signal.reserve(512); |
| 65 | for (int i = 0; i < 512; ++i) { |
| 66 | signal.push_back(static_cast<fl::i16>(3000 * ((i % 2 == 0) ? 1 : -1))); |
nothing calls this directly
no test coverage detected