summaryrefslogtreecommitdiff
path: root/src/tests/test_window.cpp
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-27 22:16:23 +0100
committerskal <pascal.massimino@gmail.com>2026-01-27 22:16:23 +0100
commitad4f87e0ebfd361c69c7ba9adc29292305f21f7c (patch)
tree7e3d4feffce3cac26139df1ace2f879e62bfc00c /src/tests/test_window.cpp
parent2f68b86ba403fdae97c00569b6bb9b58ad1f33a6 (diff)
feat(audio): Implement real-time spectrogram synthesizer
Adds a multi-voice, real-time audio synthesis engine that generates sound from spectrogram data using an Inverse Discrete Cosine Transform (IDCT). Key features: - A thread-safe, double-buffered system for dynamically updating spectrograms in real-time without interrupting audio playback. - Core DSP components: FDCT, IDCT, and Hamming window functions. - A simple sequencer in the main loop to demonstrate scripted audio events and dynamic updates. - Unit tests for the new synth engine and Hamming window, integrated with CTest. - A file documenting the build process, features, and how to run tests.
Diffstat (limited to 'src/tests/test_window.cpp')
-rw-r--r--src/tests/test_window.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/tests/test_window.cpp b/src/tests/test_window.cpp
new file mode 100644
index 0000000..1667dab
--- /dev/null
+++ b/src/tests/test_window.cpp
@@ -0,0 +1,34 @@
+#include "audio/window.h"
+#include <stdio.h>
+#include <math.h>
+#include <assert.h>
+
+// A simple floating point comparison with a tolerance
+bool is_close(float a, float b, float epsilon = 1e-6f) {
+ return fabsf(a - b) < epsilon;
+}
+
+int main() {
+ float window[WINDOW_SIZE];
+ hamming_window_512(window);
+
+ // Test 1: Window should start and end at the same small value
+ assert(is_close(window[0], 0.08f));
+ assert(is_close(window[WINDOW_SIZE - 1], 0.08f));
+ printf("Test 1 passed: Window start and end values are correct.\n");
+
+ // Test 2: Window should be symmetric
+ for (int i = 0; i < WINDOW_SIZE / 2; ++i) {
+ assert(is_close(window[i], window[WINDOW_SIZE - 1 - i]));
+ }
+ printf("Test 2 passed: Window is symmetric.\n");
+
+ // Test 3: The two middle points of the even-sized window should be equal and the peak.
+ assert(is_close(window[WINDOW_SIZE / 2 - 1], window[WINDOW_SIZE / 2]));
+ assert(window[WINDOW_SIZE / 2] > window[WINDOW_SIZE / 2 - 2]); // Should be greater than neighbors
+ printf("Test 3 passed: Window peak is correct for even size.\n");
+
+ printf("All tests passed for Hamming window!\n");
+
+ return 0;
+}