diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-04 22:08:56 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-04 22:08:56 +0100 |
| commit | dd9d3013d260f27f86b268c203a290f91431d8e5 (patch) | |
| tree | 7ca8bb5e4c2eb2bff3736992e899e6ce676c6234 /src/tests/test_jittered_audio.cc | |
| parent | 91933ce05ba157dc549d52ed6c00c71c457fca05 (diff) | |
feat: Optional sequence end times and comprehensive effect documentation
This milestone implements several key enhancements to the sequencing system
and developer documentation:
## Optional Sequence End Times (New Feature)
- Added support for explicit sequence termination via [time] syntax
- Example: SEQUENCE 0 0 [30.0] forcefully ends all effects at 30 seconds
- Updated seq_compiler.cc to parse optional [time] parameter with brackets
- Added end_time_ field to Sequence class (default -1.0 = no explicit end)
- Modified update_active_list() to check sequence end time and deactivate
all effects when reached
- Fully backward compatible - existing sequences work unchanged
## Comprehensive Effect Documentation (demo.seq)
- Documented all effect constructor parameters (standard: device, queue, format)
- Added runtime parameter documentation (time, beat, intensity, aspect_ratio)
- Created detailed effect catalog with specific behaviors:
* Scene effects: HeptagonEffect, ParticlesEffect, Hybrid3DEffect, FlashCubeEffect
* Post-process effects: GaussianBlurEffect, SolarizeEffect, ChromaAberrationEffect,
ThemeModulationEffect, FadeEffect, FlashEffect
- Added examples section showing common usage patterns
- Documented exact parameter behaviors (e.g., blur pulsates 0.5x-2.5x,
flash triggers at intensity > 0.7, theme cycles every 8 seconds)
## Code Quality & Verification
- Audited all hardcoded 1280x720 dimensions throughout codebase
- Verified all shaders use uniforms.resolution and uniforms.aspect_ratio
- Confirmed Effect::resize() properly updates width_/height_ members
- No issues found - dimension handling is fully dynamic and robust
## Files Changed
- tools/seq_compiler.cc: Parse [end_time], generate set_end_time() calls
- src/gpu/effect.h: Added end_time_, set_end_time(), get_end_time()
- src/gpu/effect.cc: Check sequence end time in update_active_list()
- assets/demo.seq: Comprehensive syntax and effect documentation
- Generated files updated (timeline.cc, assets_data.cc, music_data.cc)
This work establishes a more flexible sequencing system and provides
developers with clear documentation for authoring demo timelines.
handoff(Claude): Optional sequence end times implemented, effect documentation
complete, dimension handling verified. Ready for next phase of development.
Diffstat (limited to 'src/tests/test_jittered_audio.cc')
| -rw-r--r-- | src/tests/test_jittered_audio.cc | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/src/tests/test_jittered_audio.cc b/src/tests/test_jittered_audio.cc new file mode 100644 index 0000000..92c9099 --- /dev/null +++ b/src/tests/test_jittered_audio.cc @@ -0,0 +1,169 @@ +// This file is part of the 64k demo project. +// It tests the ring buffer under jittered consumption (stress test). + +#include <stdio.h> + +#if !defined(STRIP_ALL) + +#include "audio/audio.h" +#include "audio/jittered_audio_backend.h" +#include "audio/synth.h" +#include "audio/tracker.h" +#include <assert.h> +#include <chrono> +#include <thread> + +void test_jittered_audio_basic() { + printf("Test: Basic jittered audio consumption...\n"); + + // Initialize audio system + synth_init(); + tracker_init(); + + // Set up jittered backend with realistic parameters + // At 32kHz, 10ms = 320 samples = 160 frames (stereo) + // Jitter of ±5ms means 5-15ms intervals, or 80-240 frames + JitteredAudioBackend jittered_backend; + jittered_backend.set_base_interval(10.0f); // 10ms base interval + jittered_backend.set_jitter_amount(5.0f); // ±5ms jitter + jittered_backend.set_chunk_size_range(80, 240); // Realistic chunk sizes for 5-15ms + + audio_set_backend(&jittered_backend); + audio_init(); + + // Start audio thread + audio_start(); + assert(jittered_backend.is_running()); + + // Simulate main loop for 2 seconds + const float total_time = 2.0f; + const float dt = 1.0f / 60.0f; // 60fps + float music_time = 0.0f; + + for (float t = 0.0f; t < total_time; t += dt) { + music_time += dt; // Normal tempo + + // Update tracker and fill buffer + tracker_update(music_time); + audio_render_ahead(music_time, dt); + + // Sleep to simulate frame time + std::this_thread::sleep_for(std::chrono::milliseconds(16)); + } + + // Stop audio + audio_shutdown(); + + // Check results + const int frames_consumed = jittered_backend.get_total_frames_consumed(); + const int underruns = jittered_backend.get_underrun_count(); + + printf(" Frames consumed: %d\n", frames_consumed); + printf(" Underruns: %d\n", underruns); + + // Should have consumed roughly 2 seconds worth of audio + // At 32kHz stereo: 2 seconds = 64000 samples = 32000 frames + assert(frames_consumed > 24000); // At least 1.5 seconds (48000 samples) + assert(frames_consumed < 40000); // At most 2.5 seconds (80000 samples) + + // Underruns are acceptable in this test, but shouldn't be excessive + assert(underruns < 50); // Less than 50 underruns in 2 seconds + + printf(" ✓ Basic jittered audio consumption PASSED\n"); +} + +void test_jittered_audio_with_acceleration() { + printf("Test: Jittered audio with tempo acceleration...\n"); + + // Initialize audio system + synth_init(); + tracker_init(); + + // Set up jittered backend with aggressive settings for stress test + // At 32kHz, 15ms = 480 samples = 240 frames (stereo) + // Jitter of ±10ms means 5-25ms intervals, or 80-400 frames + JitteredAudioBackend jittered_backend; + jittered_backend.set_base_interval(15.0f); // Slower consumption + jittered_backend.set_jitter_amount(10.0f); // High jitter + jittered_backend.set_chunk_size_range(80, 400); // Realistic stress test range + + audio_set_backend(&jittered_backend); + audio_init(); + + // Start audio thread + audio_start(); + + // Simulate acceleration scenario (similar to real demo) + const float total_time = 10.0f; + const float dt = 1.0f / 60.0f; + float music_time = 0.0f; + float physical_time = 0.0f; + + for (int frame = 0; frame < 600; ++frame) { // 10 seconds @ 60fps + physical_time = frame * dt; + + // Variable tempo (accelerate from 5-10s) + float tempo_scale = 1.0f; + if (physical_time >= 5.0f && physical_time < 10.0f) { + const float progress = (physical_time - 5.0f) / 5.0f; + tempo_scale = 1.0f + progress * 1.0f; // 1.0 → 2.0 + } + + music_time += dt * tempo_scale; + + // Update tracker and fill buffer + tracker_update(music_time); + audio_render_ahead(music_time, dt); + + // Sleep to simulate frame time + std::this_thread::sleep_for(std::chrono::milliseconds(16)); + + // Progress indicator + if (frame % 60 == 0) { + printf(" Frame %d: music_time=%.2fs, tempo=%.2fx, consumed=%d frames, underruns=%d\r", + frame, music_time, tempo_scale, + jittered_backend.get_total_frames_consumed(), + jittered_backend.get_underrun_count()); + fflush(stdout); + } + } + printf("\n"); + + // Stop audio + audio_shutdown(); + + // Check results + const int frames_consumed = jittered_backend.get_total_frames_consumed(); + const int underruns = jittered_backend.get_underrun_count(); + + printf(" Total frames consumed: %d\n", frames_consumed); + printf(" Total underruns: %d\n", underruns); + + // Should have consumed roughly 12.5 seconds worth of audio + // (10 seconds physical time with acceleration 1.0x → 2.0x) + // At 32kHz stereo: 12.5 seconds = 400000 samples = 200000 frames + assert(frames_consumed > 120000); // At least 7.5 seconds (240000 samples) + assert(frames_consumed < 240000); // At most 15 seconds (480000 samples) + + // During acceleration with jitter, some underruns are expected but not excessive + assert(underruns < 200); // Less than 200 underruns in 10 seconds + + printf(" ✓ Jittered audio with acceleration PASSED\n"); +} + +int main() { + printf("Running Jittered Audio Backend tests...\n\n"); + test_jittered_audio_basic(); + test_jittered_audio_with_acceleration(); + printf("\n✅ All Jittered Audio Backend tests PASSED\n"); + return 0; +} + +#else + +int main() { + printf("Jittered Audio Backend tests skipped (STRIP_ALL enabled)\n"); + return 0; +} + +#endif /* !defined(STRIP_ALL) */ |
