summaryrefslogtreecommitdiff
path: root/src/tests/test_wav_dump.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_wav_dump.cc')
-rw-r--r--src/tests/test_wav_dump.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tests/test_wav_dump.cc b/src/tests/test_wav_dump.cc
index cc2de19..aa195cc 100644
--- a/src/tests/test_wav_dump.cc
+++ b/src/tests/test_wav_dump.cc
@@ -190,6 +190,54 @@ void test_wav_stereo_buffer_size() {
printf(" āœ“ Buffer size calculations correct for stereo\n");
}
+void test_clipping_detection() {
+ printf("Test: Clipping detection and reporting...\n");
+
+ const char* test_file = "test_clipping.wav";
+
+ audio_init();
+ AudioEngine engine;
+ engine.init();
+
+ WavDumpBackend wav_backend;
+ wav_backend.set_output_file(test_file);
+ wav_backend.init();
+ wav_backend.start();
+
+ // Create test samples with intentional clipping
+ const int num_samples = 1000;
+ float test_samples[1000];
+
+ // Mix of normal and clipped samples
+ for (int i = 0; i < num_samples; ++i) {
+ if (i % 10 == 0) {
+ test_samples[i] = 1.5f; // Clipped high
+ } else if (i % 10 == 1) {
+ test_samples[i] = -1.2f; // Clipped low
+ } else {
+ test_samples[i] = 0.5f; // Normal
+ }
+ }
+
+ // Write samples
+ wav_backend.write_audio(test_samples, num_samples);
+
+ // Verify clipping was detected (20% of samples should be clipped)
+ const size_t clipped = wav_backend.get_clipped_samples();
+ assert(clipped == 200); // 10% + 10% = 20% of 1000
+
+ printf(" Detected %zu clipped samples (expected 200)\n", clipped);
+
+ wav_backend.shutdown();
+ engine.shutdown();
+ audio_shutdown();
+
+ // Clean up
+ remove(test_file);
+
+ printf(" āœ“ Clipping detection works correctly\n");
+}
+
#endif /* !defined(STRIP_ALL) */
int main() {
@@ -197,6 +245,7 @@ int main() {
printf("Running WAV Dump Backend tests...\n\n");
test_wav_format_matches_live_audio();
test_wav_stereo_buffer_size();
+ test_clipping_detection();
printf("\nāœ… All WAV Dump tests PASSED\n");
return 0;
#else