xtc/tests/integration/test_playback_example.c

32 lines
1.4 KiB
C
Raw Normal View History

2026-11-06 22:00:35 +01:00
/* Verify the bundled song produces finite stereo audio in every bar offline. */
#include "xtc/xtc_midi.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
int main(void)
{
xtc_project *project = NULL;
xtc_midi_plan *midi = NULL;
xtc_plan *graph = NULL;
double energy[4] = {0};
assert(xtc_project_create(&project) == XTC_OK);
assert(xtc_project_load(project, "examples/projects/playback-test.xtc") == XTC_OK);
assert(xtc_midi_plan_create(project, 48000, &midi) == XTC_OK);
assert(xtc_graph_compile(xtc_project_graph(project), 48000, 256, &graph) == XTC_OK);
for (uint64_t pos = 0; pos < 384000; pos += 256) {
float ml[256], mr[256], left[256], right[256];
assert(xtc_midi_plan_render_stereo(midi, pos, NULL, 0, ml, mr, 256) == XTC_OK);
assert(xtc_plan_process_stereo(graph, NULL, NULL, NULL, ml, mr, left, right, 256) == XTC_OK);
for (size_t i = 0; i < 256 && pos + i < 384000; ++i) {
assert(isfinite(left[i]) && isfinite(right[i]));
assert(fabsf(left[i]) <= 1 && fabsf(right[i]) <= 1);
energy[(pos + i) / 96000] += fabsf(left[i]) + fabsf(right[i]);
}
}
for (size_t bar = 0; bar < 4; ++bar) assert(energy[bar] > 1);
xtc_plan_destroy(graph);
xtc_midi_plan_destroy(midi);
xtc_project_destroy(project);
puts("Playback example renders all four bars without devices or media.");
return 0;
}