diff options
Diffstat (limited to 'src/tests/test_wav_dump.cc')
| -rw-r--r-- | src/tests/test_wav_dump.cc | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/src/tests/test_wav_dump.cc b/src/tests/test_wav_dump.cc index c68578b..cc2de19 100644 --- a/src/tests/test_wav_dump.cc +++ b/src/tests/test_wav_dump.cc @@ -3,10 +3,12 @@ #include "audio/audio.h" #include "audio/audio_engine.h" +#include "audio/ring_buffer.h" #include "audio/wav_dump_backend.h" #include <assert.h> #include <stdio.h> #include <string.h> +#include <vector> #if !defined(STRIP_ALL) @@ -32,31 +34,48 @@ void test_wav_format_matches_live_audio() { const char* test_file = "test_format.wav"; + // Initialize audio system + audio_init(); + + // Initialize AudioEngine + AudioEngine engine; + engine.init(); + // Create WAV dump backend WavDumpBackend wav_backend; wav_backend.set_output_file(test_file); - wav_backend.set_duration(2.0f); // Only 2 seconds for quick testing - audio_set_backend(&wav_backend); + wav_backend.init(); + wav_backend.start(); - // Initialize audio system (calls synth_init internally) - audio_init(); + // Simulate 2 seconds of audio rendering (frontend-driven) + const float duration = 2.0f; + const float update_dt = 1.0f / 60.0f; + const int frames_per_update = (int)(32000 * update_dt); + const int samples_per_update = frames_per_update * 2; // Stereo - // Initialize AudioEngine (replaces direct synth_init/tracker_init) - AudioEngine engine; - engine.init(); + AudioRingBuffer* ring_buffer = audio_get_ring_buffer(); + std::vector<float> chunk_buffer(samples_per_update); - // Manually trigger some audio for testing - engine.update(0.0f); // Trigger patterns at t=0 + float music_time = 0.0f; + for (float t = 0.0f; t < duration; t += update_dt) { + // Update audio engine (triggers patterns) + engine.update(music_time); + music_time += update_dt; - // Render short duration (1 second = 60 updates @ 60Hz) - for (int i = 0; i < 60; ++i) { - float t = i / 60.0f; - engine.update(t); + // Render audio ahead + audio_render_ahead(music_time, update_dt); + + // Read from ring buffer + if (ring_buffer != nullptr) { + ring_buffer->read(chunk_buffer.data(), samples_per_update); + } - // Simulate audio render (WavDumpBackend will handle this in start()) + // Write to WAV file + wav_backend.write_audio(chunk_buffer.data(), samples_per_update); } - audio_start(); // This triggers the actual WAV rendering + // Shutdown + wav_backend.shutdown(); engine.shutdown(); audio_shutdown(); @@ -146,6 +165,7 @@ void test_wav_format_matches_live_audio() { printf(" ✓ WAV format verified: stereo, 32kHz, 16-bit PCM\n"); printf(" ✓ Matches live audio output configuration\n"); + printf(" ✓ Backend is passive (frontend-driven)\n"); } void test_wav_stereo_buffer_size() { |
