| 13 | #include "test.h" |
| 14 | |
| 15 | FL_TEST_FILE(FL_FILEPATH) { |
| 16 | |
| 17 | using namespace fl; |
| 18 | using namespace fl::test; |
| 19 | |
| 20 | FL_TEST_CASE("audio::Reactive basic functionality") { |
| 21 | // Test basic initialization |
| 22 | audio::Reactive audio; |
| 23 | audio::ReactiveConfig config; |
| 24 | config.sampleRate = 22050; |
| 25 | config.gain = 128; |
| 26 | // AGC removed — gain is now controlled via Processor::setGain() |
| 27 | |
| 28 | audio.begin(config); |
| 29 | |
| 30 | // Check initial state |
| 31 | const audio::Data& data = audio.getData(); |
| 32 | FL_CHECK(data.volume == 0.0f); |
| 33 | FL_CHECK(data.volumeRaw == 0.0f); |
| 34 | FL_CHECK_FALSE(data.beatDetected); |
| 35 | |
| 36 | // Test adding samples - Create audio::Sample and add it |
| 37 | // Reduced from 1000 to 500 samples for performance (still provides excellent coverage) |
| 38 | fl::vector<int16_t> samples; |
| 39 | samples.reserve(500); |
| 40 | |
| 41 | for (int i = 0; i < 500; ++i) { |
| 42 | // Generate a simple sine wave sample |
| 43 | float phase = 2.0f * FL_M_PI * 1000.0f * i / 22050.0f; // 1kHz |
| 44 | int16_t sample = static_cast<int16_t>(8000.0f * fl::sinf(phase)); |
| 45 | samples.push_back(sample); |
| 46 | } |
| 47 | |
| 48 | // Create audio::Sample from our generated samples with timestamp |
| 49 | audio::SampleImplPtr impl = fl::make_shared<audio::SampleImpl>(); |
| 50 | uint32_t testTimestamp = 1234567; // Test timestamp value |
| 51 | impl->assign(samples.begin(), samples.end(), testTimestamp); |
| 52 | audio::Sample audioSample(impl); |
| 53 | |
| 54 | // Process the audio sample directly (timestamp comes from audio::Sample) |
| 55 | audio.processSample(audioSample); |
| 56 | |
| 57 | // Check that we detected some audio |
| 58 | const audio::Data& processedData = audio.getData(); |
| 59 | FL_CHECK(processedData.volume > 0.0f); |
| 60 | FL_CHECK_LE(processedData.volume, 1.0f); |
| 61 | FL_CHECK_LE(processedData.volumeRaw, 1.0f); |
| 62 | FL_CHECK_LE(processedData.peak, 1.0f); |
| 63 | |
| 64 | // Verify that the timestamp was properly captured from the audio::Sample |
| 65 | FL_CHECK(processedData.timestamp == testTimestamp); |
| 66 | |
| 67 | // Verify that the audio::Sample correctly stores and returns its timestamp |
| 68 | FL_CHECK(audioSample.timestamp() == testTimestamp); |
| 69 | } |
| 70 | |
| 71 | FL_TEST_CASE("audio::Reactive convenience functions") { |
| 72 | audio::Reactive audio; |
nothing calls this directly
no test coverage detected