#define _POSIX_C_SOURCE 200809L /* Accelerated virtual playback: synchronous consumer, no hardware/server. */ #include "xtc/xtc_realtime.h" #include #include #include #include int main(int argc, char **argv) { xtc_graph *graph = NULL; xtc_realtime *engine = NULL; xtc_realtime_status status; size_t gain, output, i, j, frames; unsigned long blocks = 1000000, iterations = 0; uint64_t samples = 0; float input[1024], left[1024], right[1024]; if (argc > 2) return 1; if (argc == 2) { char *end; blocks = strtoul(argv[1], &end, 10); if (!*argv[1] || *end || blocks < 100 || blocks > 100000000) return 1; } assert(xtc_graph_create(2, &graph) == XTC_OK); assert(xtc_graph_add_gain(graph, 0.5f, &gain) == XTC_OK); assert(xtc_graph_add_output(graph, &output) == XTC_OK); assert(xtc_graph_connect(graph, gain, output) == XTC_OK); assert(xtc_realtime_create(48000, 1024, &engine) == XTC_OK); assert(xtc_realtime_submit(engine, graph) == XTC_OK); for (j = 0; j < 1024; ++j) input[j] = j % 2 ? -0.5f : 0.25f; for (i = 0; i < blocks; ++i) { static const size_t sizes[] = {31, 128, 1024}; frames = sizes[i % 3]; if (i && i % 100 == 0) { /* Quiescent control work models stop, seek/wrap and graph restart. * No hardware lifecycle claims are made by this test. */ xtc_realtime_collect(engine); assert(xtc_realtime_position(engine, (i % 200) ? 48000 : 0) == XTC_OK); assert(xtc_realtime_submit(engine, graph) == XTC_OK); ++iterations; } assert(xtc_realtime_process_stereo(engine, input, NULL, NULL, NULL, NULL, left, right, frames) == XTC_OK); for (j = 0; j < frames; ++j) assert(isfinite(left[j]) && left[j] == input[j] * 0.5f && right[j] == left[j]); samples += frames; } assert(xtc_realtime_get_status(engine, &status) == XTC_OK); assert(status.last_result == XTC_OK && status.processed_blocks == blocks); assert(status.active_revision == status.submitted_revision); xtc_realtime_collect(engine); xtc_realtime_destroy(engine); xtc_graph_destroy(graph); printf("Virtual playback: %lu blocks, %.3f audio hours, %lu quiescent seek/rebuild cycles passed.\n", blocks, (double)samples / 48000 / 3600, iterations); return 0; }